Skip to content

Commit e89705f

Browse files
Make C test data directory configurable via TSI_TEST_DATA_DIR env var
1 parent f22781b commit e89705f

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

lib/meson.build

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ tsinfer_lib = static_library('tsinfer',
2323
sources: tsinfer_sources, dependencies: [m_dep, tskit_dep],
2424
c_args: extra_c_args, link_with:[avl_lib])
2525

26-
unit_tests = executable('tests',
27-
sources: ['tests/tests.c'],
26+
src_root = meson.project_source_root()
27+
28+
unit_tests = executable('tests',
29+
sources: ['tests/tests.c'],
2830
link_with: [tsinfer_lib], dependencies:[cunit_dep, tskit_dep])
29-
test('Unit tests', unit_tests)
31+
test('Unit tests', unit_tests,
32+
env: ['TSI_TEST_DATA_DIR=' + src_root + '/test_data/'])

lib/tests/tests.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@
3333

3434
#include <CUnit/Basic.h>
3535

36-
/* FIXME this needs to be updated somehow to allow the tests to be run from
37-
* different directories, i.e., with ninja -C build test
38-
*/
39-
#define TEST_DATA_DIR "test_data"
40-
4136
/* Global variables used for test in state in the test suite */
4237

4338
char *_tmp_file_name;
4439
FILE *_devnull;
40+
static const char *_test_data_dir;
4541

4642
tsk_treeseq_t _single_tree_ex_ts;
4743
/* 3.00┊ 0 ┊ */
@@ -1317,14 +1313,19 @@ tsinfer_suite_init(void)
13171313
if (_devnull == NULL) {
13181314
return CUE_SINIT_FAILED;
13191315
}
1316+
_test_data_dir = getenv("TSI_TEST_DATA_DIR");
1317+
if (_test_data_dir == NULL) {
1318+
_test_data_dir = "test_data/";
1319+
}
13201320

1321-
ret = tsk_treeseq_load(
1322-
&_single_tree_ex_ts, TEST_DATA_DIR "/single_tree_example.trees", 0);
1321+
char path[4096];
1322+
snprintf(path, sizeof(path), "%s%s", _test_data_dir, "single_tree_example.trees");
1323+
ret = tsk_treeseq_load(&_single_tree_ex_ts, path, 0);
13231324
if (ret != 0) {
13241325
return CUE_SINIT_FAILED;
13251326
}
1326-
ret = tsk_treeseq_load(
1327-
&_multi_tree_ex_ts, TEST_DATA_DIR "/multi_tree_example.trees", 0);
1327+
snprintf(path, sizeof(path), "%s%s", _test_data_dir, "multi_tree_example.trees");
1328+
ret = tsk_treeseq_load(&_multi_tree_ex_ts, path, 0);
13281329
if (ret != 0) {
13291330
return CUE_SINIT_FAILED;
13301331
}

0 commit comments

Comments
 (0)