1{
2 lib,
3 php,
4 runCommand,
5}:
6
7let
8 runTest =
9 name: body:
10 runCommand name { } ''
11 testFailed=
12 checking() {
13 echo -n "Checking $1... " > /dev/stderr
14 }
15 ok() {
16 echo ok > /dev/stderr
17 }
18 nok() {
19 echo fail > /dev/stderr
20 testFailed=1
21 }
22
23 ${body}
24
25 if test -n "$testFailed"; then
26 exit 1
27 fi
28
29 touch $out
30 '';
31
32 check = cond: if cond then "ok" else "nok";
33in
34{
35 withExtensions-enables-previously-disabled-extensions = runTest "php-test-withExtensions-enables-previously-disabled-extensions" ''
36 php="${php}"
37
38 checking "that imagick is not present by default"
39 $php/bin/php -r 'exit(extension_loaded("imagick") ? 1 : 0);' && ok || nok
40
41 phpWithImagick="${php.withExtensions ({ all, ... }: [ all.imagick ])}"
42 checking "that imagick extension is present when enabled"
43 $phpWithImagick/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
44 '';
45
46 overrideAttrs-preserves-enabled-extensions =
47 let
48 customPhp = (php.withExtensions ({ all, ... }: [ all.imagick ])).overrideAttrs (attrs: {
49 postInstall = attrs.postInstall or "" + ''
50 touch "$out/oApee-was-here"
51 '';
52 });
53 in
54 runTest "php-test-overrideAttrs-preserves-enabled-extensions" ''
55 php="${customPhp}"
56 phpUnwrapped="${customPhp.unwrapped}"
57
58 checking "if overrides took hold"
59 test -f "$phpUnwrapped/oApee-was-here" && ok || nok
60
61 checking "if imagick extension is still present"
62 $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
63
64 checking "if imagick extension is linked against the overridden PHP"
65 echo $php
66 $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
67 '';
68
69 unwrapped-overrideAttrs-stacks =
70 let
71 customPhp = lib.pipe php.unwrapped [
72 (
73 pkg:
74 pkg.overrideAttrs (attrs: {
75 postInstall = attrs.postInstall or "" + ''
76 touch "$out/oAs-first"
77 '';
78 })
79 )
80
81 (
82 pkg:
83 pkg.overrideAttrs (attrs: {
84 postInstall = attrs.postInstall or "" + ''
85 touch "$out/oAs-second"
86 '';
87 })
88 )
89 ];
90 in
91 runTest "php-test-unwrapped-overrideAttrs-stacks" ''
92 checking "if first override remained"
93 ${check (builtins.match ".*oAs-first.*" customPhp.postInstall != null)}
94
95 checking "if second override is there"
96 ${check (builtins.match ".*oAs-second.*" customPhp.postInstall != null)}
97 '';
98
99 wrapped-overrideAttrs-stacks =
100 let
101 customPhp = lib.pipe php [
102 (
103 pkg:
104 pkg.overrideAttrs (attrs: {
105 postInstall = attrs.postInstall or "" + ''
106 touch "$out/oAs-first"
107 '';
108 })
109 )
110
111 (
112 pkg:
113 pkg.overrideAttrs (attrs: {
114 postInstall = attrs.postInstall or "" + ''
115 touch "$out/oAs-second"
116 '';
117 })
118 )
119 ];
120 in
121 runTest "php-test-wrapped-overrideAttrs-stacks" ''
122 checking "if first override remained"
123 ${check (builtins.match ".*oAs-first.*" customPhp.unwrapped.postInstall != null)}
124
125 checking "if second override is there"
126 ${check (builtins.match ".*oAs-second.*" customPhp.unwrapped.postInstall != null)}
127 '';
128}