Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build testing #277

Merged
merged 14 commits into from
May 14, 2019
8 changes: 2 additions & 6 deletions .ci/azure-steps.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
steps:

- checkout: self
fetchDepth: 50
submodules: true

- task: CMake@1
inputs:
cmakeArgs: .. -DCLI12_SINGLE_FILE=ON -DCLI11_CXX_STD=14 -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
cmakeArgs: .. -DCLI11_SINGLE_FILE=$(cli11.single) -DCLI11_CXX_STD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options)
displayName: 'Configure'

- script: cmake --build . -j
displayName: 'Build'
workingDirectory: build

- script: ctest --output-on-failure -C Debug
- script: ctest --output-on-failure -C $(cli11.build_type)
displayName: 'Test'
workingDirectory: build
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ insert_final_newline = true
end_of_line = lf
trim_trailing_whitespace = true

[*.yml]
indent_size = 2
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Set handling has been completely replaced by a new backend that works as a Valid
* Cleanup for shadow warnings [#232]
* Better alignment on multiline descriptions [#269]
* Better support for aarch64 [#266]
* Respect `BUILD_TESTING` only if CLI11 is the main project; otherwise, `CLI11_TESTING` must be used [#277]
* Drop auto-detection of experimental optional; must be enabled explicitly (too fragile) [#277]
henryiii marked this conversation as resolved.
Show resolved Hide resolved

> ### Converting from CLI11 1.7:
>
Expand Down Expand Up @@ -54,6 +56,7 @@ Set handling has been completely replaced by a new backend that works as a Valid
[#265]: https://github.com/CLIUtils/CLI11/pull/265
[#266]: https://github.com/CLIUtils/CLI11/pull/266
[#269]: https://github.com/CLIUtils/CLI11/pull/269
[#277]: https://github.com/CLIUtils/CLI11/pull/277


## Version 1.7.1: Quick patch
Expand Down Expand Up @@ -85,7 +88,7 @@ Passing the same subcommand multiple times is better supported. Several new feat
* Parsing is now done in phases: `shortcurcuits`, `ini`, `env`, `callbacks`, and `requirements`; all subcommands complete a phase before moving on. [#179]
* Calling parse multiple times is now officially supported without `clear` (automatic). [#179]
* Dropped the mostly undocumented `short_circuit` property, as help flag parsing is a bit more complex, and the default callback behavior of options now works properly. [#179]
* Use the standard `BUILD_TESTING` over `CLI11_TESTING` if defined (`CLI11_TESTING` may eventually be removed) [#183]
* Use the standard `BUILD_TESTING` over `CLI11_TESTING` if defined [#183]
* Cleanup warnings [#191]
* Remove deprecated names: `set_footer`, `set_name`, `set_callback`, and `set_type_name`. Use without the `set_` instead. [#192]

Expand Down
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# User settable
set(CLI11_CXX_STD "11" CACHE STRING "The CMake standard to require")

# Special override for Clang on Linux (useful with an old stdlibc++ and a newer clang)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
option(CLI11_FORCE_LIBCXX "Force Clang to use libc++ instead of libstdc++ (Linux only)" OFF)
if(CLI11_FORCE_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
endif()
endif()

set(CUR_PROJ ON)
set(CMAKE_CXX_STANDARD ${CLI11_CXX_STD})
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down Expand Up @@ -149,14 +158,25 @@ if(CLI11_SINGLE_FILE)
target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
endif()

cmake_dependent_option(CLI11_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build" OFF "CLI11_SINGLE_FILE" OFF)
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS
"Duplicate all the tests for a single file build"
OFF
"CLI11_SINGLE_FILE"
OFF)

cmake_dependent_option(CLI11_TESTING "Build the tests and add them" ON "CUR_PROJ" OFF)
if(DEFINED BUILD_TESTING)
cmake_dependent_option(CLI11_TESTING "" ON "BUILD_TESTING" OFF)
message(STATUS "BUILD_TESTING is defined and it supersedes CLI11_TESTING. Has forced to ${CLI11_TESTING}")
cmake_dependent_option(CLI11_TESTING
"Build the tests and add them (BUILD_TESTING also works if this is the main project)"
ON
"CUR_PROJ"
OFF)

if(DEFINED BUILD_TESTING AND CUR_PROJ)
set(CLI11_TESTING_INTERNAL ON)
else()
set(CLI11_TESTING_INTERNAL "${CLI11_TESTING}")
phlptp marked this conversation as resolved.
Show resolved Hide resolved
endif()
if(CLI11_TESTING)

if(CLI11_TESTING_INTERNAL)
enable_testing()
add_subdirectory(tests)
endif()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ An acceptable CLI parser library should be all of the following:

- Easy to include (i.e., header only, one file if possible, **no external requirements**).
- Short, simple syntax: This is one of the main reasons to use a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability.
- C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.5+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+.
- C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.4+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+.
- Work on Linux, macOS, and Windows.
- Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][].
- Clear help printing.
Expand Down
59 changes: 53 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,68 @@
trigger:
- master

variables:
cli11.single: ON
cli11.std: 14
cli11.build_type: Debug
cli11.options:

jobs:
- job: Linux

- job: ClangFormat
pool:
vmImage: 'ubuntu-16.04'
steps:
- template: .ci/azure-steps.yml
- script: scripts/check_style_docker.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the other format check be dropped. Seems a little redundant to have both, or are they checking different things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be slowly reducing our usage of non-Azure CI, so yes. I could probably go ahead and drop that in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually still only checking "clang-tidy" on Travis. I'll need to move that in here in the future.

displayName: Check format

- job: macOS
- job: Native
strategy:
matrix:
Linux:
vmImage: 'ubuntu-16.04'
macOS:
vmImage: 'macOS-10.14'
Windows:
vmImage: 'vs2017-win2016'
pool:
vmImage: 'macOS-10.13'
vmImage: $(vmImage)
steps:
- template: .ci/azure-steps.yml

- job: Windows
- job: Docker
variables:
cli11.single: OFF
pool:
vmImage: 'vs2017-win2016'
vmImage: 'ubuntu-16.04'
strategy:
matrix:
gcc9:
containerImage: gcc:9
cli11.std: 17
gcc4.7:
containerImage: gcc:4.7
cli11.std: 11
clang3.4:
containerImage: silkeh/clang:3.4
cli11.std: 11
clang8:
containerImage: silkeh/clang:8
cli11.std: 14
cli11.options: -DCLI11_FORCE_LIBCXX=ON
container: $[ variables['containerImage'] ]
steps:
# Note that silkeh/clang does not include ca-certificates, so check the shasum for verification
- script: |
wget --no-check-certificate "https://cmake.org/files/v3.14/cmake-3.14.3-Linux-x86_64.tar.gz"
echo "29faa62fb3a0b6323caa3d9557e1a5f1205614c0d4c5c2a9917f16a74f7eff68 cmake-3.14.3-Linux-x86_64.tar.gz" | shasum -sca 256
displayName: Download CMake
- task: ExtractFiles@1
inputs:
archiveFilePatterns: 'cmake*.tar.gz'
destinationFolder: 'cmake_program'
displayName: Extract CMake
- bash: echo "##vso[task.prependpath]$(Build.SourcesDirectory)/cmake_program/cmake-3.14.3-Linux-x86_64/bin"
displayName: Add CMake to PATH
- template: .ci/azure-steps.yml

6 changes: 1 addition & 5 deletions include/CLI/Optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#define CLI11_STD_OPTIONAL 0
#endif

#if defined(CLI11_CPP14) && __has_include(<experimental/optional>) && \
!defined(CLI11_EXPERIMENTAL_OPTIONAL) \
&& (!defined(CLI11_STD_OPTIONAL) || CLI11_STD_OPTIONAL == 0)
#define CLI11_EXPERIMENTAL_OPTIONAL 1
#elif !defined(CLI11_EXPERIMENTAL_OPTIONAL)
#if !defined(CLI11_EXPERIMENTAL_OPTIONAL)
#define CLI11_EXPERIMENTAL_OPTIONAL 0
#endif

Expand Down
7 changes: 4 additions & 3 deletions include/CLI/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define _GLIBCXX_USE_NANOSLEEP
#endif

#include <array>
#include <chrono>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -86,9 +87,9 @@ class Timer {
/// This prints out a time string from a time
std::string make_time_str(double time) const {
auto print_it = [](double x, std::string unit) {
char buffer[50];
std::snprintf(buffer, 50, "%.5g", x);
return buffer + std::string(" ") + unit;
std::array<char, 50> buffer;
std::snprintf(buffer.data(), 50, "%.5g", x);
return buffer.data() + std::string(" ") + unit;
};

if(time < .000001)
Expand Down
5 changes: 3 additions & 2 deletions scripts/check_style_docker.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env sh

# Also good but untagged: CLANG_FORMAT=unibeautify/clang-format
# This might provide more control in the future: silkeh/clang:8 (etc)
CLANG_FORMAT=saschpe/clang-format:5.0.1

set -evx

docker run --rm -it ${CLANG_FORMAT} --version
docker run --rm -it -v "$(pwd)":/workdir -w /workdir ${CLANG_FORMAT} -style=file -sort-includes -i $(git ls-files -- '*.cpp' '*.hpp')
docker run --rm ${CLANG_FORMAT} --version
docker run --rm --user $(id -u):$(id -g) -v "$(pwd)":/workdir -w /workdir ${CLANG_FORMAT} -style=file -sort-includes -i $(git ls-files -- '*.cpp' '*.hpp')

git diff --exit-code --color

Expand Down