Generation Testing¶
Safe-DS has two generation targets, Python (for execution) and Markdown (for documentation). In either case, the generation tests are data-driven instead of being specified explicitly. This document explains how to add a new generation test.
Python Generation¶
Adding a generation test¶
-
Create a new folder (not just a file!) in the
tests/resources/generation/pythondirectory or any subdirectory. Give the folder a descriptive name, since the folder name becomes part of the test name. By default, the runner integration is disabled. If you want to test the runner integration, place the folder intests/resources/generation/python/runner integrationor any subdirectory instead.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.sdsstubdirectly 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. Generation will be triggered for all files in the folder. - Add the Safe-DS code that you want to test to the files.
- If you want to run the program only up to a specific placeholder of a pipeline, surround the name of that
placeholder with test markers, e.g.
val »a« = 1;. You may only mark a single placeholder this way. Add a comment in the preceding line with the following format: - Run the tests. The test runner will automatically pick up the new test, and create a snapshot of the current output of the generator.
- Verify that the snapshot is correct, modify it if needed, and commit it.
Updating the snapshots¶
To quickly update the snapshots after changes to the code generator, run vitest with the --update flag.
Markdown Generation¶
Adding a generation test¶
-
Create a new folder (not just a file!) in the
tests/resources/generation/markdowndirectory 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.sdsstubdirectly 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. Generation will be triggered for all files in the folder. - Add the Safe-DS code that you want to test to the files.
- Run the tests. The test runner will automatically pick up the new test, and create a snapshot of the current output of the generator.
- Verify that the snapshot is correct, modify it if needed, and commit it.
Updating the snapshots¶
To quickly update the snapshots after changes to the code generator, run vitest with the --update flag.