9 inherit (testers) testEqualContents testBuildFailure;
12 # Success case for `replaceVars`.
13 replaceVars = testEqualContents {
14 assertion = "replaceVars";
15 actual = replaceVars ./source.txt {
17 "equal in" = "are the same in";
18 brotherhood = "shared humanity";
21 expected = builtins.toFile "expected" ''
22 All human beings are born free and are the same in dignity and rights.
23 They are endowed with reason and conscience and should act towards
24 one another in a spirit of shared humanity.
26 -- eroosevelt@humanrights.un.org
30 # There might eventually be a usecase for this, but it's not supported at the moment.
31 replaceVars-fails-on-directory =
32 runCommand "replaceVars-fails" { failed = testBuildFailure (replaceVars emptyDirectory { }); }
34 grep -e "ERROR: file.*empty-directory.*does not exist" $failed/testBuildFailure.log
38 replaceVars-fails-in-build-phase =
39 runCommand "replaceVars-fails"
40 { failed = testBuildFailure (replaceVars emptyFile { not-found = "boo~"; }); }
42 grep -e "ERROR: pattern @not-found@ doesn't match anything in file.*empty-file" $failed/testBuildFailure.log
46 replaceVars-fails-in-check-phase =
47 runCommand "replaceVars-fails"
51 src = builtins.toFile "source.txt" ''
53 before @whatIsThis@ middle @It'sOdd2Me@ after.
54 @cannot detect due to space@
58 testBuildFailure (replaceVars src { });
61 grep -e "unsubstituted Nix identifiers.*source.txt" $failed/testBuildFailure.log
62 grep -F "@whatIsThis@" $failed/testBuildFailure.log
63 grep -F "@It'sOdd2Me@" $failed/testBuildFailure.log
64 grep -F 'more precise `substitute` function' $failed/testBuildFailure.log
66 # Shouldn't see irrelevant details.
67 ! grep -q -E -e "Header|before|middle|after|Trailer" $failed/testBuildFailure.log
69 # Shouldn't see the "cannot detect" version.
70 ! grep -q -F "cannot detect due to space" $failed/testBuildFailure.log