Skip to content

Commit 433fd91

Browse files
authored
Build testing (#277)
* build-testing better supported * Add formatting to Azure * Adding more jobs to Azure * Control * Allow libc++ to be used on linux * Fix modernize message * Fix variable * fixup! Fix modernize message * Drop auto exp. optional * Update readme, better user id in docker * Fix BUILD_TESTING * Drop format from travis, leave tidy for now * Check tidy and format * Tidy fully on Azure now
1 parent 0be526e commit 433fd91

14 files changed

+133
-77
lines changed

Diff for: .ci/azure-build.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
steps:
2+
3+
- task: CMake@1
4+
inputs:
5+
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)
6+
displayName: 'Configure'
7+
8+
- script: cmake --build . $(cli11.threadopt)
9+
displayName: 'Build'
10+
workingDirectory: build
11+

Diff for: .ci/azure-cmake.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
steps:
2+
3+
# Note that silkeh/clang does not include ca-certificates, so check the shasum for verification
4+
- bash: |
5+
wget --no-check-certificate "https://cmake.org/files/v3.14/cmake-3.14.3-Linux-x86_64.tar.gz"
6+
echo "29faa62fb3a0b6323caa3d9557e1a5f1205614c0d4c5c2a9917f16a74f7eff68 cmake-3.14.3-Linux-x86_64.tar.gz" | shasum -sca 256
7+
displayName: Download CMake
8+
9+
- task: ExtractFiles@1
10+
inputs:
11+
archiveFilePatterns: 'cmake*.tar.gz'
12+
destinationFolder: 'cmake_program'
13+
displayName: Extract CMake
14+
15+
- bash: echo "##vso[task.prependpath]$(Build.SourcesDirectory)/cmake_program/cmake-3.14.3-Linux-x86_64/bin"
16+
displayName: Add CMake to PATH

Diff for: .ci/azure-steps.yml

-18
This file was deleted.

Diff for: .ci/azure-test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
steps:
2+
3+
- script: ctest --output-on-failure -C $(cli11.build_type)
4+
displayName: 'Test'
5+
workingDirectory: build

Diff for: .ci/check_tidy.sh

-21
This file was deleted.

Diff for: .editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ insert_final_newline = true
77
end_of_line = lf
88
trim_trailing_whitespace = true
99

10+
[*.yml]
11+
indent_size = 2

Diff for: .travis.yml

-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ matrix:
2323
- .ci/make_and_test.sh 14
2424
- .ci/make_and_test.sh 17
2525

26-
# Check style/tidy
27-
- compiler: clang
28-
env:
29-
- CHECK_STYLE=yes
30-
script:
31-
- cd "${TRAVIS_BUILD_DIR}"
32-
- scripts/check_style.sh
33-
- .ci/check_tidy.sh
34-
3526
# Docs and clang 3.5
3627
- compiler: clang
3728
env:

Diff for: CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Set handling has been completely replaced by a new backend that works as a Valid
2121
* Cleanup for shadow warnings [#232]
2222
* Better alignment on multiline descriptions [#269]
2323
* Better support for aarch64 [#266]
24+
* Respect `BUILD_TESTING` only if CLI11 is the main project; otherwise, `CLI11_TESTING` must be used [#277]
25+
* Drop auto-detection of experimental optional; must be enabled explicitly (too fragile) [#277]
2426

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

5861

5962
## Version 1.7.1: Quick patch
@@ -85,7 +88,7 @@ Passing the same subcommand multiple times is better supported. Several new feat
8588
* Parsing is now done in phases: `shortcurcuits`, `ini`, `env`, `callbacks`, and `requirements`; all subcommands complete a phase before moving on. [#179]
8689
* Calling parse multiple times is now officially supported without `clear` (automatic). [#179]
8790
* 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]
88-
* Use the standard `BUILD_TESTING` over `CLI11_TESTING` if defined (`CLI11_TESTING` may eventually be removed) [#183]
91+
* Use the standard `BUILD_TESTING` over `CLI11_TESTING` if defined [#183]
8992
* Cleanup warnings [#191]
9093
* Remove deprecated names: `set_footer`, `set_name`, `set_callback`, and `set_type_name`. Use without the `set_` instead. [#192]
9194

Diff for: CMakeLists.txt

+28-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ cmake_minimum_required(VERSION 3.4)
22
# Note: this is a header only library. If you have an older CMake than 3.4,
33
# just add the CLI11/include directory and that's all you need to do.
44

5-
# Make sure users don't get warnings on a tested (3.4 to 3.13) version
5+
# Make sure users don't get warnings on a tested (3.4 to 3.14) version
66
# of CMake. For most of the policies, the new version is better (hence the change).
7-
if(${CMAKE_VERSION} VERSION_LESS 3.13)
7+
# We don't use the 3.4...3.14 syntax because of a bug in a version of MSVC
8+
if(${CMAKE_VERSION} VERSION_LESS 3.14)
89
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
910
else()
10-
cmake_policy(VERSION 3.13)
11+
cmake_policy(VERSION 3.14)
1112
endif()
1213

1314
set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
@@ -27,6 +28,15 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
2728
# User settable
2829
set(CLI11_CXX_STD "11" CACHE STRING "The CMake standard to require")
2930

31+
# Special override for Clang on Linux (useful with an old stdlibc++ and a newer clang)
32+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
33+
option(CLI11_FORCE_LIBCXX "Force Clang to use libc++ instead of libstdc++ (Linux only)" OFF)
34+
if(CLI11_FORCE_LIBCXX)
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
36+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
37+
endif()
38+
endif()
39+
3040
set(CUR_PROJ ON)
3141
set(CMAKE_CXX_STANDARD ${CLI11_CXX_STD})
3242
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -149,14 +159,23 @@ if(CLI11_SINGLE_FILE)
149159
target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
150160
endif()
151161

152-
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build" OFF "CLI11_SINGLE_FILE" OFF)
162+
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS
163+
"Duplicate all the tests for a single file build"
164+
OFF
165+
"CLI11_SINGLE_FILE"
166+
OFF)
153167

154-
cmake_dependent_option(CLI11_TESTING "Build the tests and add them" ON "CUR_PROJ" OFF)
155-
if(DEFINED BUILD_TESTING)
156-
cmake_dependent_option(CLI11_TESTING "" ON "BUILD_TESTING" OFF)
157-
message(STATUS "BUILD_TESTING is defined and it supersedes CLI11_TESTING. Has forced to ${CLI11_TESTING}")
168+
169+
if(DEFINED CLI11_TESTING)
170+
set(CLI11_TESTING_INTERNAL "${CLI11_TESTING}")
171+
elseif(CUR_PROJ)
172+
option(BUILD_TESTING "Build the tests" ON)
173+
set(CLI11_TESTING_INTERNAL "${BUILD_TESTING}")
174+
else()
175+
set(CLI11_TESTING_INTERNAL OFF)
158176
endif()
159-
if(CLI11_TESTING)
177+
178+
if(CLI11_TESTING_INTERNAL)
160179
enable_testing()
161180
add_subdirectory(tests)
162181
endif()

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ An acceptable CLI parser library should be all of the following:
7373

7474
- Easy to include (i.e., header only, one file if possible, **no external requirements**).
7575
- 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.
76-
- 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+.
76+
- 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+.
7777
- Work on Linux, macOS, and Windows.
7878
- Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][].
7979
- Clear help printing.

Diff for: azure-pipelines.yml

+58-8
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,71 @@
66
trigger:
77
- master
88

9+
variables:
10+
cli11.single: ON
11+
cli11.std: 14
12+
cli11.build_type: Debug
13+
cli11.options:
14+
cli11.threadopt: -j
15+
916
jobs:
10-
- job: Linux
17+
18+
- job: ClangFormatTidy
19+
variables:
20+
CXX_FLAGS: "-Werror -Wcast-align -Wfloat-equal -Wimplicit-atomic-properties -Wmissing-declarations -Woverlength-strings -Wshadow -Wstrict-selector-match -Wundeclared-selector -Wunreachable-code -std=c++11"
21+
cli11.options: -DCLANG_TIDY_FIX=ON
22+
cli11.std: 11
23+
cli11.single: OFF
24+
cli11.threadopt:
1125
pool:
1226
vmImage: 'ubuntu-16.04'
27+
container: silkeh/clang:5
1328
steps:
14-
- template: .ci/azure-steps.yml
29+
- script: scripts/check_style.sh
30+
displayName: Check format
31+
- template: .ci/azure-cmake.yml
32+
- template: .ci/azure-build.yml
33+
- script: git diff --exit-code --color
34+
displayName: Check tidy
1535

16-
- job: macOS
36+
- job: Native
37+
strategy:
38+
matrix:
39+
Linux:
40+
vmImage: 'ubuntu-16.04'
41+
macOS:
42+
vmImage: 'macOS-10.14'
43+
Windows:
44+
vmImage: 'vs2017-win2016'
1745
pool:
18-
vmImage: 'macOS-10.13'
46+
vmImage: $(vmImage)
1947
steps:
20-
- template: .ci/azure-steps.yml
48+
- template: .ci/azure-build.yml
49+
- template: .ci/azure-test.yml
2150

22-
- job: Windows
51+
- job: Docker
52+
variables:
53+
cli11.single: OFF
2354
pool:
24-
vmImage: 'vs2017-win2016'
55+
vmImage: 'ubuntu-16.04'
56+
strategy:
57+
matrix:
58+
gcc9:
59+
containerImage: gcc:9
60+
cli11.std: 17
61+
gcc4.7:
62+
containerImage: gcc:4.7
63+
cli11.std: 11
64+
clang3.4:
65+
containerImage: silkeh/clang:3.4
66+
cli11.std: 11
67+
clang8:
68+
containerImage: silkeh/clang:8
69+
cli11.std: 14
70+
cli11.options: -DCLI11_FORCE_LIBCXX=ON
71+
container: $[ variables['containerImage'] ]
2572
steps:
26-
- template: .ci/azure-steps.yml
73+
- template: .ci/azure-cmake.yml
74+
- template: .ci/azure-build.yml
75+
- template: .ci/azure-test.yml
76+

Diff for: include/CLI/Optional.hpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
#define CLI11_STD_OPTIONAL 0
2020
#endif
2121

22-
#if defined(CLI11_CPP14) && __has_include(<experimental/optional>) && \
23-
!defined(CLI11_EXPERIMENTAL_OPTIONAL) \
24-
&& (!defined(CLI11_STD_OPTIONAL) || CLI11_STD_OPTIONAL == 0)
25-
#define CLI11_EXPERIMENTAL_OPTIONAL 1
26-
#elif !defined(CLI11_EXPERIMENTAL_OPTIONAL)
22+
#if !defined(CLI11_EXPERIMENTAL_OPTIONAL)
2723
#define CLI11_EXPERIMENTAL_OPTIONAL 0
2824
#endif
2925

Diff for: include/CLI/Timer.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define _GLIBCXX_USE_NANOSLEEP
1010
#endif
1111

12+
#include <array>
1213
#include <chrono>
1314
#include <functional>
1415
#include <iostream>
@@ -86,9 +87,9 @@ class Timer {
8687
/// This prints out a time string from a time
8788
std::string make_time_str(double time) const {
8889
auto print_it = [](double x, std::string unit) {
89-
char buffer[50];
90-
std::snprintf(buffer, 50, "%.5g", x);
91-
return buffer + std::string(" ") + unit;
90+
std::array<char, 50> buffer;
91+
std::snprintf(buffer.data(), 50, "%.5g", x);
92+
return buffer.data() + std::string(" ") + unit;
9293
};
9394

9495
if(time < .000001)

Diff for: scripts/check_style_docker.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env sh
22

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

67
set -evx
78

8-
docker run --rm -it ${CLANG_FORMAT} --version
9-
docker run --rm -it -v "$(pwd)":/workdir -w /workdir ${CLANG_FORMAT} -style=file -sort-includes -i $(git ls-files -- '*.cpp' '*.hpp')
9+
docker run --rm ${CLANG_FORMAT} --version
10+
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')
1011

1112
git diff --exit-code --color
1213

0 commit comments

Comments
 (0)