Code Actions Testing¶
Code actions tests are data-driven instead of being specified explicitly. This document explains how to add a new code action test.
Adding a code action test¶
-
Create a new folder (not just a file!) in the
tests/resources/code actions
directory or any subdirectory. Give the folder a descriptive name, since the folder name becomes part of the test name.Skipping a test
If you want to skip a test, add the prefix
skip-
to the folder name. -
Add files with the extension
.sdsdev
,.sds
, or.sdsstub
directly inside the folder. All files in a folder will be loaded into the same workspace, so they can reference each other. Files in different folders are loaded into different workspaces, so they cannot reference each other. - Add the Safe-DS code that you want to test to the files.
- Specify the code actions to apply using test comments (see below) at the top of the file.
- Run the tests. The test runner will automatically pick up the new test, and create a snapshot of the current output after applying the selected code actions.
- Verify that the snapshot is correct, modify it if needed, and commit it.
Format of test comments¶
- As usual, test comments are single-line comments that start with
$TEST$
. - Then, the keyword
apply
follows. - Finally, you must specify the title of the code action enclosed in double-quotes. You can also add an
r
before the opening double-quote to indicate that the title should be interpreted as a regular expression that must match the entire actual title.
Here are some examples:
We apply all code actions with the exact title Remove statement.
.
We apply all code actions with a title that starts with Remove
.
Updating the snapshots¶
To quickly update the snapshots after changes to the code generator, run vitest
with the --update
flag.