Skip to content

Commit 0413dca

Browse files
committed
👷 [Runtime] enable unittest on Ci
1 parent 57e2d57 commit 0413dca

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎.github/workflows/runtime.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ jobs:
2020
run: |
2121
cmake -B build -G Ninja -S runtime -DBUILD_TESTING=ON
2222
cmake --build build --parallel
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.x'
26+
- name: Install dependencies & Generate TN models
27+
run: |
28+
pip install pynini importlib_resources
29+
python -m tn --language zh --overwrite_cache
30+
- name: Run tests
31+
run: ctest --test-dir build/test --output-on-failure
2332

2433
build-windows:
2534
name: build (windows-latest)
@@ -45,6 +54,8 @@ jobs:
4554
cmake --version
4655
gcc --version
4756
57+
# Tests are skipped on Windows: processor_test needs zh_tn_*.fst, which
58+
# are generated via pynini, and pynini has no Windows build.
4859
cmake -S runtime -B build -G Ninja \
4960
-DCMAKE_BUILD_TYPE=Release \
5061
-DBUILD_TESTING=OFF

‎runtime/test/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ endif()
1515

1616
add_executable(processor_test processor_test.cc)
1717
target_link_libraries(processor_test PUBLIC wetext_processor)
18+
# Inject an absolute path to the *.fst models and golden data so the test does
19+
# not depend on the working directory.
20+
target_compile_definitions(processor_test PRIVATE
21+
WETEXT_TN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../tn")
1822
gtest_discover_tests(processor_test)

‎runtime/test/processor_test.cc‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "processor/wetext_processor.h"
2121
#include "utils/wetext_string.h"
2222

23+
// Absolute path to the dir with *.fst models and golden data, injected by CMake
24+
// so the test does not depend on the current working directory.
25+
#ifndef WETEXT_TN_DIR
26+
#define WETEXT_TN_DIR "../tn"
27+
#endif
28+
2329
std::vector<std::pair<std::string, std::string>> ParseTestCase(
2430
const std::string& file_path) {
2531
const std::string delimiter = "=>";
@@ -52,8 +58,8 @@ class ProcessorTest
5258
std::string spoken;
5359

5460
virtual void SetUp() {
55-
std::string tagger_path = "../tn/zh_tn_tagger.fst";
56-
std::string verbalizer_path = "../tn/zh_tn_verbalizer.fst";
61+
std::string tagger_path = WETEXT_TN_DIR "/zh_tn_tagger.fst";
62+
std::string verbalizer_path = WETEXT_TN_DIR "/zh_tn_verbalizer.fst";
5763
processor = new wetext::Processor(tagger_path, verbalizer_path);
5864
written = GetParam().first;
5965
spoken = GetParam().second;
@@ -67,6 +73,6 @@ TEST_P(ProcessorTest, NormalizeTest) {
6773
}
6874

6975
std::vector<std::pair<std::string, std::string>> test_cases =
70-
ParseTestCase("../tn/chinese/test/data/normalizer.txt");
76+
ParseTestCase(WETEXT_TN_DIR "/chinese/test/data/normalizer.txt");
7177
INSTANTIATE_TEST_SUITE_P(NormalizeTest, ProcessorTest,
7278
testing::ValuesIn(test_cases));

0 commit comments

Comments
 (0)