1 { testers, lib, pkgs, hello, runCommand, emptyFile, emptyDirectory, ... }:
3 pkgs-with-overlay = pkgs.extend(final: prev: {
4 proof-of-overlay-hello = prev.hello;
9 versionSuffix = "test";
14 lib.recurseIntoAttrs {
15 lycheeLinkCheck = lib.recurseIntoAttrs pkgs.lychee.tests;
17 hasPkgConfigModules = pkgs.callPackage ../hasPkgConfigModules/tests.nix { };
19 shellcheck = pkgs.callPackage ../shellcheck/tests.nix { };
21 runCommand = lib.recurseIntoAttrs {
22 bork = pkgs.python3Packages.bork.tests.pytest-network;
24 dns-resolution = testers.runCommand {
25 name = "runCommand-dns-resolution-test";
26 nativeBuildInputs = [ pkgs.ldns ];
33 nonDefault-hash = testers.runCommand {
34 name = "runCommand-nonDefaultHash-test";
38 echo aaaaaaaaaaicjnrkeflncmrlk > $out/keymash
40 hash = "sha256-eMy+6bkG+KS75u7Zt4PM3APhtdVd60NxmBRN5GKJrHs=";
44 runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: {
45 name = "runNixOSTest-test";
46 nodes.machine = { pkgs, ... }: {
47 system.nixos = dummyVersioning;
48 environment.systemPackages = [ pkgs.proof-of-overlay-hello pkgs.figlet ];
51 machine.succeed("hello | figlet >/dev/console")
55 # Check that the wiring of nixosTest is correct.
56 # Correct operation of the NixOS test driver should be asserted elsewhere.
57 nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, ... }: {
58 name = "nixosTest-test";
59 nodes.machine = { pkgs, ... }: {
60 system.nixos = dummyVersioning;
61 environment.systemPackages = [ pkgs.proof-of-overlay-hello pkgs.figlet ];
64 machine.succeed("hello | figlet >/dev/console")
68 testBuildFailure = lib.recurseIntoAttrs {
69 happy = runCommand "testBuildFailure-happy" {
70 failed = testers.testBuildFailure (runCommand "fail" {} ''
75 echo 'line\nwith-\bbackslashes'
76 printf "incomplete line - no newline"
81 grep -F 'ok-ish' $failed/result
83 grep -F 'failing though' $failed/testBuildFailure.log
84 grep -F 'also stderr' $failed/testBuildFailure.log
85 grep -F 'line\nwith-\bbackslashes' $failed/testBuildFailure.log
86 grep -F 'incomplete line - no newline' $failed/testBuildFailure.log
88 [[ 3 = $(cat $failed/testBuildFailure.exit) ]]
93 helloDoesNotFail = runCommand "testBuildFailure-helloDoesNotFail" {
94 failed = testers.testBuildFailure (testers.testBuildFailure hello);
96 # Add hello itself as a prerequisite, so we don't try to run this test if
97 # there's an actual failure in hello.
100 echo "Checking $failed/testBuildFailure.log"
101 grep -F 'testBuildFailure: The builder did not fail, but a failure was expected' $failed/testBuildFailure.log >/dev/null
102 [[ 1 = $(cat $failed/testBuildFailure.exit) ]]
107 multiOutput = runCommand "testBuildFailure-multiOutput" {
108 failed = testers.testBuildFailure (runCommand "fail" {
109 # dev will be the default output
110 outputs = ["dev" "doc" "out"];
116 grep -F 'i am failing' $failed/testBuildFailure.log >/dev/null
117 [[ 1 = $(cat $failed/testBuildFailure.exit) ]]
119 # Checking our note that dev is the default output
120 echo $failed/_ | grep -- '-dev/_' >/dev/null
126 testEqualContents = lib.recurseIntoAttrs {
127 equalDir = testers.testEqualContents {
128 assertion = "The same directory contents at different paths are recognized as equal";
129 expected = runCommand "expected" { } ''
135 chmod a+x -- "$out/e"
137 actual = runCommand "actual" { } ''
143 chmod a+x -- "$out/e"
147 fileMissing = testers.testBuildFailure (
148 testers.testEqualContents {
149 assertion = "Directories with different file list are not recognized as equal";
150 expected = runCommand "expected" { } ''
156 actual = runCommand "actual" { } ''
164 equalExe = testers.testEqualContents {
165 assertion = "The same executable file contents at different paths are recognized as equal";
166 expected = runCommand "expected" { } ''
170 actual = runCommand "actual" { } ''
176 unequalExe = testers.testBuildFailure (
177 testers.testEqualContents {
178 assertion = "Different file mode bits are not recognized as equal";
179 expected = runCommand "expected" { } ''
183 actual = runCommand "actual" { } ''
189 unequalExeInDir = testers.testBuildFailure (
190 testers.testEqualContents {
191 assertion = "Different file mode bits are not recognized as equal in directory";
192 expected = runCommand "expected" { } ''
195 chmod a+x -- "$out/b"
197 actual = runCommand "actual" { } ''
204 nonExistentPath = testers.testBuildFailure (
205 testers.testEqualContents {
206 assertion = "Non existent paths are not recognized as equal";
207 expected = "${emptyDirectory}/foo";
208 actual = "${emptyDirectory}/bar";
212 emptyFileAndDir = testers.testBuildFailure (
213 testers.testEqualContents {
214 assertion = "Empty file and directory are not recognized as equal";
215 expected = emptyFile;
216 actual = emptyDirectory;
222 log = testers.testBuildFailure (
223 testers.testEqualContents {
224 assertion = "Different files are not recognized as equal in subdirectories";
225 expected = runCommand "expected" { } ''
228 echo EXPECTED >"$out/b/c"
230 actual = runCommand "actual" { } ''
233 echo ACTUAL >"$out/b/c"
238 runCommand "testEqualContents-fileDiff" { inherit log; } ''
241 # Note: use `&&` operator to chain commands because errexit (set -e)
242 # does not work in this context (even when set explicitly and with
243 # inherit_errexit), otherwise the subshell exits with the status of
244 # the last run command and ignores preceding failures.
245 grep -F -- 'Contents must be equal, but were not!' "$log/testBuildFailure.log" &&
246 grep -E -- '\+\+\+ .*-expected/b/c' "$log/testBuildFailure.log" &&
247 grep -E -- '--- .*-actual/b/c' "$log/testBuildFailure.log" &&
248 grep -F -- -ACTUAL "$log/testBuildFailure.log" &&
249 grep -F -- +EXPECTED "$log/testBuildFailure.log"
251 echo "Test failed: could not find pattern in build log $log"