python311Packages.moto: 4.2.6 -> 4.2.10
[NixPkgs.git] / pkgs / build-support / setup-hooks / patch-rc-path-hooks / test / default.nix
blob82bc160387ee5bb602c9a2b1d70183bfbf81cc07
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     )
134     { };
138   test-csh = callPackage
139     (
140       { lib
141       , runCommandLocal
142       , gnused
143       , hello
144       , patchRcPathCsh
145       , tcsh
146       }:
147       runCommandLocal "patch-rc-path-csh-test"
148         {
149           nativeBuildInputs = [
150             patchRcPathCsh
151             tcsh
152           ];
153           meta = {
154             description = "Package test of patchActivateCsh";
155             inherit (patchRcPathCsh.meta) maintainers;
156           };
157         }
158         ''
159           set -eu -o pipefail
162           # Test patching a blank file
164           echo > blank.csh
166           echo "Generating blank_patched.csh from blank.csh"
167           cp blank.csh blank_patched.csh
168           patchRcPathCsh blank_patched.csh "$PWD/delta:$PWD/foxtrot"
170           echo "Testing in Csh if blank.csh and blank_patched.csh modifies PATH the same way"
171           tcsh -e ${./test-sourcing-csh} blank.csh blank_patched.csh
174           # Test patching silent_hello file
176           echo "hello > /dev/null" > silent_hello.csh
178           echo "Generating silent_hello_patched.csh from silent_hello.csh"
179           cp silent_hello.csh silent_hello_patched.csh
180           patchRcPathCsh silent_hello_patched.csh "${hello}/bin"
182           echo "Testing in Csh if silent_hello_patched.csh get sourced without errer"
183           tcsh -e -c "source silent_hello_patched.csh"
186           # Generate the sample source
188           substitute ${./sample_source.csh.in} sample_source.csh --replace @sed@ ${gnused}/bin/sed
189           chmod u+rw sample_source.csh
192           # Test patching the sample source
194           echo "Generating sample_source_patched.csh from sample_source.csh"
195           cp sample_source.csh sample_source_patched.csh
196           chmod u+w sample_source_patched.csh
197           patchRcPathCsh sample_source_patched.csh "$PWD/delta:$PWD/foxtrot"
199           echo "Testing in Csh if sample_source.csh and sample_source_patched.csh modifies PATH the same way"
200           tcsh -e ${./test-sourcing-csh} sample_source.csh sample_source_patched.csh
203           # Test double-patching the sample source
205           echo "Patching again sample_source_patched.csh from sample_source.csh"
206           patchRcPathCsh sample_source_patched.csh "$PWD/foxtrot:$PWD/golf"
208           echo "Testing in Csh if sample_source.csh and sample_source_patched.csh modifies PATH the same way"
209           tcsh -e ${./test-sourcing-csh} sample_source.csh sample_source_patched.csh
212           # Create a dummy output
213           touch "$out"
214         ''
215     )
216     { };
220   test-fish = callPackage
221     (
222       { lib
223       , runCommandLocal
224       , fish
225       , hello
226       , patchRcPathFish
227       }:
228       runCommandLocal "patch-rc-path-fish-test"
229         {
230           nativeBuildInputs = [
231             fish
232             patchRcPathFish
233           ];
234           meta = {
235             description = "Package test of patchActivateFish";
236             inherit (patchRcPathFish.meta) maintainers;
237           };
238         }
239         ''
240           set -eu -o pipefail
243           # Test patching a blank file
245           echo > blank.fish
247           echo "Generating blank_patched.fish from blank.fish"
248           cp blank.fish blank_patched.fish
249           patchRcPathFish blank_patched.fish "$PWD/delta:$PWD/foxtrot"
251           echo "Testing in Fish if blank.fish and blank_patched.fish modifies PATH the same way"
252           HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
253           HOME="$HOME_TEMP" fish ${./test-sourcing-fish} blank.fish blank_patched.fish
254           rm -r "$HOME_TEMP"
257           # Test patching silent_hello file
259           echo "hello > /dev/null" > silent_hello.fish
261           echo "Generating silent_hello_patched.fish from silent_hello.fish"
262           cp silent_hello.fish silent_hello_patched.fish
263           patchRcPathFish silent_hello_patched.fish "${hello}/bin"
265           echo "Testing in Fish if silent_hello_patched.fish get sourced without error"
266           HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
267           HOME="$HOME_TEMP" fish -c "source silent_hello_patched.fish"
268           rm -r "$HOME_TEMP"
271           # Test patching the sample source
273           cp ${./sample_source.fish} sample_source_patched.fish
274           chmod u+w sample_source_patched.fish
276           echo "Generating sample_source_patched.fish from ${./sample_source.fish}"
277           patchRcPathFish sample_source_patched.fish "$PWD/delta:$PWD/foxtrot"
278           echo "Testing in Fish if sample_source.fish and sample_source_patched.fish modifies PATH the same way"
279           HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
280           HOME="$HOME_TEMP" fish ${./test-sourcing-fish} ${./sample_source.fish} sample_source_patched.fish
281           rm -r "$HOME_TEMP"
284           # Test double-patching the sample source
286           echo "Patching again sample_source_patched.fish from ${./sample_source.fish}"
287           patchRcPathFish sample_source_patched.fish "$PWD/foxtrot:$PWD/golf"
289           echo "Testing in Fish if sample_source.fish and sample_source_patched.fish modifies PATH the same way"
290           HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
291           HOME="$HOME_TEMP" fish ${./test-sourcing-fish} ${./sample_source.fish} sample_source_patched.fish
292           rm -r "$HOME_TEMP"
295           # Create a dummy output
296           touch "$out"
297         ''
298     )
299     { };
303   test-posix = callPackage
304     (
305       { lib
306       , runCommandLocal
307       , bash
308       , dash
309       , gnused
310       , hello
311       , ksh
312       , patchRcPathPosix
313       , shellcheck
314       }:
315       runCommandLocal "patch-rc-path-posix-test"
316         {
317           nativeBuildInputs = [
318             bash
319             dash
320             ksh
321             patchRcPathPosix
322             shellcheck
323           ];
324           meta = {
325             description = "Package test of patchActivatePosix";
326             inherit (patchRcPathPosix.meta) maintainers;
327           };
328         }
329         ''
330           set -eu -o pipefail
333           # Check the setup hook script
335           echo "Running shellcheck against ${./test-sourcing-posix}"
336           shellcheck -s sh --exclude SC1090 ${./test-sourcing-posix}
337           shellcheck -s dash --exclude SC1090 ${./test-sourcing-posix}
340           # Test patching a blank file
342           echo > blank.sh
344           echo "Generating blank_patched.sh from blank.sh"
345           cp blank.sh blank_patched.sh
346           patchRcPathPosix blank_patched.sh "$PWD/delta:$PWD/foxtrot"
348           echo "Running shellcheck against blank_patched.sh"
349           shellcheck -s sh blank_patched.sh
350           shellcheck -s dash blank_patched.sh
352           echo "Testing in Bash if blank.sh and blank_patched.sh modifies PATH the same way"
353           bash --posix ${./test-sourcing-posix} ./blank.sh ./blank_patched.sh
355           echo "Testing in Dash if blank.sh and blank_patched.sh modifies PATH the same way"
356           dash ${./test-sourcing-posix} ./blank.sh ./blank_patched.sh
358           echo "Testing in Ksh if ./blank.sh and ./blank_patched.sh modifies PATH the same way"
359           ksh ${./test-sourcing-posix} "$PWD/blank.sh" "$PWD/blank_patched.sh"
362           # Test patching silent_hello file
364           echo "hello > /dev/null" > silent_hello.sh
366           echo "Generating silent_hello_patched.sh from silent_hello.sh"
367           cp silent_hello.sh silent_hello_patched.sh
368           patchRcPathPosix silent_hello_patched.sh "${hello}/bin"
370           echo "Running shellcheck against silent_hello_patched.sh"
371           shellcheck -s sh silent_hello_patched.sh
372           shellcheck -s dash silent_hello_patched.sh
374           echo "Testing in Bash if silent_hello_patched.sh get sourced without error"
375           bash --posix -eu -c ". ./silent_hello_patched.sh"
377           echo "Testing in Dash if silent_hello_patched.sh get sourced without error"
378           dash -eu -c ". ./silent_hello_patched.sh"
380           echo "Testing in Ksh if silent_hello_patched.sh get sourced without error"
381           ksh -eu -c ". $PWD/silent_hello_patched.sh"
384           # Generate the sample source "$PWD/delta:$PWD/foxtrot" "$PWD/delta:$PWD/foxtrot"
386           substitute ${./sample_source.sh.in} sample_source.sh --replace @sed@ ${gnused}/bin/sed
387           chmod u+rw sample_source.sh
390           # Check the sample source
392           echo "Running shellcheck against sample_source.sh"
393           shellcheck -s sh sample_source.sh
394           shellcheck -s dash sample_source.sh
397           # Test patching the sample source
399           echo "Generating sample_source_patched.sh from sample_source.sh"
400           cp sample_source.sh sample_source_patched.sh
401           chmod u+w sample_source_patched.sh
402           patchRcPathPosix sample_source_patched.sh "$PWD/delta:$PWD/foxtrot"
404           echo "Running shellcheck against sample_source_patched.sh"
405           shellcheck -s sh sample_source_patched.sh
406           shellcheck -s dash sample_source_patched.sh
408           echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
409           bash --posix ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
411           echo "Testing in Dash if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
412           dash ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
414           echo "Testing in Ksh if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
415           ksh ${./test-sourcing-posix} "$PWD/sample_source.sh" "$PWD/sample_source_patched.sh"
418           # Test double-patching the sample source
420           echo "Patching again sample_source_patched.sh"
421           patchRcPathPosix sample_source_patched.sh "$PWD/foxtrot:$PWD/golf"
423           echo "Running shellcheck against sample_source_patched.sh"
424           shellcheck -s sh sample_source_patched.sh
425           shellcheck -s dash sample_source_patched.sh
427           echo "Testing in Bash if sample_source.bash and sample_source_patched.bash modifies PATH the same way"
428           bash --posix ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
430           echo "Testing in Dash if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
431           dash ${./test-sourcing-posix} "./sample_source.sh" "./sample_source_patched.sh"
433           echo "Testing in Ksh if sample_source.sh and sample_source_patched.sh modifies PATH the same way"
434           ksh ${./test-sourcing-posix} "$PWD/sample_source.sh" "$PWD/sample_source_patched.sh"
437           # Create a dummy output
438           touch "$out"
439         ''
440     )
441     { };