Skip to content

Commit 674c907

Browse files
committed
tests.testers.testEqualArrayOrMap: switch to testBuildFailure'
1 parent b2bb494 commit 674c907

File tree

1 file changed

+62
-142
lines changed
  • pkgs/build-support/testers/testEqualArrayOrMap

1 file changed

+62
-142
lines changed

pkgs/build-support/testers/testEqualArrayOrMap/tests.nix

Lines changed: 62 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
# `testers.testBuildFailure`. This is due to the fact that `testers.testBuildFailure` modifies the derivation such that
33
# it produces an output containing the exit code, logs, and other things. Since `testers.runCommand` expects the empty
44
# derivation, it produces a hash mismatch.
5-
{
6-
lib,
7-
runCommand,
8-
testers,
9-
}:
5+
{ lib, testers }:
106
let
117
inherit (lib.attrsets) recurseIntoAttrs;
12-
inherit (testers) testEqualArrayOrMap testBuildFailure;
8+
inherit (testers) testBuildFailure' testEqualArrayOrMap;
139
concatValuesArrayToActualArray = ''
1410
nixLog "appending all values in valuesArray to actualArray"
1511
for value in "''${valuesArray[@]}"; do
@@ -101,37 +97,18 @@ recurseIntoAttrs {
10197
# doing nothing
10298
'';
10399
};
104-
array-missing-value =
105-
let
100+
array-missing-value = testBuildFailure' {
101+
drv = testEqualArrayOrMap {
106102
name = "testEqualArrayOrMap-array-missing-value";
107-
failure = testEqualArrayOrMap {
108-
name = "${name}-failure";
109-
valuesArray = [ "apple" ];
110-
expectedArray = [ ];
111-
script = concatValuesArrayToActualArray;
112-
};
113-
in
114-
runCommand name
115-
{
116-
failed = testBuildFailure failure;
117-
passthru = {
118-
inherit failure;
119-
};
120-
}
121-
''
122-
nixLog "Checking for exit code 1"
123-
(( 1 == "$(cat "$failed/testBuildFailure.exit")" ))
124-
nixLog "Checking for first error message"
125-
grep -F \
126-
"ERROR: assertEqualArray: arrays differ in length: expectedArray has length 0 but actualArray has length 1" \
127-
"$failed/testBuildFailure.log"
128-
nixLog "Checking for second error message"
129-
grep -F \
130-
"ERROR: assertEqualArray: arrays differ at index 0: expectedArray has no such index but actualArray has value 'apple'" \
131-
"$failed/testBuildFailure.log"
132-
nixLog "Test passed"
133-
touch $out
134-
'';
103+
valuesArray = [ "apple" ];
104+
expectedArray = [ ];
105+
script = concatValuesArrayToActualArray;
106+
};
107+
expectedBuilderLogEntries = [
108+
"ERROR: assertEqualArray: arrays differ in length: expectedArray has length 0 but actualArray has length 1"
109+
"ERROR: assertEqualArray: arrays differ at index 0: expectedArray has no such index but actualArray has value 'apple'"
110+
];
111+
};
135112
map-insert = testEqualArrayOrMap {
136113
name = "testEqualArrayOrMap-map-insert";
137114
valuesMap = {
@@ -168,115 +145,58 @@ recurseIntoAttrs {
168145
unset 'actualMap[bee]'
169146
'';
170147
};
171-
map-missing-key =
172-
let
148+
map-missing-key = testBuildFailure' {
149+
drv = testEqualArrayOrMap {
173150
name = "testEqualArrayOrMap-map-missing-key";
174-
failure = testEqualArrayOrMap {
175-
name = "${name}-failure";
176-
valuesMap = {
177-
bee = "1";
178-
cat = "2";
179-
dog = "3";
180-
};
181-
expectedMap = {
182-
apple = "0";
183-
bee = "1";
184-
cat = "2";
185-
dog = "3";
186-
};
187-
script = concatValuesMapToActualMap;
151+
valuesMap = {
152+
bee = "1";
153+
cat = "2";
154+
dog = "3";
188155
};
189-
in
190-
runCommand name
191-
{
192-
failed = testBuildFailure failure;
193-
passthru = {
194-
inherit failure;
195-
};
196-
}
197-
''
198-
nixLog "Checking for exit code 1"
199-
(( 1 == "$(cat "$failed/testBuildFailure.exit")" ))
200-
nixLog "Checking for first error message"
201-
grep -F \
202-
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 4 but actualMap has length 3" \
203-
"$failed/testBuildFailure.log"
204-
nixLog "Checking for second error message"
205-
grep -F \
206-
"ERROR: assertEqualMap: maps differ at key 'apple': expectedMap has value '0' but actualMap has no such key" \
207-
"$failed/testBuildFailure.log"
208-
nixLog "Test passed"
209-
touch $out
210-
'';
211-
map-missing-key-with-empty =
212-
let
213-
name = "map-missing-key-with-empty";
214-
failure = testEqualArrayOrMap {
215-
name = "${name}-failure";
216-
valuesArray = [ ];
217-
expectedMap.apple = 1;
218-
script = "";
156+
expectedMap = {
157+
apple = "0";
158+
bee = "1";
159+
cat = "2";
160+
dog = "3";
219161
};
220-
in
221-
runCommand name
222-
{
223-
failed = testBuildFailure failure;
224-
passthru = {
225-
inherit failure;
226-
};
227-
}
228-
''
229-
nixLog "Checking for exit code 1"
230-
(( 1 == "$(cat "$failed/testBuildFailure.exit")" ))
231-
nixLog "Checking for first error message"
232-
grep -F \
233-
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 1 but actualMap has length 0" \
234-
"$failed/testBuildFailure.log"
235-
nixLog "Checking for second error message"
236-
grep -F \
237-
"ERROR: assertEqualMap: maps differ at key 'apple': expectedMap has value '1' but actualMap has no such key" \
238-
"$failed/testBuildFailure.log"
239-
nixLog "Test passed"
240-
touch $out
241-
'';
242-
map-extra-key =
243-
let
162+
script = concatValuesMapToActualMap;
163+
};
164+
expectedBuilderLogEntries = [
165+
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 4 but actualMap has length 3"
166+
"ERROR: assertEqualMap: maps differ at key 'apple': expectedMap has value '0' but actualMap has no such key"
167+
];
168+
};
169+
map-missing-key-with-empty = testBuildFailure' {
170+
drv = testEqualArrayOrMap {
171+
name = "testEqualArrayOrMap-map-missing-key-with-empty";
172+
valuesArray = [ ];
173+
expectedMap.apple = 1;
174+
script = "";
175+
};
176+
expectedBuilderLogEntries = [
177+
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 1 but actualMap has length 0"
178+
"ERROR: assertEqualMap: maps differ at key 'apple': expectedMap has value '1' but actualMap has no such key"
179+
];
180+
};
181+
map-extra-key = testBuildFailure' {
182+
drv = testEqualArrayOrMap {
244183
name = "testEqualArrayOrMap-map-extra-key";
245-
failure = testEqualArrayOrMap {
246-
name = "${name}-failure";
247-
valuesMap = {
248-
apple = "0";
249-
bee = "1";
250-
cat = "2";
251-
dog = "3";
252-
};
253-
expectedMap = {
254-
apple = "0";
255-
bee = "1";
256-
dog = "3";
257-
};
258-
script = concatValuesMapToActualMap;
184+
valuesMap = {
185+
apple = "0";
186+
bee = "1";
187+
cat = "2";
188+
dog = "3";
259189
};
260-
in
261-
runCommand
262-
{
263-
failed = testBuildFailure failure;
264-
passthru = {
265-
inherit failure;
266-
};
267-
}
268-
''
269-
nixLog "Checking for exit code 1"
270-
(( 1 == "$(cat "$failed/testBuildFailure.exit")" ))
271-
nixLog "Checking for first error message"
272-
grep -F \
273-
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 3 but actualMap has length 4" \
274-
"$failed/testBuildFailure.log"
275-
nixLog "Checking for second error message"
276-
grep -F \
277-
"ERROR: assertEqualMap: maps differ at key 'cat': expectedMap has no such key but actualMap has value '2'" \
278-
"$failed/testBuildFailure.log"
279-
nixLog "Test passed"
280-
touch $out
281-
'';
190+
expectedMap = {
191+
apple = "0";
192+
bee = "1";
193+
dog = "3";
194+
};
195+
script = concatValuesMapToActualMap;
196+
};
197+
expectedBuilderLogEntries = [
198+
"ERROR: assertEqualMap: maps differ in length: expectedMap has length 3 but actualMap has length 4"
199+
"ERROR: assertEqualMap: maps differ at key 'cat': expectedMap has no such key but actualMap has value '2'"
200+
];
201+
};
282202
}

0 commit comments

Comments
 (0)