From 3852c4efc918f0b7e3a6b5688c20287fb3863fc2 Mon Sep 17 00:00:00 2001 From: Mitja HORVAT Date: Wed, 22 Sep 2021 19:22:37 +0200 Subject: [PATCH] meson: Add unit test framework This commit also adds the first unit test. The unit test compares the phonetic map generated by the Python and by the C implementation and fails if the generated maps are different. --- meson.build | 1 + tests/meson.build | 12 ++++++++++++ tests/test_phogen_map | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/meson.build create mode 100755 tests/test_phogen_map diff --git a/meson.build b/meson.build index 18daa75..1b33af6 100644 --- a/meson.build +++ b/meson.build @@ -8,3 +8,4 @@ PHOGEN_WORD_LIST = files('data/words_alpha.txt.backup') subdir('c') subdir('python') +subdir('tests') diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..bda9fd7 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,12 @@ + +_phogen_map_c = PHOGEN_MAP_EXE.full_path() +_phogen_map_py = meson.source_root() / '@0@'.format(PHOGEN_MAP_PY[0]) +_word_list = meson.source_root() / '@0@'.format(PHOGEN_WORD_LIST[0]) + +test('test_phogen_map', + find_program('test_phogen_map'), + env : ['PHOGEN_MAP_C=@0@'.format(_phogen_map_c), + 'PHOGEN_MAP_PY=@0@'.format(_phogen_map_py), + 'PHOGEN_WORD_LIST=@0@'.format(_word_list)]) + + diff --git a/tests/test_phogen_map b/tests/test_phogen_map new file mode 100755 index 0000000..ee3ad79 --- /dev/null +++ b/tests/test_phogen_map @@ -0,0 +1,37 @@ +#!/bin/sh -ex +# +# Test Case: +# +# Use the Python and C implementations to produce the various tables. Compare +# if the generated files are identical for both. +# +# Environment: +# +# PHOGEN_MAP_C - should point to the C executable +# PHOGEN_MAP_PY - should point to the Python executable +# PHOGEN_WORD_LIST - word list + +function on_exit() +{ + rm -v /tmp/phogen_*_$$.h + rm -v /tmp/phogen_*_$$.json + rm -v /tmp/phogen_*_$$.py +} + +trap on_exit EXIT + +$PHOGEN_MAP_C \ + --input "$PHOGEN_WORD_LIST" \ + --clang "/tmp/phogen_c_$$.h" \ + --python "/tmp/phogen_c_$$.py" \ + --json "/tmp/phogen_c_$$.json" + +$PHOGEN_MAP_PY \ + --input "$PHOGEN_WORD_LIST" \ + --clang "/tmp/phogen_py_$$.h" \ + --python "/tmp/phogen_py_$$.py" \ + --json "/tmp/phogen_py_$$.json" + +cmp /tmp/phogen_c_$$.h /tmp/phogen_py_$$.h +cmp /tmp/phogen_c_$$.py /tmp/phogen_py_$$.py +cmp /tmp/phogen_c_$$.json /tmp/phogen_py_$$.json