mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 08:25:32 +00:00
Had a real yak shave this morning with disabling assertions in release
builds in our C/C++ code. It turns out that our unit tests use
`assert()` which we intended to use from `test_assert.h`, but in some
cases `cassert` or `assert.h` had been #included after `test_assert.h`,
overriding our special `assert()` macro. The chain of includes is
somewhat hard to puzzle out -- it's often buried several levels deep.
This meant that a release build would drop all test assertions, meaning
most tests passed, unsurprisingly, as there were no assertions left to
fail ... but some tests failed with crashes because we optimized out
important lines such as `assert(some_important_function())`.
I was quite unhappy with this fragility, so I have opted to rename
`assert()` to `test_assert()` in all of our home-grown C/C++ unit tests,
which further highlighted unit tests which were only using the C/C++
`assert()` and not ours, so then had to figure out which unit test
executables needed to have `test_assert` added, and then ... then ...
discovered a bug in `test_color.h`, where we were #including
`io.h`/`unistd.h` inside a `namespace console_color {}` block, which
just happened to be the first ref to those beautiful headers, and thus
(because `#pragma once`) meant that useful little functions like
`access()` were no longer accessible to us in the global namespace.
I have also audited Every Single Call to `assert()` to verify that we do
not do Important Work inside the parentheses, and, apart from those
offending unit tests, now resolved with `test_assert()`, it looks like
all is good.
I would like to present one very well-shaved yak in this commit.
Fixes: #12619
37 lines
1.4 KiB
Meson
37 lines
1.4 KiB
Meson
# Copyright: © 2018 SIL International.
|
|
# Description: Cross platform build script to compile unit tests.
|
|
# Create Date: 2 Oct 2018
|
|
# Authors: Tim Eves (TSE)
|
|
# History: 2 Oct 2018 - TSE - Added tests for utfcodec & json.
|
|
# 19 Oct 2018 - TSE - Added kmnkbd directory for API unit tests.
|
|
#
|
|
|
|
# Note: this version of cmpfiles ignores line endings, which is better for platform independence
|
|
cmpfiles = ['-c', 'import sys; a = open(sys.argv[1], \'r\').read(); b = open(sys.argv[2], \'r\').read(); sys.exit(not (a==b))']
|
|
stnds = join_paths(meson.current_source_dir(), 'standards')
|
|
|
|
libsrc = include_directories(
|
|
'../src',
|
|
'../../common/include'
|
|
)
|
|
|
|
# kmx_test_source is required for linux builds, so always enable it even when we
|
|
# disable all other tests
|
|
subdir('kmx_test_source')
|
|
|
|
if get_option('keyman_core_tests')
|
|
message('option "keyman_core_tests" is true, enabling tests')
|
|
|
|
if get_option('default_library') != 'static'
|
|
ctypes_void_p_size = ['-c', 'import ctypes; print(ctypes.sizeof(ctypes.c_void_p))']
|
|
r = run_command(python, ctypes_void_p_size, check: true)
|
|
python_ctypes_compatible = r.stdout().to_int() == cpp_compiler.sizeof('void *')
|
|
if not python_ctypes_compatible
|
|
message('Python ctypes is incompatible with built shared object. Disabling some tests.')
|
|
endif
|
|
endif
|
|
|
|
subdir('unit')
|
|
else
|
|
message('option "keyman_core_tests" is false, disabling tests')
|
|
endif
|