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