diff --git a/.github/workflows/runtime.yml b/.github/workflows/runtime.yml index 2ebacaa..2edf961 100644 --- a/.github/workflows/runtime.yml +++ b/.github/workflows/runtime.yml @@ -20,6 +20,18 @@ jobs: run: | cmake -B build -G Ninja -S runtime -DBUILD_TESTING=ON cmake --build build --parallel + - uses: actions/setup-python@v5 + if: matrix.os == 'ubuntu-latest' + with: + python-version: '3.x' + - name: Install dependencies & Generate TN models + if: matrix.os == 'ubuntu-latest' + run: | + pip install pynini importlib_resources + python -m tn --language zh --overwrite_cache + - name: Run tests + if: matrix.os == 'ubuntu-latest' + run: ctest --test-dir build/test --output-on-failure build-windows: name: build (windows-latest) @@ -45,6 +57,8 @@ jobs: cmake --version gcc --version + # Tests are skipped on Windows: processor_test needs zh_tn_*.fst, which + # are generated via pynini, and pynini has no Windows build. cmake -S runtime -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_TESTING=OFF diff --git a/runtime/test/CMakeLists.txt b/runtime/test/CMakeLists.txt index bf1b67f..4b43bb7 100644 --- a/runtime/test/CMakeLists.txt +++ b/runtime/test/CMakeLists.txt @@ -15,4 +15,8 @@ endif() add_executable(processor_test processor_test.cc) target_link_libraries(processor_test PUBLIC wetext_processor) +# Inject an absolute path to the *.fst models and golden data so the test does +# not depend on the working directory. +target_compile_definitions(processor_test PRIVATE + WETEXT_TN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../tn") gtest_discover_tests(processor_test) diff --git a/runtime/test/processor_test.cc b/runtime/test/processor_test.cc index e4be967..16e91bc 100644 --- a/runtime/test/processor_test.cc +++ b/runtime/test/processor_test.cc @@ -20,6 +20,12 @@ #include "processor/wetext_processor.h" #include "utils/wetext_string.h" +// Absolute path to the dir with *.fst models and golden data, injected by CMake +// so the test does not depend on the current working directory. +#ifndef WETEXT_TN_DIR +#define WETEXT_TN_DIR "../tn" +#endif + std::vector> ParseTestCase( const std::string& file_path) { const std::string delimiter = "=>"; @@ -52,8 +58,8 @@ class ProcessorTest std::string spoken; virtual void SetUp() { - std::string tagger_path = "../tn/zh_tn_tagger.fst"; - std::string verbalizer_path = "../tn/zh_tn_verbalizer.fst"; + std::string tagger_path = WETEXT_TN_DIR "/zh_tn_tagger.fst"; + std::string verbalizer_path = WETEXT_TN_DIR "/zh_tn_verbalizer.fst"; processor = new wetext::Processor(tagger_path, verbalizer_path); written = GetParam().first; spoken = GetParam().second; @@ -67,6 +73,6 @@ TEST_P(ProcessorTest, NormalizeTest) { } std::vector> test_cases = - ParseTestCase("../tn/chinese/test/data/normalizer.txt"); + ParseTestCase(WETEXT_TN_DIR "/chinese/test/data/normalizer.txt"); INSTANTIATE_TEST_SUITE_P(NormalizeTest, ProcessorTest, testing::ValuesIn(test_cases));