Skip to main content

Execution Model

A Scrut test document can contain arbitrary amounts of test cases. Scrut provides a shared execution environment for all executions from a single document, which results in certain behaviors and side-effects that should be known:

Shared Shell Environment

Each subsequent test case in the same document inherits the shell environment of the previous test case. This means: All environment variables, shell variables, aliases, functions, etc that have been set in one test case are available to the immediate following test case.

Shared Ephemeral Directories

Each test cases in the same document executes in the the same working directory and is provided with the same temporary directory ($TEMPDIR). Both directories will be removed (cleaned up) after test execution - independent of whether the test execution succeeds or fails.

  • Exception: If the --work-directory command-line parameter is provided, then this directory will not be cleaned up (deleted) after execution. A temporary directory, that still will be removed after execution, will be created within the working directory.

Process Isolation

Scrut starts individual bash processes for executing each shell expression of each test case in the same document. The environment of the previous execution is pulled in through a shared state file, that contains all environment variables, shell variables, aliases, functions and settings as they were set when the the previous test case execution ended.

Markdown vs Cram

Markdown is the default Scrut test document format. Cram is supported for legacy reasons. Hence it's legacy mode of execution is also respected. The main difference in Cram from the above is:

Each execution from the same test document is executed in the same shell process.

This is less flexible (e.g. Scrut cannot constraint max execution time per test case) and more prone to unintended side-effects (e.g. set -e terminating all test executions, not only a single test case or detached processes interfering with output association to specific tests). We recommend to use Markdown.