1{
2 substitute,
3 testers,
4 runCommand,
5}:
6let
7 # Ofborg doesn't allow any traces on stderr,
8 # so mock `lib` to not trace warnings,
9 # because substitute gives a deprecation warning
10 substituteSilent = substitute.override (prevArgs: {
11 lib = prevArgs.lib.extend (
12 finalLib: prevLib: {
13 trivial = prevLib.trivial // {
14 warn = msg: value: value;
15 };
16 }
17 );
18 });
19in
20{
21
22 substitutions = testers.testEqualContents {
23 assertion = "substitutions-spaces";
24 actual = substitute {
25 src = builtins.toFile "source" ''
26 Hello world!
27 '';
28 substitutions = [
29 "--replace-fail"
30 "Hello world!"
31 "Yo peter!"
32 ];
33 };
34 expected = builtins.toFile "expected" ''
35 Yo peter!
36 '';
37 };
38
39 legacySingleReplace = testers.testEqualContents {
40 assertion = "substitute-single-replace";
41 actual = substituteSilent {
42 src = builtins.toFile "source" ''
43 Hello world!
44 '';
45 replacements = [
46 "--replace-fail"
47 "world"
48 "paul"
49 ];
50 };
51 expected = builtins.toFile "expected" ''
52 Hello paul!
53 '';
54 };
55
56 legacyString = testers.testEqualContents {
57 assertion = "substitute-string";
58 actual = substituteSilent {
59 src = builtins.toFile "source" ''
60 Hello world!
61 '';
62 # Not great that this works at all, but is supported
63 replacements = "--replace-fail world string";
64 };
65 expected = builtins.toFile "expected" ''
66 Hello string!
67 '';
68 };
69
70 legacySingleArg = testers.testEqualContents {
71 assertion = "substitute-single-arg";
72 actual = substituteSilent {
73 src = builtins.toFile "source" ''
74 Hello world!
75 '';
76 # Not great that this works at all, but is supported
77 replacements = [
78 "--replace-fail world list"
79 ];
80 };
81 expected = builtins.toFile "expected" ''
82 Hello list!
83 '';
84 };
85
86 legacyVar = testers.testEqualContents {
87 assertion = "substitute-var";
88 actual = substituteSilent {
89 src = builtins.toFile "source" ''
90 @greeting@ @name@!
91 '';
92 # Not great that this works at all, but is supported
93 replacements = [
94 "--subst-var name"
95 "--subst-var-by greeting Yo"
96 ];
97 name = "peter";
98 };
99 expected = builtins.toFile "expected" ''
100 Yo peter!
101 '';
102 };
103
104}