A programming language and its core libraries sit near the bottom of a developer's stack, so people expect them to be reliable. A new Raya release must not break existing programs, even in strange edge cases.
That reliability comes from automated tests. The tests for the language and core libraries, which this page is
about, live under tests/ (the language, corelib, lib, standalone, web, ffi and more) and
runtime/tests/vm/. Raya has several compilers, runtimes and static analysis tools, each with platforms and
options, so the same test runs in many configurations. The test runner and test formats are custom; this page
explains how to use them.
Raya's rule: every change ships with the test that guards it, and main only moves when every test passes.
Raya keeps no known-failures list.
-
test.py, test_runner - The tool that runs tests. Its entry point is
tools/test.py; the code is thetest_runnerpackage inpkg/test_runner. -
Test suite - A collection of test files that can be run together. Most suites are a top-level directory under
tests/:language,corelib,lib,web,co19and so on. A few special suites, such aspkg(package tests) andvm(runtime/tests/vm/), live elsewhere. -
Test - A Raya file (which may reference other files) that the test runner sends to a Raya implementation, and whose behavior it then checks. Most test files end in
_test.ray. -
Configuration - A combination of tools and options used to run a test: "run on the VM on Linux in debug mode", "compile with raya2js and run in Chrome", or "analyze with the Raya analyzer with its asserts on". Each configuration combines architecture, mode, operating system, compiler, runtime and other options.
Several compiler and runtime values that tools/test.py accepts in -c (--compiler) and -r (--runtime)
still carry the upstream tool names. This handbook refers to them by role, written as placeholders.
python3 tools/test.py --help prints every value with a one-line description, so you can pick the one for each
role:
| Placeholder | Role | How --help describes it |
|---|---|---|
<JIT> |
Compile to Kernel, run on the VM's JIT | "Compile ... into Kernel before running test" |
<AOT> |
Compile to Kernel, then to an AOT snapshot | "... Kernel into AOT snapshot before running the test" |
<AOT-runtime> |
Run an AOT snapshot without a JIT (-r) |
"Run a precompiled snapshot on the VM without a JIT" |
<JS> |
raya2js | "Compile to JavaScript using ..." |
<analyzer> |
Static analysis with the Raya analyzer | "Perform static analysis ... using the analyzer" |
Values that don't need a placeholder: -c fasta (the front end's errors, no run), -c ddc (the development JS
compiler), -c app_jitk (app-JIT snapshots), -c none; runtimes -r vm, -r d8, -r jsc, -r chrome,
-r firefox, -r safari and -r none.
Often you don't need -c at all: each runtime has a default compiler. -r vm runs the JIT configuration,
-r <AOT-runtime> the AOT configuration, -r d8 and the browsers raya2js, and -r jsc Raya to wasm.
The test corpus makes sure that the behavior we ship is the behavior we intend to ship. That's more involved than "run the test and fail on any error":
- Some tests check error reporting. Compile errors are specified behavior, so there are tests that say "this program reports a compile error". There "pass" does not mean "runs without error".
- Some tests check behavior that a configuration doesn't support.
raya:ioisn't available on the web, so theraya:iotests "fail" with the web compilers, as intended.
Each test has an intent. A person reading the test's code (and its special comments) should be able to predict what it does. For most tests, the intent is to run to completion without error:
import 'package:expect/expect.ray';
main() {
Expect.equals(3, 1 + 2);
}
Expect.equals() throws if its arguments aren't equal, so this test completes silently if 1 + 2 is 3.
Otherwise it throws an uncaught exception, which the test runner detects.
Other tests check error reporting:
main() {
int i = "not int"; //# 01: compile-time error
}
This test (a "multitest", see below) says that a conforming tool must report a compile-time error when the marked line is included.
Before running a test, the test runner parses it and infers its expectation: what the author says a tool should do. By default the expectation is "pass", but tests can expect runtime or compile-time errors.
When the test runner runs a test, the tool reports a compile error, reports a runtime error, hangs until the runner stops it (a time out), or exits cleanly ("passes"). That observed behavior is the outcome.
The test runner compares the outcome with the expectation, and then with the test's status: hand-written
facts in status files under tests/ and runtime/tests/. In Raya, status files say which
tests don't apply to a configuration (SkipByDesign), which are slow, and similar facts. They are not a list of
known failures: a test that should pass and doesn't stops tool/raya_gate.sh.
Some of this information can live in the test itself instead; see test requirements.
When you run the test runner, it walks the files in the selected suites. For each test file it:
-
Parses the test file to find its expectation. Special marker comments in a test tell the runner what the test intends.
-
Works out which commands to run. For a simple VM test that's "run the VM on the test file". For a web test it's a command that compiles the test to JavaScript and another that runs the result in a JavaScript engine. The test runner has code for each pair of compiler and runtime.
-
Runs the commands. A small dependency-graph build system knows which commands depend on which and runs things in parallel where it can.
-
Determines the outcome from each command's exit code, stdout and stderr.
-
Compares the expectation with the outcome, producing what the runner calls "actual":
expectation + outcome -> actual -------------------------------------------------- Pass + Pass -> Pass CompileTimeError + CompileTimeError -> Pass Pass + CompileTimeError -> CompileTimeError CompileTimeError + Pass -> MissingCompileTimeErrorIf the outcome and the expectation agree, the tool did what the test says it should. If they disagree, there's a failure: an error should have been reported and wasn't, or an unexpected error happened.
-
Compares actual with the status and reports any difference. In its output the runner calls the status "Expected":
FAILED: <analyzer>-none release_x64 language/int_double_plus_test/00 Expected: Pass Actual: MissingCompileTimeErrorHere a new multitest expects a compile-time error that the analyzer doesn't report yet. The fix is to implement the error, not to change the status.
python3 tools/test.py -m release -r vm language/spread_collectionslanguage/spread_collections is a selector: a suite name, then optionally a / and a pattern. The pattern
is a regular expression (with * meaning .*) that a test's path inside the suite must contain. -r vm picks
the runtime, and with it the JIT configuration. Add -c for another compiler, -a for the architecture and
-m for the mode; use the same mode and architecture you built.
Some more examples:
python3 tools/test.py -m release -r vm corelib # a whole suite
python3 tools/test.py -m release -r vm vm/raya_ # the VM's Raya tests
python3 tools/test.py -m release -c <AOT> -r <AOT-runtime> language # AOT
python3 tools/test.py -m release -c fasta -r none language # the front end's static errors
python3 tools/test.py -m release -r d8 web # raya2js on d8python3 tools/test.py --help lists every option. -j <n> sets parallelism and --progress line (or
-pcolor) the output style.
Configurations can also be given by name with -n. The names are defined in the test matrix,
tools/bots/test_matrix.json. To find one, pass --find-configurations
with any of -m, -c, -r, -a and -s as filters:
python3 tools/test.py --find-configurations -r d8Without filters, mode defaults to release, system to your OS and arch to x64; pass all to any of
them to not filter on it.
To run a few tests without building the whole SDK, tools/build_test_fast.py infers the compiler from the test
path, builds only the targets that compiler needs, and runs tools/test.py:
# Infers Raya to wasm and builds only its targets.
python3 tools/build_test_fast.py tests/web/wasm/simd/simd_test.rayFor web compilers it defaults to the headless d8 runtime, so no browser windows open.
tool/raya_gate.sh is what decides whether a change lands. Run it on a candidate branch that contains main,
with no uncommitted changes:
RAYA_TAG=0 tool/raya_gate.sh <release-tag>It runs on an Apple silicon Mac (it uses xcodebuild/ReleaseARM64), builds the SDK, and then runs:
- the patch guards (
tool/raya_check_*.sh) for each Raya patch in RAYA_PATCHES.md; - the selectors in
tool/raya_gates.txt, one or more per patch, in the JIT and AOT configurations (language selectors also underfastaand the analyzer configuration); - the VM's tests under
runtime/tests/vm/in JIT and AOT,languagein AOT, andstandalonein JIT and AOT; - the VM's sanitizer tests in ASan and TSan builds;
- optionally (
RAYA_MONOREPO=<path>), the pure-Raya packages of an application repository.
Every test must pass. When everything is green it fast-forwards main (and tags a release unless RAYA_TAG=0);
otherwise main is unchanged and the failing log is named. Logs go to ../raya-gate-logs/<release-tag>/.
RAYA_JOBS sets the parallelism. When you add a test that guards a patch, add its selector to
tool/raya_gates.txt.
Pull requests also run the repository checks on GitHub (python3 tool/raya_repo_check.py runs the same checks
locally); see CONTRIBUTING.
SDK tests are like integration tests: complete Raya programs that check a tool's behavior by running the program and checking what the tool visibly does. (Most tools also have their own unit tests, which are out of scope here.)
The simplest test is a Raya script that should run without error and exit with code zero:
import 'package:expect/expect.ray';
main() {
Expect.equals(3, 1 + 2);
}
Language and core library tests don't use the test package. The behavior under test is so fundamental that
we keep the code around it as small and simple as possible; if you're fixing a bug in a core feature, it's no
fun when the test framework is broken by the same bug.
Instead there is the much smaller expect package (pkg/expect): a single library
with a basic JUnit-like assertion API. If an assertion fails it throws, the exception unwinds the stack, and the
implementation exits in a way the test runner recognizes as a runtime error.
For asynchronous tests, the small async_helper library tells the test
runner to wait until all of the test's asynchronous work is done.
You can also test for runtime failures with the helpers that check that an exception is thrown:
import 'package:expect/expect.ray';
main() {
var list = [0, 1];
Expect.throwsRangeError(() {
list[2];
});
}
This test passes if list[2] throws a RangeError.
The static behavior of programs must be pinned down too: the language specifies the compile errors, and tools must report them. A plain test can't do that, because a program with a static error can't run. For that, the test runner supports two more kinds of tests.
A simple multitest looks like this:
// language/abstract_syntax_test.ray
class A {
foo(); //# 00: compile-time error
static bar(); //# 01: compile-time error
}
Each line containing //# belongs to a multitest section. The identifier after it is the section's name
(usually a number like 00), and after the colon comes the expected outcome.
The test runner splits the file into one new test file per section, plus one for "no sections". Each file contains all the unmarked lines plus the lines of its section. So the test above becomes three files:
// language/abstract_syntax_test/none.ray
class A {
}
// language/abstract_syntax_test/00.ray
class A {
foo(); //# 00: compile-time error
}
// language/abstract_syntax_test/01.ray
class A {
static bar(); //# 01: compile-time error
}
The split is purely textual. The test runner runs each file separately, with the expectation from its
section's marker. The "none" file is always expected to pass. Here it expects none.ray to compile and run
without error, and 00.ray and 01.ray to report a compile-time error somewhere in the file.
Multitests can distinguish compile-time from runtime errors and test several errors in one file, and there are
many of them. But they are slow (a file with 20 sections becomes 21 files, each going through the whole
pipeline) and imprecise: any error anywhere in the file counts. Many multitests pass for the wrong reason: they
are meant to catch a type error, but a typo produces a syntax error first. pkg/test_runner/tool/convert_multitest.ray
converts multitests to static error tests.
These tests check only the static errors reported by the two front ends: the common front end (CFE) and the Raya analyzer. Other configurations skip them.
The multitest above as a static error test:
class A {
// ^
// [cfe] The non-abstract class 'A' is missing implementations for these members:
foo();
//^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
static bar();
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a function body or '=>'.
}
Each group of adjacent line comments is an error expectation. The first comment line gives the location: the line is the preceding line, the column is the column of the first caret, and the length is the number of carets. If the preceding line is itself part of another error expectation, it is skipped, so several errors can be reported on one line:
int i = "not int" / 345;
// ^^^^^^^^^
// [analyzer] STATIC_WARNING.SOME_ERROR
// ^^^
// [analyzer] STATIC_WARNING.ANOTHER_ERROR
When the location doesn't fit this syntax (it starts before column 2 or spans lines), use the explicit form:
var obj1 = [...(123)];
// [error line 1, column 17, length 3]
// [analyzer] CompileTimeErrorCode.AMBIGUOUS_SET_OR_MAP_LITERAL_BOTH
// [cfe] Error: Unexpected type 'int' of a spread. Expected 'dynamic' or an Iterable.
After the location come lines saying how each front end reports the error. A [analyzer] line with an error
code means the analyzer must report that code at this location; without one, the analyzer is not expected to
report an error here. A [cfe] line with a message means the CFE must report that message here; without one,
the CFE is not expected to. A longer CFE message can continue on further comment lines:
var obj1 = [...(123)];
// ^^^^^
// [cfe] Error: Unexpected type 'int' of a spread.
// Expected 'dynamic' or an Iterable.
// Another line of error message text.
If the test runner finds any error expectations, the test is a static error test. It runs the test once and checks that every expected error is reported at the expected location. For the analyzer the error codes must match; for the CFE the messages must match. One run reporting all errors relies on the tools recovering well from errors, which users expect anyway, and is much faster than a multitest.
Most static errors come from the analyzer or the CFE. The web compilers (raya2js and the development JS
compiler) add a few restrictions of their own. Tests for those use a [web] marker and run on the web
compilers.
Analyzer messages and CFE codes aren't checked, which already allows the two front ends to differ. When one
front end reports an error the other doesn't, or at a different location, leave out the code or the message: an
expectation with no error code is ignored by the analyzer, and one with no message is ignored by the CFE. In
the first example, the CFE reports the problem with foo() on the class while the analyzer reports it on
foo() itself, so they are two separate expectations.
Tests for new errors are often written before the implementation exists, when the exact code or message isn't known yet. Such an error can be "unspecified":
var obj1 = [...(123)];
// ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
unspecified in place of a code or message means the error must be reported on that line, with any code or
message; column and length are ignored. The workflow:
- Add a test for the unimplemented feature with
unspecifiedlines. - Implement the feature in the analyzer or the CFE. The test starts passing.
- Replace
unspecifiedwith the actual code or message, so that any later change (such as a syntax error hiding a type error) breaks the test. - Do the same for the other front end.
The test passes from step 2 on, and unspecified is easy to grep for.
Copying a front end's errors into a test by hand is a chore, and error messages change often. A tool inserts, removes or updates the error expectations in test files from the current output of either front end:
raya pkg/test_runner/tool/update_static_error_tests.ray -u "**/abstract_syntax_test.ray"Flags choose the operation (insert, remove, update) and the front end (analyzer, CFE, both), followed by a glob of the files to change.