From fa4b10d5a0b6e877621e4e13de077dfcc4dce186 Mon Sep 17 00:00:00 2001 From: matoro Date: Tue, 7 May 2024 15:41:36 -0400 Subject: [PATCH] Add meson support for tests Allows tests to use "meson test" instead of a shell script. This also means that they now fully respect user-specified toolchain (e.g. clang compiler, custom CFLAGS, etc). Running C++ test is conditional on enabling INIReader support in the build. ``` 1/16 test_multi OK 0.05s 2/16 test_multi_max_line OK 0.04s 3/16 test_single OK 0.04s 4/16 test_disallow_inline_comments OK 0.03s 5/16 test_stop_on_first_error OK 0.03s 6/16 test_handler_lineno OK 0.02s 7/16 test_heap OK 0.06s 8/16 test_string OK 0.06s 9/16 test_heap_max_line OK 0.05s 10/16 test_heap_realloc OK 0.05s 11/16 test_heap_realloc_max_line OK 0.05s 12/16 test_heap_string OK 0.04s 13/16 test_call_handler_on_new_section OK 0.04s 14/16 test_allow_no_value OK 0.03s 15/16 test_alloc OK 0.02s 16/16 test_INIReaderExample OK 0.02s Ok: 16 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 0 Timeout: 0 ``` --- .github/workflows/tests.yml | 10 ++++++++ examples/meson.build | 4 ++++ meson.build | 15 +++++++++--- runtest.sh | 6 +++++ tests/meson.build | 46 +++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 examples/meson.build create mode 100755 runtest.sh create mode 100644 tests/meson.build diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4971e43..c241538 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,3 +20,13 @@ jobs: cd ../examples ./cpptest.sh git diff --exit-code + build-meson: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@main + - uses: BSFishy/meson-build@master + with: + action: test + meson-version: 1.4.1 diff --git a/examples/meson.build b/examples/meson.build new file mode 100644 index 0000000..1e0a2b1 --- /dev/null +++ b/examples/meson.build @@ -0,0 +1,4 @@ +runtest = files(join_paths(meson.project_source_root(), 'runtest.sh')) + +unittest_INIReaderExample = executable('unittest_INIReaderExample', src_inih, src_INIReader, 'INIReaderExample.cpp', cpp_args : ['-Wall']) +test('test_INIReaderExample', runtest, depends : [unittest_INIReaderExample], args : [files('cpptest.txt'), unittest_INIReaderExample.full_path()]) diff --git a/meson.build b/meson.build index d440cbc..4e4fe4b 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,8 @@ project('inih', ['c'], license : 'BSD-3-Clause', version : '58', - default_options : ['cpp_std=c++11'] + default_options : ['cpp_std=c++11'], + meson_version: '>=0.56.0' ) #### options #### @@ -71,8 +72,10 @@ endif #### inih #### inc_inih = include_directories('.') +src_inih = files('ini.c') + lib_inih = library('inih', - ['ini.c'], + [src_inih], include_directories : inc_inih, c_args : [arg_static, extra_args], install : distro_install, @@ -96,13 +99,17 @@ inih_dep = declare_dependency( include_directories : inc_inih ) +subdir('tests') + #### INIReader #### if get_option('with_INIReader') add_languages('cpp') inc_INIReader = include_directories('cpp') + src_INIReader = files(join_paths('cpp', 'INIReader.cpp')) + lib_INIReader = library('INIReader', - ['cpp/INIReader.cpp'], + src_INIReader, cpp_args : extra_args, include_directories : inc_INIReader, dependencies : inih_dep, @@ -126,4 +133,6 @@ if get_option('with_INIReader') include_directories : inc_INIReader, compile_args : extra_args ) + + subdir('examples') endif diff --git a/runtest.sh b/runtest.sh new file mode 100755 index 0000000..9db945b --- /dev/null +++ b/runtest.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "${1}")" +diff "${1}" <("${2}") diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..0ccc0df --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,46 @@ +runtest = files(join_paths(meson.project_source_root(), 'runtest.sh')) + +unittest_multi = executable('unittest_multi', src_inih, 'unittest.c', c_args : ['-Wall']) +test('test_multi', runtest, depends : [unittest_multi], args : [files('baseline_multi.txt'), unittest_multi.full_path()]) + +unittest_multi_max_line = executable('unittest_multi_max_line', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_MAX_LINE=20']) +test('test_multi_max_line', runtest, depends : [unittest_multi_max_line], args : [files('baseline_multi_max_line.txt'), unittest_multi_max_line.full_path()]) + +unittest_single = executable('unittest_single', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_ALLOW_MULTILINE=0']) +test('test_single', runtest, depends : [unittest_single], args : [files('baseline_single.txt'), unittest_single.full_path()]) + +unittest_disallow_inline_comments = executable('unittest_disallow_inline_comments', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_ALLOW_INLINE_COMMENTS=0']) +test('test_disallow_inline_comments', runtest, depends : [unittest_disallow_inline_comments], args : [files('baseline_disallow_inline_comments.txt'), unittest_disallow_inline_comments.full_path()]) + +unittest_stop_on_first_error = executable('unittest_stop_on_first_error', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_STOP_ON_FIRST_ERROR=1']) +test('test_stop_on_first_error', runtest, depends : [unittest_stop_on_first_error], args : [files('baseline_stop_on_first_error.txt'), unittest_stop_on_first_error.full_path()]) + +unittest_handler_lineno = executable('unittest_handler_lineno', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_HANDLER_LINENO=1']) +test('test_handler_lineno', runtest, depends : [unittest_handler_lineno], args : [files('baseline_handler_lineno.txt'), unittest_handler_lineno.full_path()]) + +unittest_string = executable('unittest_string', src_inih, 'unittest_string.c', c_args : ['-Wall', '-DINI_MAX_LINE=20']) +test('test_string', runtest, depends : [unittest_string], args : [files('baseline_string.txt'), unittest_string.full_path()]) + +unittest_heap = executable('unittest_heap', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_USE_STACK=0']) +test('test_heap', runtest, depends : [unittest_heap], args : [files('baseline_heap.txt'), unittest_heap.full_path()]) + +unittest_heap_max_line = executable('unittest_heap_max_line', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20']) +test('test_heap_max_line', runtest, depends : [unittest_heap_max_line], args : [files('baseline_heap_max_line.txt'), unittest_heap_max_line.full_path()]) + +unittest_heap_realloc = executable('unittest_heap_realloc', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5']) +test('test_heap_realloc', runtest, depends : [unittest_heap_realloc], args : [files('baseline_heap_realloc.txt'), unittest_heap_realloc.full_path()]) + +unittest_heap_realloc_max_line = executable('unittest_heap_realloc_max_line', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5']) +test('test_heap_realloc_max_line', runtest, depends : [unittest_heap_realloc_max_line], args : [files('baseline_heap_realloc_max_line.txt'), unittest_heap_realloc_max_line.full_path()]) + +unittest_heap_string = executable('unittest_heap_string', src_inih, 'unittest_string.c', c_args : ['-Wall', '-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20']) +test('test_heap_string', runtest, depends : [unittest_heap_string], args : [files('baseline_heap_string.txt'), unittest_heap_string.full_path()]) + +unittest_call_handler_on_new_section = executable('unittest_call_handler_on_new_section', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_CALL_HANDLER_ON_NEW_SECTION=1']) +test('test_call_handler_on_new_section', runtest, depends : [unittest_call_handler_on_new_section], args : [files('baseline_call_handler_on_new_section.txt'), unittest_call_handler_on_new_section.full_path()]) + +unittest_allow_no_value = executable('unittest_allow_no_value', src_inih, 'unittest.c', c_args : ['-Wall', '-DINI_ALLOW_NO_VALUE=1']) +test('test_allow_no_value', runtest, depends : [unittest_allow_no_value], args : [files('baseline_allow_no_value.txt'), unittest_allow_no_value.full_path()]) + +unittest_alloc = executable('unittest_alloc', src_inih, 'unittest_alloc.c', c_args : ['-Wall', '-DINI_CUSTOM_ALLOCATOR=1', '-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=12']) +test('test_alloc', runtest, depends : [unittest_alloc], args : [files('baseline_alloc.txt'), unittest_alloc.full_path()])