bandwhich: 0.23.0 -> 0.23.1; move to by-name; nixfmt; useFetchCargoVendor (#356934)
[NixPkgs.git] / pkgs / build-support / setup-hooks / patch-rc-path-hooks / test / default.nix
blob8479e2c9bbcbf9c079d024ecfcadaaf0051de842
1 { callPackage }:
4   test-bash = callPackage (
5     {
6       lib,
7       runCommandLocal,
8       bash,
9       hello,
10       ksh,
11       patchRcPathBash,
12       shellcheck,
13       zsh,
14     }:
15     runCommandLocal "patch-rc-path-bash-test"
16       {
17         nativeBuildInputs = [
18           bash
19           ksh
20           patchRcPathBash
21           shellcheck
22           zsh
23         ];
24         meta = {
25           description = "Package test of patchActivateBash";
26           inherit (patchRcPathBash.meta) maintainers;
27         };
28       }
29       ''
30         set -eu -o pipefail
33         # Check the setup hook script
35         echo "Running shellcheck against ${./test-sourcing-bash}"
36         shellcheck -s bash --exclude SC1090 ${./test-sourcing-bash}
37         shellcheck -s ksh --exclude SC1090 ${./test-sourcing-bash}
40         # Test patching a blank file
42         echo > blank.bash
44         echo "Generating blank_patched.bash from blank.bash"
45         cp blank.bash blank_patched.bash
46         patchRcPathBash blank_patched.bash "$PWD/delta:$PWD/foxtrot"
48         echo "Running shellcheck against blank_patched.bash"
49         shellcheck -s bash blank_patched.bash
50         shellcheck -s ksh blank_patched.bash
52         echo "Testing in Bash if blank.bash and blank_patched.bash modifies PATH the same way"
53         bash ${./test-sourcing-bash} ./blank.bash ./blank_patched.bash
55         echo "Testing in Ksh if blank.bash and blank_patched.bash modifies PATH the same way"
56         ksh ${./test-sourcing-bash} "$PWD/blank.bash" "$PWD/blank_patched.bash"
58         echo "Testing in Zsh if blank.bash and blank_patched.bash modifies PATH the same way"
59         zsh ${./test-sourcing-bash} ./blank.bash ./blank_patched.bash
62         # Test patching silent_hello
64         echo "hello > /dev/null" > silent_hello.bash
66         echo "Generating silent_hello_patched.bash from silent_hello.bash"
67         cp silent_hello.bash silent_hello_patched.bash
68         patchRcPathBash silent_hello_patched.bash "${hello}/bin"
70         echo "Running shellcheck against silent_hello_patched.bash"
71         shellcheck -s bash silent_hello_patched.bash
73         echo "Testing in Bash if silent_hello_patched.bash get sourced without error"
74         bash -eu -o pipefail -c ". ./silent_hello_patched.bash"
76         echo "Testing in Ksh if silent_hello_patched.bash get sourced without error"
77         ksh -eu -o pipefail -c ". ./silent_hello_patched.bash"
79         echo "Testing in Zsh if silent_hello_patched.bash get sourced without error"
80         zsh -eu -o pipefail -c ". ./silent_hello_patched.bash"
83         # Check the sample source
85         echo "Running shellcheck against sample_source.bash"
86         shellcheck -s bash ${./sample_source.bash}
87         shellcheck -s ksh ${./sample_source.bash}
90         # Test patching the sample source
92         cp ${./sample_source.bash} sample_source_patched.bash
93         chmod u+w sample_source_patched.bash
95         echo "Generating sample_source_patched.bash from ./sample_source.bash"
96         patchRcPathBash sample_source_patched.bash "$PWD/delta:$PWD/foxtrot"
98         echo "Running shellcheck against sample_source_patched.bash"
99         shellcheck -s bash sample_source_patched.bash
101         echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
102         bash ${./test-sourcing-bash} ${./sample_source.bash} ./sample_source_patched.bash
104         echo "Testing in Ksh if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
105         ksh ${./test-sourcing-bash} ${./sample_source.bash} "$PWD/sample_source_patched.bash"
107         echo "Testing in Zsh if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
108         zsh ${./test-sourcing-bash} ${./sample_source.bash} ./sample_source_patched.bash
111         # Test double-patching the sample source
113         echo "Patching again sample_source_patched.bash"
114         patchRcPathBash sample_source_patched.bash "$PWD/foxtrot:$PWD/golf"
116         echo "Running shellcheck against sample_source_patched.bash"
117         shellcheck -s bash sample_source_patched.bash
118         shellcheck -s ksh sample_source_patched.bash
120         echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
121         bash ${./test-sourcing-bash} ${./sample_source.bash} ./sample_source_patched.bash
123         echo "Testing in Ksh if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
124         ksh ${./test-sourcing-bash} ${./sample_source.bash} "$PWD/sample_source_patched.bash"
126         echo "Testing in Zsh if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
127         zsh ${./test-sourcing-bash} ${./sample_source.bash} ./sample_source_patched.bash
130         # Create a dummy output
131         touch "$out"
132       ''
133   ) { };
135   test-csh = callPackage (
136     {
137       lib,
138       runCommandLocal,
139       gnused,
140       hello,
141       patchRcPathCsh,
142       tcsh,
143     }:
144     runCommandLocal "patch-rc-path-csh-test"
145       {
146         nativeBuildInputs = [
147           patchRcPathCsh
148           tcsh
149         ];
150         meta = {
151           description = "Package test of patchActivateCsh";
152           inherit (patchRcPathCsh.meta) maintainers;
153         };
154       }
155       ''
156         set -eu -o pipefail
159         # Test patching a blank file
161         echo > blank.csh
163         echo "Generating blank_patched.csh from blank.csh"
164         cp blank.csh blank_patched.csh
165         patchRcPathCsh blank_patched.csh "$PWD/delta:$PWD/foxtrot"
167         echo "Testing in Csh if blank.csh and blank_patched.csh modifies PATH the same way"
168         tcsh -e ${./test-sourcing-csh} blank.csh blank_patched.csh
171         # Test patching silent_hello file
173         echo "hello > /dev/null" > silent_hello.csh
175         echo "Generating silent_hello_patched.csh from silent_hello.csh"
176         cp silent_hello.csh silent_hello_patched.csh
177         patchRcPathCsh silent_hello_patched.csh "${hello}/bin"
179         echo "Testing in Csh if silent_hello_patched.csh get sourced without errer"
180         tcsh -e -c "source silent_hello_patched.csh"
183         # Generate the sample source
185         substitute ${./sample_source.csh.in} sample_source.csh --replace @sed@ ${gnused}/bin/sed
186         chmod u+rw sample_source.csh
189         # Test patching the sample source
191         echo "Generating sample_source_patched.csh from sample_source.csh"
192         cp sample_source.csh sample_source_patched.csh
193         chmod u+w sample_source_patched.csh
194         patchRcPathCsh sample_source_patched.csh "$PWD/delta:$PWD/foxtrot"
196         echo "Testing in Csh if sample_source.csh and sample_source_patched.csh modifies PATH the same way"
197         tcsh -e ${./test-sourcing-csh} sample_source.csh sample_source_patched.csh
200         # Test double-patching the sample source
202         echo "Patching again sample_source_patched.csh from sample_source.csh"
203         patchRcPathCsh sample_source_patched.csh "$PWD/foxtrot:$PWD/golf"
205         echo "Testing in Csh if sample_source.csh and sample_source_patched.csh modifies PATH the same way"
206         tcsh -e ${./test-sourcing-csh} sample_source.csh sample_source_patched.csh
209         # Create a dummy output
210         touch "$out"
211       ''
212   ) { };
214   test-fish = callPackage (
215     {
216       lib,
217       runCommandLocal,
218       fish,
219       hello,
220       patchRcPathFish,
221     }:
222     runCommandLocal "patch-rc-path-fish-test"
223       {
224         nativeBuildInputs = [
225           fish
226           patchRcPathFish
227         ];
228         meta = {
229           description = "Package test of patchActivateFish";
230           inherit (patchRcPathFish.meta) maintainers;
231         };
232       }
233       ''
234         set -eu -o pipefail
237         # Test patching a blank file
239         echo > blank.fish
241         echo "Generating blank_patched.fish from blank.fish"
242         cp blank.fish blank_patched.fish
243         patchRcPathFish blank_patched.fish "$PWD/delta:$PWD/foxtrot"
245         echo "Testing in Fish if blank.fish and blank_patched.fish modifies PATH the same way"
246         HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
247         HOME="$HOME_TEMP" fish ${./test-sourcing-fish} blank.fish blank_patched.fish
248         rm -r "$HOME_TEMP"
251         # Test patching silent_hello file
253         echo "hello > /dev/null" > silent_hello.fish
255         echo "Generating silent_hello_patched.fish from silent_hello.fish"
256         cp silent_hello.fish silent_hello_patched.fish
257         patchRcPathFish silent_hello_patched.fish "${hello}/bin"
259         echo "Testing in Fish if silent_hello_patched.fish get sourced without error"
260         HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
261         HOME="$HOME_TEMP" fish -c "source silent_hello_patched.fish"
262         rm -r "$HOME_TEMP"
265         # Test patching the sample source
267         cp ${./sample_source.fish} sample_source_patched.fish
268         chmod u+w sample_source_patched.fish
270         echo "Generating sample_source_patched.fish from ${./sample_source.fish}"
271         patchRcPathFish sample_source_patched.fish "$PWD/delta:$PWD/foxtrot"
272         echo "Testing in Fish if sample_source.fish and sample_source_patched.fish modifies PATH the same way"
273         HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
274         HOME="$HOME_TEMP" fish ${./test-sourcing-fish} ${./sample_source.fish} sample_source_patched.fish
275         rm -r "$HOME_TEMP"
278         # Test double-patching the sample source
280         echo "Patching again sample_source_patched.fish from ${./sample_source.fish}"
281         patchRcPathFish sample_source_patched.fish "$PWD/foxtrot:$PWD/golf"
283         echo "Testing in Fish if sample_source.fish and sample_source_patched.fish modifies PATH the same way"
284         HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
285         HOME="$HOME_TEMP" fish ${./test-sourcing-fish} ${./sample_source.fish} sample_source_patched.fish
286         rm -r "$HOME_TEMP"
289         # Create a dummy output
290         touch "$out"
291       ''
292   ) { };
294   test-posix = callPackage (
295     {
296       lib,
297       runCommandLocal,
298       bash,
299       dash,
300       gnused,
301       hello,
302       ksh,
303       patchRcPathPosix,
304       shellcheck,
305     }:
306     runCommandLocal "patch-rc-path-posix-test"
307       {
308         nativeBuildInputs = [
309           bash
310           dash
311           ksh
312           patchRcPathPosix
313           shellcheck
314         ];
315         meta = {
316           description = "Package test of patchActivatePosix";
317           inherit (patchRcPathPosix.meta) maintainers;
318         };
319       }
320       ''
321         set -eu -o pipefail
324         # Check the setup hook script
326         echo "Running shellcheck against ${./test-sourcing-posix}"
327         shellcheck -s sh --exclude SC1090 ${./test-sourcing-posix}
328         shellcheck -s dash --exclude SC1090 ${./test-sourcing-posix}
331         # Test patching a blank file
333         echo > blank.sh
335         echo "Generating blank_patched.sh from blank.sh"
336         cp blank.sh blank_patched.sh
337         patchRcPathPosix blank_patched.sh "$PWD/delta:$PWD/foxtrot"
339         echo "Running shellcheck against blank_patched.sh"
340         shellcheck -s sh blank_patched.sh
341         shellcheck -s dash blank_patched.sh
343         echo "Testing in Bash if blank.sh and blank_patched.sh modifies PATH the same way"
344         bash --posix ${./test-sourcing-posix} ./blank.sh ./blank_patched.sh
346         echo "Testing in Dash if blank.sh and blank_patched.sh modifies PATH the same way"
347         dash ${./test-sourcing-posix} ./blank.sh ./blank_patched.sh
349         echo "Testing in Ksh if ./blank.sh and ./blank_patched.sh modifies PATH the same way"
350         ksh ${./test-sourcing-posix} "$PWD/blank.sh" "$PWD/blank_patched.sh"
353         # Test patching silent_hello file
355         echo "hello > /dev/null" > silent_hello.sh
357         echo "Generating silent_hello_patched.sh from silent_hello.sh"
358         cp silent_hello.sh silent_hello_patched.sh
359         patchRcPathPosix silent_hello_patched.sh "${hello}/bin"
361         echo "Running shellcheck against silent_hello_patched.sh"
362         shellcheck -s sh silent_hello_patched.sh
363         shellcheck -s dash silent_hello_patched.sh
365         echo "Testing in Bash if silent_hello_patched.sh get sourced without error"
366         bash --posix -eu -c ". ./silent_hello_patched.sh"
368         echo "Testing in Dash if silent_hello_patched.sh get sourced without error"
369         dash -eu -c ". ./silent_hello_patched.sh"
371         echo "Testing in Ksh if silent_hello_patched.sh get sourced without error"
372         ksh -eu -c ". $PWD/silent_hello_patched.sh"
375         # Generate the sample source "$PWD/delta:$PWD/foxtrot" "$PWD/delta:$PWD/foxtrot"
377         substitute ${./sample_source.sh.in} sample_source.sh --replace @sed@ ${gnused}/bin/sed
378         chmod u+rw sample_source.sh
381         # Check the sample source
383         echo "Running shellcheck against sample_source.sh"
384         shellcheck -s sh sample_source.sh
385         shellcheck -s dash sample_source.sh
388         # Test patching the sample source
390         echo "Generating sample_source_patched.sh from sample_source.sh"
391         cp sample_source.sh sample_source_patched.sh
392         chmod u+w sample_source_patched.sh
393         patchRcPathPosix sample_source_patched.sh "$PWD/delta:$PWD/foxtrot"
395         echo "Running shellcheck against sample_source_patched.sh"
396         shellcheck -s sh sample_source_patched.sh
397         shellcheck -s dash sample_source_patched.sh
399         echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
400         bash --posix ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
402         echo "Testing in Dash if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
403         dash ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
405         echo "Testing in Ksh if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
406         ksh ${./test-sourcing-posix} "$PWD/sample_source.sh" "$PWD/sample_source_patched.sh"
409         # Test double-patching the sample source
411         echo "Patching again sample_source_patched.sh"
412         patchRcPathPosix sample_source_patched.sh "$PWD/foxtrot:$PWD/golf"
414         echo "Running shellcheck against sample_source_patched.sh"
415         shellcheck -s sh sample_source_patched.sh
416         shellcheck -s dash sample_source_patched.sh
418         echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
419         bash --posix ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
421         echo "Testing in Dash if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
422         dash ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
424         echo "Testing in Ksh if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
425         ksh ${./test-sourcing-posix} "$PWD/sample_source.sh" "$PWD/sample_source_patched.sh"
428         # Create a dummy output
429         touch "$out"
430       ''
431   ) { };