Commit e8265f910271466de5becabde45ce8a218029607

Authored by Eli Schwartz
Committed by GitHub
1 parent 25655940

meson: add support for testsuite (#701)

* meson: add support for testsuite

* meson: fix deprecation warning for run_command with unchecked return code

This would implicitly default to false, so if something bizarre happened
and the command errored out, meson would consider that fine. Now meson
emits a warning about this deprecated legacy behavior, suggests that it
will eventually change, and, most importantly, prevents a warning-free
build.

Suppress the warning by manually specifying the sensible behavior, which
is to fail on errors.

* meson: download catch2 on demand if a system version is unavailable

Produced by running `meson wrap install catch2` and checking the results
into git.

No modifications to the build files are expected; this makes use of
https://mesonbuild.com/Wrap-dependency-system-manual.html#provide-section

* style: pre-commit.ci fixes

* ci: add meson build to the CI

* ci: meson doesn't depend on ninja or or have a ninja extra

* ci: minor cleanup to Meson job

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
.github/workflows/tests.yml
... ... @@ -45,6 +45,24 @@ jobs:
45 45 run: ctest --output-on-failure
46 46 working-directory: build
47 47  
  48 + meson-build:
  49 + name: Meson build
  50 + runs-on: ubuntu-latest
  51 + steps:
  52 + - uses: actions/checkout@v2
  53 +
  54 + - name: Prepare commands
  55 + run: |
  56 + pipx install meson
  57 + pipx install ninja
  58 +
  59 + - name: Configure
  60 + run: meson setup build-meson . -Dtests=true
  61 +
  62 + - name: Build
  63 + run: meson compile -C build-meson
  64 +
  65 +
48 66 cmake-config:
49 67 name: CMake config check
50 68 runs-on: ubuntu-latest
... ...
meson.build
1 1 project('CLI11', ['cpp'],
2   - version : run_command(find_program('scripts/ExtractVersion.py')).stdout().strip(),
3   - default_options : ['cpp_std=c++11']
  2 + version : run_command(find_program('scripts/ExtractVersion.py'), check: true).stdout().strip(),
  3 + default_options : ['cpp_std=c++11', 'warning_level=3']
4 4 )
5 5  
  6 +cxx = meson.get_compiler('cpp')
  7 +
6 8 CLI11_inc = include_directories(['include'])
7 9  
8 10 CLI11_dep = declare_dependency(
9 11 include_directories : CLI11_inc,
10 12 version : meson.project_version(),
11 13 )
  14 +
  15 +if get_option('tests')
  16 + warnings = ['-Wshadow', '-Wsign-conversion', '-Wswitch-enum']
  17 + if cxx.get_id() == 'gcc' and cxx.version().version_compare('>=4.9')
  18 + warnings += '-Weffc++'
  19 + endif
  20 + add_project_arguments(cxx.get_supported_arguments(warnings), language: 'cpp')
  21 +
  22 + subdir('tests')
  23 +endif
... ...
meson_options.txt 0 โ†’ 100644
  1 +option('tests', type: 'boolean', value: false, description: 'Build CLI11 tests')
... ...
subprojects/catch2.wrap 0 โ†’ 100644
  1 +[wrap-file]
  2 +directory = Catch2-2.13.7
  3 +source_url = https://github.com/catchorg/Catch2/archive/v2.13.7.zip
  4 +source_filename = Catch2-2.13.7.zip
  5 +source_hash = 3f3ccd90ad3a8fbb1beeb15e6db440ccdcbebe378dfd125d07a1f9a587a927e9
  6 +patch_filename = catch2_2.13.7-1_patch.zip
  7 +patch_url = https://wrapdb.mesonbuild.com/v2/catch2_2.13.7-1/get_patch
  8 +patch_hash = 2f7369645d747e5bd866317ac1dd4c3d04dc97d3aad4fc6b864bdf75d3b57158
  9 +
  10 +[provide]
  11 +catch2 = catch2_dep
... ...
tests/meson.build 0 โ†’ 100644
  1 +catch2 = dependency('catch2')
  2 +
  3 +testmain = static_library(
  4 + 'catch_main',
  5 + 'main.cpp', 'catch.hpp',
  6 + dependencies: catch2,
  7 +)
  8 +testdep = declare_dependency(
  9 + link_with: testmain,
  10 + dependencies: [catch2, CLI11_dep]
  11 +)
  12 +
  13 +link_test_lib = library(
  14 + 'link_test_1',
  15 + 'link_test_1.cpp',
  16 + dependencies: CLI11_dep,
  17 +)
  18 +
  19 +if cxx.get_id() == 'msvc'
  20 + nodeprecated = ['/wd4996']
  21 +else
  22 + nodeprecated = ['-Wno-deprecated-declarations']
  23 +endif
  24 +
  25 +boost = dependency('boost', required: false)
  26 +if boost.found()
  27 + boost_dep = declare_dependency(
  28 + dependencies: boost,
  29 + compile_args: '-DCLI11_BOOST_OPTIONAL',
  30 + )
  31 +else
  32 + boost_dep = declare_dependency()
  33 +endif
  34 +
  35 +testnames = [
  36 + ['HelpersTest', {}],
  37 + ['ConfigFileTest', {}],
  38 + ['OptionTypeTest', {}],
  39 + ['SimpleTest', {}],
  40 + ['AppTest', {}],
  41 + ['SetTest', {}],
  42 + ['TransformTest', {}],
  43 + ['CreationTest', {}],
  44 + ['SubcommandTest', {}],
  45 + ['HelpTest', {}],
  46 + ['FormatterTest', {}],
  47 + ['NewParseTest', {}],
  48 + ['OptionalTest', {'dependencies': boost_dep}],
  49 + ['DeprecatedTest', {'cpp_args': nodeprecated}],
  50 + ['StringParseTest', {}],
  51 + ['ComplexTypeTest', {}],
  52 + ['TrueFalseTest', {}],
  53 + ['OptionGroupTest', {}],
  54 + # multi-only
  55 + ['TimerTest', {}],
  56 + # link_test
  57 + ['link_test_2', {'link_with': link_test_lib}],
  58 +]
  59 +
  60 +if host_machine.system() == 'windows'
  61 + testnames += [['WindowsTest', {}]]
  62 +endif
  63 +
  64 +if boost.found()
  65 + testnames += [['BoostOptionTypeTest', {'dependencies': boost_dep}]]
  66 +endif
  67 +
  68 +foreach n: testnames
  69 + name = n[0]
  70 + kwargs = n[1]
  71 + t = executable(name, name + '.cpp',
  72 + cpp_args: kwargs.get('cpp_args', []),
  73 + build_by_default: false,
  74 + dependencies: [testdep] + kwargs.get('dependencies', []),
  75 + link_with: kwargs.get('link_with', [])
  76 + )
  77 + test(name, t)
  78 +endforeach
... ...