Tests in VS Code
Run meta test verbs from the VS Code Test Explorer or from the gutter of the editor. How tests are found, which command each button runs, and how the result is read.
The extension shows the meta test verbs of your workspace in the Test
Explorer of VS Code. You run a test with the play button next to it, and VS
Code marks it as passed or failed. Under the buttons the extension runs the
same actus test as in the terminal. How to write a test, and where to put
it, is in Testing.
A project with tests
This page uses a small project called stock. It has one module, stock, with
one verb that is open. The facade of the module is src/stock/stock.act:
The verb is in src/stock/count.act:
And src/main.act uses it:
The tests of a module go in the folder tests of the module. Create
src/stock/tests/count.act:
How tests are found
Open the Testing view in the Activity Bar. The extension has added a
controller called Actus Tests. It groups the tests by project: the project
of a test file is the nearest folder above it that holds an Actus.toml. Under
each project there is one entry for each file that has tests, named with the
path of the file inside the project, and under it one entry for each test. The
project entry is named after its folder, or after its path inside the
workspace folder when the project is not the workspace folder itself, so a
workspace with several projects shows each one apart. For the project above,
opened as the workspace folder stock:
The extension finds a test by reading the text of the .act files. It does not
ask the compiler. A test is a meta test line followed by the first
verb name( after it. Other meta lines in between, such as meta effect, are
allowed. meta test and the verb may also be on one line. Text in a comment (#
or //), in a string and in a """ documentation block is not read, so a
meta test in a docstring is not a test. If a struct, enum, pack,
role, perform, const, import, open or extern comes first, the
meta test line before it is dropped.
The list stays up to date:
- when you open a file, and as you type in it, from the text in the editor,
- when a
.actfile is created, changed or deleted on disk, - when the workspace folders change,
- when you press the refresh button of the Testing view.
The search through the workspace skips folders named target, node_modules
and .git. A file with no tests is not listed.
Run tests
There is one run profile, called Run Actus Tests. It is the default. There is no debug profile.
- The play button next to a test runs that test. The gutter of the
editor has the same button on the line of the
verb. - The play button next to a file runs all the tests of that file.
- Run All Tests at the top runs every test, one file after another.
The extension starts actus test in the project folder of the test, the folder
that holds its Actus.toml, and gives it the path of the file relative to that
folder, so a test of a project nested inside the workspace runs in its own
project. Tests of different projects run in separate commands. When
exactly one test of a file is selected, it adds the name of the test and
--exact. In the Test Results view, the first line of a run is the command, so
you can see it. It ends with --profile and the value of
actus.profile, debug by
default. For a single test it is:
When you select more than one test of the same file, or the file itself, the
command has no name and no --exact, and the whole file runs. Only the tests
you selected get a result. The extension has no way to run a part of a file
other than one test.
Stopping a run takes effect before the next file starts. The process of the file that is running is not stopped.
Read the result
The extension reads the lines that actus test prints for each test:
It takes the module path before the last ::, the verb name after it, the word ok or FAILED, and the time
in milliseconds. The time shows next to the test. The Test Results view has the
whole output, with ok in green and FAILED in red, and with test result: ok.
or test result: FAILED. coloured in the same way.
Here is a third test in the file that cannot pass. It expects 4, and the verb gives 3:
Running the file, from its play button, gives this:
In the Testing view the first two tests get a green check, and
remaining_is_wrong_on_purpose gets a red cross. Its message is the text in the
brackets of its line, 10 ms, exit code 1. A test that fails returns a number
other than 0. If you want to know which check failed, return a different number
for each one, as Testing says.
Some outcomes have no line for a test:
- If the tests do not build,
actus testprints an error and no test line. Every selected test fails, and its message is the text thatactus testprinted. - If a selected test has no
okline of its own, it is never counted as passed. Whenactus testran no test at all (running 0 tests) or printed no line for the test, the test is marked as errored, and the message names the command, the folder it ran in and the lines thatactus testprinted.
The extension matches a result to a test by the name of the verb and the path
of the module. It works out the module path from the path of the file, so
src/stock/tests/count.act is the module stock and tests/count.act is the
module tests. Two tests with the same verb name in two modules are told
apart. If the module path does not fit any result, the extension takes the
result only when exactly one result has that verb name.
A workspace that is not trusted runs nothing. The Test Results view says
Actus tests require a trusted workspace.
Tests without the Test Explorer
The command Actus: Test runs actus test for the whole project and writes
the output in the Actus Language Server channel of the Output panel. The
task actus: test does the same in a terminal and fills the Problems panel
when there is an error. See
Commands, tasks and the status bar.
What you learned
- The Testing view lists every
meta testverb of the workspace, found from the text of the files, grouped by the project (the nearestActus.toml). - A test, a file or Run All Tests runs
actus test --file <path>in the project folder, with the name of the test and--exactwhen exactly one test of the file is chosen, and--profile <profile>. - The result of each test comes from its line
test module::name ... okorFAILEDin the output; a test with no line of its own is errored, never passed.