Skip to content

Commit ed45251

Browse files
authored
Add meson support for tests (#170)
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 ``` Co-authored-by: matoro <[email protected]>
1 parent 077174e commit ed45251

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

.github/workflows/tests.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515

1616
- name: Run Diff Tests
1717
run: |
@@ -20,3 +20,14 @@ jobs:
2020
cd ../examples
2121
./cpptest.sh
2222
git diff --exit-code
23+
24+
build-meson:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
- uses: actions/setup-python@v5
30+
- uses: BSFishy/[email protected]
31+
with:
32+
action: test
33+
meson-version: 1.4.1

examples/meson.build

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh'))
2+
3+
tests = {
4+
'INIReaderExample': { 'args': [] },
5+
}
6+
7+
foreach name, properties : tests
8+
exe = executable('unittest_' + name, src_inih, src_INIReader, 'INIReaderExample.cpp', cpp_args : ['-Wall', properties['args']])
9+
test('test_' + name, runtest, depends : [exe], args : [files('cpptest.txt'), exe.full_path()])
10+
endforeach

meson.build

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ project('inih',
22
['c'],
33
license : 'BSD-3-Clause',
44
version : '58',
5-
default_options : ['cpp_std=c++11']
5+
default_options : ['cpp_std=c++11'],
6+
meson_version: '>=0.56.0'
67
)
78

89
#### options ####
@@ -71,8 +72,10 @@ endif
7172
#### inih ####
7273
inc_inih = include_directories('.')
7374

75+
src_inih = files('ini.c')
76+
7477
lib_inih = library('inih',
75-
['ini.c'],
78+
[src_inih],
7679
include_directories : inc_inih,
7780
c_args : [arg_static, extra_args],
7881
install : distro_install,
@@ -96,13 +99,17 @@ inih_dep = declare_dependency(
9699
include_directories : inc_inih
97100
)
98101

102+
subdir('tests')
103+
99104
#### INIReader ####
100105
if get_option('with_INIReader')
101106
add_languages('cpp')
102107
inc_INIReader = include_directories('cpp')
103108

109+
src_INIReader = files(join_paths('cpp', 'INIReader.cpp'))
110+
104111
lib_INIReader = library('INIReader',
105-
['cpp/INIReader.cpp'],
112+
src_INIReader,
106113
cpp_args : extra_args,
107114
include_directories : inc_INIReader,
108115
dependencies : inih_dep,
@@ -126,4 +133,6 @@ if get_option('with_INIReader')
126133
include_directories : inc_INIReader,
127134
compile_args : extra_args
128135
)
136+
137+
subdir('examples')
129138
endif

tests/meson.build

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh'))
2+
3+
tests = {
4+
'multi': { 'args': [] },
5+
'multi_max_line': { 'args': ['-DINI_MAX_LINE=20'] },
6+
'single': { 'args': ['-DINI_ALLOW_MULTILINE=0'] },
7+
'disallow_inline_comments': { 'args': ['-DINI_ALLOW_INLINE_COMMENTS=0'] },
8+
'stop_on_first_error': { 'args': ['-DINI_STOP_ON_FIRST_ERROR=1'] },
9+
'handler_lineno': { 'args': ['-DINI_HANDLER_LINENO=1'] },
10+
'string': { 'src': 'unittest_string.c', 'args': ['-DINI_MAX_LINE=20'] },
11+
'heap': { 'args': ['-DINI_USE_STACK=0'] },
12+
'heap_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] },
13+
'heap_realloc': { 'args': ['-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] },
14+
'heap_realloc_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] },
15+
'heap_string': { 'src': 'unittest_string.c', 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] },
16+
'call_handler_on_new_section': { 'args': ['-DINI_CALL_HANDLER_ON_NEW_SECTION=1'] },
17+
'allow_no_value': { 'args': ['-DINI_ALLOW_NO_VALUE=1'] },
18+
'alloc': { 'src': 'unittest_alloc.c', 'args': ['-DINI_CUSTOM_ALLOCATOR=1', '-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=12'] }
19+
}
20+
21+
foreach name, properties : tests
22+
test_src = 'src' in properties ? properties['src'] : 'unittest.c'
23+
exe = executable('unittest_' + name, src_inih, test_src, c_args : ['-Wall', properties['args']])
24+
test('test_' + name, runtest, depends : [exe], args : [files('baseline_' + name + '.txt'), exe.full_path()])
25+
endforeach

tests/runtest.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
cd "$(dirname "${1}")"
6+
diff "${1}" <("${2}")

0 commit comments

Comments
 (0)