Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meson test driver #170

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
matoro marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Diff Tests
run: |
Expand All @@ -20,3 +20,14 @@ jobs:
cd ../examples
./cpptest.sh
git diff --exit-code

build-meson:
matoro marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: BSFishy/[email protected]
with:
action: test
meson-version: 1.4.1
10 changes: 10 additions & 0 deletions examples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh'))

tests = {
'INIReaderExample': { 'args': [] },
}

foreach name, properties : tests
exe = executable('unittest_' + name, src_inih, src_INIReader, 'INIReaderExample.cpp', cpp_args : ['-Wall', properties['args']])
test('test_' + name, runtest, depends : [exe], args : [files('cpptest.txt'), exe.full_path()])
endforeach
15 changes: 12 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'
matoro marked this conversation as resolved.
Show resolved Hide resolved
)

#### options ####
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -126,4 +133,6 @@ if get_option('with_INIReader')
include_directories : inc_INIReader,
compile_args : extra_args
)

subdir('examples')
endif
25 changes: 25 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
runtest = files(join_paths(meson.project_source_root(), 'tests', 'runtest.sh'))

tests = {
'multi': { 'args': [] },
'multi_max_line': { 'args': ['-DINI_MAX_LINE=20'] },
'single': { 'args': ['-DINI_ALLOW_MULTILINE=0'] },
'disallow_inline_comments': { 'args': ['-DINI_ALLOW_INLINE_COMMENTS=0'] },
'stop_on_first_error': { 'args': ['-DINI_STOP_ON_FIRST_ERROR=1'] },
'handler_lineno': { 'args': ['-DINI_HANDLER_LINENO=1'] },
'string': { 'src': 'unittest_string.c', 'args': ['-DINI_MAX_LINE=20'] },
'heap': { 'args': ['-DINI_USE_STACK=0'] },
'heap_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] },
'heap_realloc': { 'args': ['-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] },
'heap_realloc_max_line': { 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=5'] },
'heap_string': { 'src': 'unittest_string.c', 'args': ['-DINI_USE_STACK=0', '-DINI_MAX_LINE=20', '-DINI_INITIAL_ALLOC=20'] },
'call_handler_on_new_section': { 'args': ['-DINI_CALL_HANDLER_ON_NEW_SECTION=1'] },
'allow_no_value': { 'args': ['-DINI_ALLOW_NO_VALUE=1'] },
'alloc': { 'src': 'unittest_alloc.c', 'args': ['-DINI_CUSTOM_ALLOCATOR=1', '-DINI_USE_STACK=0', '-DINI_ALLOW_REALLOC=1', '-DINI_INITIAL_ALLOC=12'] }
}

foreach name, properties : tests
test_src = 'src' in properties ? properties['src'] : 'unittest.c'
exe = executable('unittest_' + name, src_inih, test_src, c_args : ['-Wall', properties['args']])
test('test_' + name, runtest, depends : [exe], args : [files('baseline_' + name + '.txt'), exe.full_path()])
endforeach
6 changes: 6 additions & 0 deletions tests/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}")
Loading