Uns☁und

An extensible and unsound programming languages framework

(This page might be a bit more readable if you enable 1st-party CSS.)

Testing

Most of the tests for Unsound amount to testing the result of parsing, compiling, emitting, and interpreting languages composed of various extensions. To this end tests can be defined in custom *.test files that allow easily specifying which language extensions to use, and which phases to run.

Test File Format

Each file is comprised of a usc-directive indicating how to invoke usc, usually specifying the extensions needed to run the tests.

# usc -x core -x meso -x thermo

Then there are several tests, each consisting of a title, input, and multiple expected outputs. For each output we define which phases of the framework should be executed, using the extensions defined in the usc-comment.

--- test name
input (source, AST JSON, or IR JSON based on first phase)
=== phase: $impl[, phase: $impl, ...]
expected output

Pipeline Shorthands

When using the standard implementation for a phase, you can omit the $impl:

=== parse, compile, emit, interpret

is equivalent to:

=== parse: $parse, compile: $compile, emit: $emit, interpret: $interpret

An empty === runs the default pipeline (parse, compile, emit, interpret):

--- simple eval test
1 + 2
===
3

Multiple Pipelines

You can define multiple === blocks, each with their own pipeline:

# usc -x core -x meso

--- parse test
let x = 1 in x
=== parse: $parse
{"type":"LetExpr",...}
=== parse: $parse, compile: $compile, interpret: $interpret
1

--- compile test (input is AST JSON)
{"type":"Literal","value":42}
=== compile: $compile, emit: $emit
$.number(42)

--- eval test
1 + 2
=== parse: $parse, compile: $compile, interpret: $interpret
3

Error Tests

Use error as a terminal phase to indicate an error is expected:

--- parse error: missing in keyword
let x = 1 x
=== parse, error
Parse error

--- compile error: const assignment
const x = 1; x = 2
=== parse, compile, error
Cannot assign to const

--- any error in full pipeline
some bad code
=== error

The expected output is matched against the error message (partial match). If omitted, any error is accepted.

Running Tests

bun run test

This runs all *.test files in the project.