Skip to content

Commit

Permalink
Switch tests to use meson
Browse files Browse the repository at this point in the history
Switches 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
```
  • Loading branch information
matoro committed May 7, 2024
1 parent 077174e commit f0ec5f9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 82 deletions.
5 changes: 0 additions & 5 deletions examples/cpptest.sh

This file was deleted.

4 changes: 4 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -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()])
12 changes: 10 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,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,
Expand All @@ -96,13 +98,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,
Expand All @@ -126,4 +132,6 @@ if get_option('with_INIReader')
include_directories : inc_INIReader,
compile_args : extra_args
)

subdir('examples')
endif
6 changes: 6 additions & 0 deletions runtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail

cd "$(dirname "${1}")"
diff "${1}" <("${2}")
46 changes: 46 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -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()])
14 changes: 0 additions & 14 deletions tests/unittest.bat

This file was deleted.

61 changes: 0 additions & 61 deletions tests/unittest.sh

This file was deleted.

0 comments on commit f0ec5f9

Please sign in to comment.