Unified Test Harness for Terrace
This directory contains the unified test harness for all Terrace language implementations. The harness automatically discovers and runs tests across all supported languages: JavaScript, C, Python, Go, and Rust.
Features
- Cross-language testing: Run the same tests across all language implementations
- Automatic test discovery: Finds all
.tce
test files in the project - Flexible test definitions: Tests are defined in human-readable
.tce
files - Build integration: Automatically builds required binaries (C test runner)
- Comprehensive reporting: Detailed test results with pass/fail status
Test File Format
Test files use the Terrace format with the following structure:
#schema test
describe Test Suite Name
it Test description
key test-key
packages js c python go rust
input
test input data
more input lines
output
expected output line 1
expected output line 2
Fields
describe
: Defines a test suiteit
: Defines a test casekey
: The test identifier passed to language implementationspackages
: Space-separated list of packages to test (js, c, python, go, rust)input
: Test input data (optional)output
: Expected output (optional for Go/Rust which use different testing frameworks)
Usage
Run all tests
npm test
# or
npm run test:unified
Run specific test
node test/test-runner.js <test-key>
Run tests for specific packages
PACKAGES="js python" node test/test-runner.js <test-key>
Supported Test Keys
JavaScript
linedata:basic
- Basic line data parsinglinedata:tabs
- Tab-based indentationlinedata:head-tail
- Head/tail parsingnew-api:basic
- Basic new API functionalitynew-api:hierarchical
- Hierarchical document parsingnew-api:functional
- Functional API featuresnew-api:node-methods
- Node method testingnew-api:inconsistent-indentation
- Arbitrary nesting
C
linedata:basic
- Basic line data parsinglinedata:tabs
- Tab-based indentationlinedata:head-tail
- Head/tail parsingnew-api:basic
- Basic new API functionalitynew-api:hierarchical
- Hierarchical document parsingnew-api:string-views
- String view functionalitynew-api:legacy-compat
- Legacy API compatibility
Python
linedata:basic
- Basic line data parsinglinedata:tabs
- Tab-based indentationlinedata:head-tail
- Head/tail parsingnew-api:basic
- Basic new API functionalitynew-api:hierarchical
- Hierarchical document parsingnew-api:functional
- Functional API featuresnew-api:node-methods
- Node method testingnew-api:readers
- Reader utilities
Go
TestTerraceDocument
- Document parsing testsTestTerraceNode
- Node functionality tests
Rust
test_basic_parsing
- Basic parsing functionalitytest_navigation_methods
- Navigation and traversal
Adding New Tests
- Create a new
.tce
file in thetest/
directory or modify existing ones - Define test suites and cases using the Terrace format
- Specify which packages should run the test
- Add the test key to the appropriate language implementation's test runner
- Update the
supports
array intest-runner.js
if needed
Test Output Format
Each language implementation should output test results in a consistent format for comparison. The expected format varies by test type:
- LineData tests:
| level X | indent Y | offsetHead Z | offsetTail W | line TEXT |
- New API tests:
| level X | head "HEAD" | tail "TAIL" | content "CONTENT" |
- Node method tests:
Node: head="HEAD", tail="TAIL", isEmpty=BOOL, is(NAME)=BOOL
- Go/Rust tests: Simple "Test passed" message
Integration with CI/CD
The test harness is designed to work with CI/CD systems:
- Returns exit code 0 on success, 1 on failure
- Provides detailed output for debugging
- Can be run in parallel across different environments
- Supports selective test execution
Dependencies
The test harness requires:
- Node.js for the test runner
- Build tools for each language (make, go, cargo, etc.)
- All language implementations to be properly set up
Troubleshooting
Common Issues
- C tests fail: Ensure the C test runner is built with
make
inpackages/c/
- Go tests fail: Ensure Go modules are properly initialized
- Rust tests fail: Ensure Cargo dependencies are installed
- Python tests fail: Ensure Python dependencies are installed
- Test discovery fails: Check that
.tce
files have correct syntax
Debug Mode
Run with verbose output:
DEBUG=1 node test/test-runner.js