Skip to content

Testing Guide ​

The core repository tests the C++ core, WASM and Python bindings, native CLI, MCP oracle, examples, and cross-binding parity. The Go binding is maintained and tested in its own repository.

Test Architecture ​

LayerFrameworkLocationDescription
C++ Unit/IntegrationGoogle Testtests/**/*.cppCore library, dictionary, grammar, normalization
Data-DrivenJSON + Google Testtests/data/tokenization/*.jsonTokenization correctness (auto-discovered)
WASMVitestbindings/wasm/tests/JS/C API, memory layout, generated ABI compatibility
Pythonpytestbindings/python/tests/Analyze/tags API, errors, ABI layout
CLIBuilt-intest / test benchmarkSingle/batch tests and benchmarks
GoGo testgo-suzumecgo API, ownership, dictionaries, and concurrency

Running Tests ​

C++ Tests ​

bash
# Build dictionaries and run the native tests
make native-test

# Or manually:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
cmake --build build --target build-dict   # Required: build dictionaries first
build/bin/suzume_test
ctest --test-dir build --output-on-failure -R native_cli_contract

Run specific tests by name pattern:

bash
ctest --test-dir build -R "ConjugationTest" --output-on-failure
ctest --test-dir build -R "UserDict" --verbose

WASM Tests ​

bash
# Build WASM and run tests
make wasm-test

# Or run tests only (if WASM is already built)
(cd bindings/wasm && yarn test)
(cd bindings/wasm && yarn test:watch)      # Watch mode
(cd bindings/wasm && yarn test:coverage)   # With coverage report

Python Tests ​

bash
make python-test
# Run pytest only (uv syncs the locked environment on first use):
(cd bindings/python && uv run --locked pytest -q)

make python-test also builds the binding and dictionaries, then runs Ruff and mypy.

Go Tests ​

Run the binding tests from the separate go-suzume repository:

bash
make test
make test-race

The first command builds the native library and runs go test ./... -count=1; the second runs the race-detector suite.

CLI Test Command ​

bash
# Test single input
suzume-cli test "東京スカイツリー" --expect "東京,スカイツリー"

# Run tests from file
suzume-cli test --file tests.tsv

# With user dictionary
suzume-cli test --file tests.tsv -d user.dic

The test command compares sets of generated tags, not the ordered token sequence from analyze. Default tag generation uses base forms, excludes particles, auxiliaries, formal nouns, and low-information words, and ignores tag order and duplicates. The default minimum tag length is two characters; use analyze when you need token boundaries and POS output.

Adding Tests ​

Expectations in tests/data/tokenization/*.json are generated from the MeCab expectation pipeline and auto-discovered by universal_tokenization_test.cpp.

Do not edit generated fixtures directly

Both tests/data/tokenization/*.json and data/**/*.tsv are tooling-managed; repository hooks block direct writes. Do not change an expected token merely to match current Suzume output. Fix the analyzer or the pipeline rule, then regenerate through the tooling.

With the repository MCP server configured, a mismatch goes through one of two fixes before the case is registered:

Fix the rule, never the expectation
test_show compares Suzume with the expected tokens; on a match, test_add registers the case. If Suzume is wrong, fix the tokenizer rule and rebuild; if the expectation is wrong, fix the normalization rule and sync with test_needs_suzume_update. Both paths return to test_show.Suzume wrongFix the tokenizer rulesrc/Rebuildcmake --build buildcheck again with test_showtest_showSuzume vs expected tokensmatches expectedtest_addregister the regression caseexpected wrongFix the normalization rulesuzume_mcp/core/test_needs_suzume_updateapply=Truecheck again with test_show
Only the normalization pipeline decides an expectation. A normalization change takes effect without a rebuild, but existing fixtures keep the old expectation until test_needs_suzume_update syncs them.
text
test_show(input_text="問題文")
# Fix the tokenizer rule and rebuild, or fix the pipeline rule.
test_show(input_text="問題文")
test_add(input_text="問題文", file="verb_example.json")

The pipeline rules live under scripts/mcp/src/suzume_mcp/core/. See the repository CONTRIBUTING.md and AGENTS.md for the current workflow and tool reference.

POS labels in fixtures

The pos values in these JSON fixtures use a Title-case reference taxonomy (Noun, Particle, …). This is a separate label set from the runtime Morpheme.pos values returned by the library, which are UPPERCASE English (NOUN, PARTICLE, …). Don't assume the two match verbatim.

Existing Test Files ​

The suite grows over time and is organized by linguistic category. A representative selection:

CategoryDescription
basic.jsonBasic tokenization, single words
adjective*.jsoni-adjectives, na-adjectives, compounds
verb*.jsonIchidan, godan, suru, passive, causative
particle*.jsonCase, topic, binding particles
usecase_*.jsonReal-world texts: news, business, casual
pattern_*.jsonLinguistic patterns

C++ Unit Tests ​

For testing internal modules directly:

  1. Create tests/category/new_test.cpp
  2. Add to TEST_SOURCES in tests/CMakeLists.txt
cpp
#include <gtest/gtest.h>
#include "module_header.h"

TEST(ModuleTest, SpecificBehavior) {
    // Arrange
    auto input = ...;

    // Act
    auto result = module.process(input);

    // Assert
    EXPECT_EQ(result.field, expected_value);
}

WASM Tests ​

For testing the WebAssembly bindings:

Create bindings/wasm/tests/feature.test.ts:

typescript
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { Suzume } from '../dist/index.js'

describe('Feature', () => {
  let suzume: Suzume

  beforeAll(async () => {
    suzume = await Suzume.create()
  })

  afterAll(() => {
    suzume.destroy()
  })

  it('should behave correctly', () => {
    const morphemes = suzume.analyze('テスト')
    expect(morphemes[0].surface).toBe('テスト')
  })
})

CLI Test Files (TSV) ​

For batch testing via the CLI:

tsv
# Comments start with #
東京スカイツリーに行きました	東京,スカイツリー,行く
美しい花が咲いている	美しい,咲く

Run with:

bash
suzume-cli test --file tests.tsv

The batch command prints details for failures and a summary with pass/fail counts. Add --verbose to see passing cases too.

Benchmarks ​

The CLI includes a built-in benchmark command:

bash
# Built-in test texts with the default measurement settings
suzume-cli test benchmark

# Control steady iterations, statistical samples, and warmup
suzume-cli test benchmark --iterations=5 --samples=3 --warmup=2

# With custom corpus
suzume-cli test benchmark --file corpus.txt

Metrics reported include initialization time, first-analysis latency, median steady-state latency, byte throughput, per-text latency, and peak RSS. Multiple samples make the steady-state median less sensitive to one-off noise.

Debug Builds ​

With Sanitizers ​

bash
# AddressSanitizer
cmake -B build-asan -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZER=ON -DENABLE_ASAN=ON
cmake --build build-asan --parallel
cmake --build build-asan --target build-dict
ctest --test-dir build-asan --output-on-failure

# UndefinedBehaviorSanitizer
cmake -B build-ubsan -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZER=ON -DENABLE_UBSAN=ON
cmake --build build-ubsan --parallel
cmake --build build-ubsan --target build-dict
ctest --test-dir build-ubsan --output-on-failure

# ThreadSanitizer
cmake -B build-tsan -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZER=ON -DENABLE_TSAN=ON
cmake --build build-tsan --parallel
cmake --build build-tsan --target build-dict
ctest --test-dir build-tsan --output-on-failure

make asan is the standard aggregate for AddressSanitizer, LeakSanitizer, and UndefinedBehaviorSanitizer.

With Coverage ​

bash
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON
cmake --build build --parallel
cmake --build build --target build-dict
ctest --test-dir build --output-on-failure
# Coverage files generated in build/

CI ​

GitHub Actions runs on pushes to main and develop, and on pull requests to main and develop. Changes that touch only Markdown, docs/ or LICENSE do not start the workflow. A pull request to develop runs only lint, guardrails and build-and-test.

JobRuns onWhat it checks
lintEvery eventBiome on the WASM binding; Ruff on the MCP server and repository scripts
guardrailsEvery eventCode guardrail ratchet, WASM-core purity, oracle overrides, binding label tables, oracle mirrors of core data, and version mirrors
mcp-testsEvery event except pull requests to developMCP server tests and that stored test expectations match a fresh derivation
sanitizersEvery event except pull requests to developNative tests under ASan, LSan, and UBSan
native-nodebugEvery event except pull requests to developNative tests with the debug features compiled out
score-parityEvery event except pull requests to developThe debug build and the shipped build give every morpheme of the tokenization test inputs the same score
cmake-configurationsEvery event except pull requests to developEach supported CMake build and install configuration
manylinux-toolchainPushes and pull requests to mainBuilding and testing the wheel with the oldest supported toolchain
macos-wheelPushes and pull requests to mainBuilds the Python wheel on macOS 26 (arm64), smoke-tests it outside the checkout, and runs the binding tests against the installed wheel
build-and-testEvery eventNative tests with coverage, examples and installed-package consumers, WASM build/size/tests, and native/Python/WASM parity
python-bindingPushes and pull requests to mainruff check / ruff format --check, mypy, pytest, and the Python example

make consumer-smoke runs in build-and-test. make format-check (including C++ clang-format) remains a local verification target and is not wired into CI.

Makefile Targets ​

TargetDescription
make testRun native (with and without debug features), MCP, oracle-sync, Python, WASM, example, consumer, CMake-configuration, parity, and guardrail checks
make buildBuild the project
make dictBuild the project, then compile dictionaries
make wasm-testBuild WASM + run WASM tests
make python-testBuild and test the Python binding, including lint/type checks
make examplesBuild the in-tree C and C++ examples
make consumer-smokeTest an installed package through find_package
make version-checkVerify versions across binding manifests
make formatFormat/lint C++, MCP, WASM, and Python sources
make format-checkCheck formatting across all languages