The compliance tests verify that Go code can be correctly transpiled to TypeScript and produce the same output as the original Go code.
Each compliance test is a directory under tests/tests/ containing:
Core Files:
*.go- Go source code to be transpiled*.gs.ts- Generated TypeScript files (auto-created, do not edit manually)expected.log- Expected output when running the code (auto-generated from Go if missing)actual.log- Actual output from TypeScript (created when tests fail)
Configuration Files (all optional):
packages: List of packages to compile (one per line, supports comments with #)skip-test: Skip this test entirelyexpect-fail: Test compilation but skip executionskip-typecheck: Skip TypeScript type checkingexpect-typecheck-fail: Expect TypeScript type checking to failskip-dependencies: compile only the fixture package, not its imports
Generated Files:
index.ts- Package index files (auto-generated)tsconfig.json- TypeScript configuration for type checking (auto-generated)
When a compliance test runs, the following steps occur:
- Creates a temporary
run/directory in the test folder - Sets up TypeScript configuration files
- Determines which packages need to be compiled
- Compiles Go source files to TypeScript using the GoScript compiler
- Outputs to
run/output/@goscript/MODULE_PATH/tests/tests/TEST_NAME/ - Copies generated
.gs.tsandindex.tsfiles back to the test directory - Adds header comments to
.gs.tsfiles indicating they're auto-generated - Type checking resolves each fixture's own emitted
run/output/@goscript/closure first
- Generates a
runner.tsscript that imports and executes the main function - Runs the TypeScript code using
bun - Captures stdout output
- Compares TypeScript output with
expected.log - If
expected.logdoesn't exist, generates it by runninggo run ./ - Creates
actual.logif outputs differ
- Generates a
tsconfig.jsonfor type checking the generated files - Runs
tsrsto verify TypeScript types are correct - Uses path mapping to resolve
@goscript/*imports
Tests can contain multiple packages in subdirectories:
test_name/
├── main.go # Main package
├── subpkg/
│ └── helper.go # Subpackage
└── packages # Optional: explicit package list
The compiler auto-detects packages by scanning for .go files, or uses the packages file if present.
packages file format:
./
./subpkg
./another/package
# Lines starting with # are comments
The test system handles dependencies per fixture:
- Builtin packages - Handwritten TypeScript in
gs/directory - Fixture dependencies - Compiled into the fixture's own
run/output/@goscript/closure and type checked from there - Path mapping - TypeScript imports resolve
@goscript/*to the fixture's emitted output first, thengs/, then the legacytests/deps/tree
Each fixture type checks against exactly the bytes its own compilation graph produced; no test writes to tests/deps/. That tree is a legacy explicit repository test-library input kept for older consumers and is scheduled for removal.
go test -v ./compilergo test -timeout 30s -run '^TestCompliance/[^/]+/test_name$' ./compiler