Skip to main content

Inline Configuration

Scrut support two kinds of inline configuration syntax:

  1. Per Test Document (document-wide) configuration, which can be defined at the start of the test document
  2. Per Test Case (test-case-wide) configuration, which can be defined with each individual test case
warning

This configuration method is only supported for test documents using the Markdown format. There is no equivalent in the Cram format.

Example

example.md
---
# optional document-wide YAML configuration
total_timeout: 30s
---

# The test document

The initial block that is initialized with `---` and terminated with `---` contains
the configuration in YAML notation.

## A simple test

```scrut
$ echo Hello One
Hello One
```

The above test does not contain any per-test configuration

## A test with configuration

```scrut {timeout: 10s}
$ echo Hello Two
Hello Two
```

The above test contains per-test configuration

Some inline-configuration attribute can overwritten by parameters provided on the command-line (see below). The order of precedence is:

  1. Command-line parameter
  2. Per Test Case configuration
  3. Per Test Document configuration
  4. Default

Test Document Configuration

NameTypeCorresponding Command Line ParameterDescription
appendlist of paths to documents--append-test-file-pathsInclude these paths in order, as if they were part of this document. All tests within the appended paths are appended to the tests defined in this document. Use-case is common/shared test tear-down. Paths must be relative to the current $TESTDIR.
defaultsSee below Test Case Configurationn/aDefaults for per-test-case configuration within the test file.
prependlist of paths to documents--prepend-test-file-pathsInclude these paths in order, as if they were part of this document. All tests within the prepend paths are prepended to the tests defined in this document. Use-case is common/shared test setup. Paths must be relative to the current $TESTDIR.
shellstring--shellThe path to the shell. If a full path is not provided, then the command must be in $PATH. Only bash compatible shells are currently supported!
total_timeoutduration string--timeout-secondsAll tests within the document (including appended and prepended) must finish executing within this time.

Defaults (Markdown and Cram)

append: []
defaults: {}
prepend: []
shell: bash
total_timeout: 15m
note

Per-document configuration in documents that are appended or prepended is ignored

Test Case Configuration

NameTypeCorresponding Command Line ParameterDescription
detachedbooleann/aTell Scrut that the shell expression of this test will detach itself, so Scrut will not consider this a test (i.e. no output or exit code evaluation). Purpose is to allow the user to detach a command (like nohup some-command &) that is doing something asynchronous (e.g. starting a server to which the tested CLI is a client).
environmentobjectn/aA set of environment variable names and values that will be explicitly set for the test.
keep_crlfboolean--keep-output-crlfWhether CRLF should be translated to LF (=false) or whether CR needs to be explicitly handled (=true).
output_streamenum (stdout, stderr, combined)--combine-output and --no-combine-outputWhich output stream to choose when applying output expectations: stdout (all expectations apply to what is printed on STDOUT), stderr (all expectations apply to what is printed on STDERR), combined (STDOUT and STDERR will combined into a single stream where all expectations are applied on)
skip_document_codepositive integern/aThe exit code, that if returned by any test, leads to skipping of the whole document.
strip_ansi_escapingbooln/aWhether to remove ANSIC escape characters from the CLI output before validating it.
timeoutnull or duration stringn/aA max execution time a test can run before it is considered failed (and will be aborted).
waitnull or duration string or Wait Configurationn/aSee Wait Configuration

Defaults (Markdown)

detached: false
environment: {}
keep_crlf: false
output_stream: stdout
skip_document_code: 80
strip_ansi_escaping: false
timeout: null
wait: null

Defaults (Cram)

detached: false
environment: {}
keep_crlf: true
output_stream: combined
skip_document_code: 80
strip_ansi_escaping: false
timeout: null
wait: null

Wait Configuration

This configuration corresponds to the per-test-case detached configuration and helps to write client / server tests where first a server is started (i.e. a test that runs detached) and then a client communicates with the server (i.e. a test that waits)

NameTypeDescription
timeoutduration stringHow long to wait for the test to run.
pathnull or stringIf set then the wait will end early once the path exists. This path must be in $TMPDIR

Example

# A server/client test example

Show-case how a server/client test that initially starts a server

## Start a server

```scrut {detached: true}
$ my-server --start && touch "$TMPDIR"/server-started
```

## Run client test once server is up

```scrut {wait: {timeout: 5m, path: server-started}}
$ my-client --do-a-thing
```
note

The path provided with the path directive must be relative to $TMPDIR.