vimPlugins.blink-cmp: 0.7.3 -> 0.7.6 (#364100)
[NixPkgs.git] / pkgs / test / replace-vars / default.nix
blob76dc81de49c81f125471d2471b3d2f441b6a1322
2   replaceVars,
3   emptyDirectory,
4   emptyFile,
5   runCommand,
6   testers,
7 }:
8 let
9   inherit (testers) testEqualContents testBuildFailure;
12   # Success case for `replaceVars`.
13   replaceVars = testEqualContents {
14     assertion = "replaceVars";
15     actual = replaceVars ./source.txt {
16       free = "free";
17       "equal in" = "are the same in";
18       brotherhood = "shared humanity";
19     };
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
27     '';
28   };
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 { }); }
33       ''
34         grep -e "ERROR: file.*empty-directory.*does not exist" $failed/testBuildFailure.log
35         touch $out
36       '';
38   replaceVars-fails-in-build-phase =
39     runCommand "replaceVars-fails"
40       { failed = testBuildFailure (replaceVars emptyFile { not-found = "boo~"; }); }
41       ''
42         grep -e "ERROR: pattern @not-found@ doesn't match anything in file.*empty-file" $failed/testBuildFailure.log
43         touch $out
44       '';
46   replaceVars-fails-in-check-phase =
47     runCommand "replaceVars-fails"
48       {
49         failed =
50           let
51             src = builtins.toFile "source.txt" ''
52               Header.
53               before @whatIsThis@ middle @It'sOdd2Me@ after.
54               @cannot detect due to space@
55               Trailer.
56             '';
57           in
58           testBuildFailure (replaceVars src { });
59       }
60       ''
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
72         touch $out
73       '';