Skip to content

Commit fa5d6d1

Browse files
Merge pull request #275585 from DanielSidhion/improve-testers-testversion
doc: add more details on testers.testVersion
2 parents 732e5e6 + b47d073 commit fa5d6d1

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

doc/build-helpers/testers.chapter.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,49 @@ meta.pkgConfigModules = [ "libfoo" ];
3030

3131
## `testVersion` {#tester-testVersion}
3232

33-
Checks the command output contains the specified version
33+
Checks that the output from running a command contains the specified version string in it as a whole word.
3434

35-
Although simplistic, this test assures that the main program
36-
can run. While there's no substitute for a real test case,
37-
it does catch dynamic linking errors and such. It also provides
38-
some protection against accidentally building the wrong version,
39-
for example when using an 'old' hash in a fixed-output derivation.
35+
Although simplistic, this test assures that the main program can run.
36+
While there's no substitute for a real test case, it does catch dynamic linking errors and such.
37+
It also provides some protection against accidentally building the wrong version, for example when using an "old" hash in a fixed-output derivation.
4038

41-
Examples:
39+
By default, the command to be run will be inferred from the given `package` attribute:
40+
it will check `meta.mainProgram` first, and fall back to `pname` or `name`.
41+
The default argument to the command is `--version`, and the version to be checked will be inferred from the given `package` attribute as well.
42+
43+
:::{.example #ex-testversion-hello}
44+
45+
# Check a program version using all the default values
46+
47+
This example will run the command `hello --version`, and then check that the version of the `hello` package is in the output of the command.
4248

4349
```nix
4450
passthru.tests.version = testers.testVersion { package = hello; };
51+
```
4552

46-
passthru.tests.version = testers.testVersion {
47-
package = seaweedfs;
48-
command = "weed version";
49-
};
53+
:::
5054

51-
passthru.tests.version = testers.testVersion {
52-
package = key;
53-
command = "KeY --help";
54-
# Wrong '2.5' version in the code. Drop on next version.
55-
version = "2.5";
56-
};
55+
:::{.example #ex-testversion-different-commandversion}
56+
57+
# Check the program version using a specified command and expected version string
58+
59+
This example will run the command `leetcode -V`, and then check that `leetcode 0.4.2` is in the output of the command as a whole word (separated by whitespaces).
60+
This means that an output like "leetcode 0.4.21" would fail the tests, and an output like "You're running leetcode 0.4.2" would pass the tests.
61+
62+
A common usage of the `version` attribute is to specify `version = "v${version}"`.
63+
64+
```nix
65+
version = "0.4.2";
5766
5867
passthru.tests.version = testers.testVersion {
59-
package = ghr;
60-
# The output needs to contain the 'version' string without any prefix or suffix.
61-
version = "v${version}";
68+
package = leetcode-cli;
69+
command = "leetcode -V";
70+
version = "leetcode ${version}";
6271
};
6372
```
6473

74+
:::
75+
6576
## `testBuildFailure` {#tester-testBuildFailure}
6677

6778
Make sure that a build does not succeed. This is useful for testing testers.

0 commit comments

Comments
 (0)