about summary refs log tree commit diff stats
path: root/tests/README.md
blob: fe93dc96d2140be76dd9a5cc067fd5289d943621 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# How to write a test

Test are simple derivations, put into the `by-name` directory.  As you
often want to test configuration, the 'standard' nixos-vm-test function
starts a vm with the specified configuration and lets you run a python
test script.

But, I've noticed, that most of my tests in this nixos-configuration are
actually testing the home-manager config of a program. As such I've built
a test infrastructure on top of the pre-existing nixos-vm-tests. It is
further described in the `mkTest` section.

## `mkTest`
A standard application test would look somewhat like this:

```nix
{mkTest}:
mkTest {
  name = "my-tests";

  # The configuration to add.
  # In this case, the less config is being tested.
  configuration = {
    imports = [
      ../../../../modules/by-name/le/less/module.nix
    ];
    config.soispha.programs.less.enable = true;
  };

  # Files that are provided at the test directory.
  # In this case, the test dir would have a `./data/test.file`
  # path pre-populated with the
  # contents of the file at the lhs.
  testData = {
    "data/test.file" = ./data/test.file;
  };

  # The description of what to do in the test.
  description = ./test.desc;

  # A sha256 hashsum of the concatenated output of the program.
  # This can be `null` to disable the checksum mechanism.
  hash = "87901231393b51cdd45bbb4339a32db2894a3a5ab164cb5c7a8fa14721fdcba7";
}
```

### The test description file
All line starting with `#` or only containing white space are
ignored. Additionally, all leading and trailing white space is stripped
before evaluating.

The general syntax is:
```
COMMAND ARGS
```
where `COMMAND` is one of the commands listed in [Commands](#### Commands)

The `ARGS` are the verbatim content from the space after the `COMMAND`
to the end of line character.

#### Commands
##### `Type`
Send the `ARGS` to the application. This interprets `ARGS` as specified
by the tmux (1) man page on `send-keys`.

#### `Sleep`
Sleep for `ARGS` seconds.

#### `Expect`
Grep the currently visible screen for the regex `ARGS`.  This regex
must match.
#### `ExpectNot`
Does the same thing as [Expect](##### Expect), but enforces, that the
regex does not match.