summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-11-04 00:20:56 +0100
committerJan Tojnar <jtojnar@gmail.com>2021-11-14 23:05:48 +0100
commit968d18045263799811c2ff9e238214bd1f6a2329 (patch)
tree4dd996fd89b4d694bf68cf813d290ff4c20c7000 /pkgs/test
parentfe630fcb1fbaa1ca740ab27327c4d893a003a3b8 (diff)
downloadnixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar.gz
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar.bz2
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar.lz
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar.xz
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.tar.zst
nixpkgs-968d18045263799811c2ff9e238214bd1f6a2329.zip
php: Implement overrideAttrs that composes with buildEnv/withExtensions
Hopefully.

Also add a couple of tests to check that.
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/default.nix2
-rw-r--r--pkgs/test/php/default.nix116
2 files changed, 118 insertions, 0 deletions
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index 80d82e5bee0..ac4aebda5cd 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -37,6 +37,8 @@ with pkgs;
 
   cross = callPackage ./cross {};
 
+  php = recurseIntoAttrs (callPackages ./php {});
+
   rustCustomSysroot = callPackage ./rust-sysroot {};
   buildRustCrate = callPackage ../build-support/rust/build-rust-crate/test { };
   importCargoLock = callPackage ../build-support/rust/test/import-cargo-lock { };
diff --git a/pkgs/test/php/default.nix b/pkgs/test/php/default.nix
new file mode 100644
index 00000000000..3c6c8f61b6d
--- /dev/null
+++ b/pkgs/test/php/default.nix
@@ -0,0 +1,116 @@
+{ lib
+, php
+, runCommand
+}:
+
+let
+  runTest = name: body: runCommand name { } ''
+    testFailed=
+    checking() {
+      echo -n "Checking $1... " > /dev/stderr
+    }
+    ok() {
+      echo ok > /dev/stderr
+    }
+    nok() {
+      echo fail > /dev/stderr
+      testFailed=1
+    }
+
+    ${body}
+
+    if test -n "$testFailed"; then
+      exit 1
+    fi
+
+    touch $out
+  '';
+
+  check = cond: if cond then "ok" else "nok";
+in
+{
+  withExtensions-enables-previously-disabled-extensions = runTest "php-test-withExtensions-enables-previously-disabled-extensions" ''
+    php="${php}"
+
+    checking "that imagick is not present by default"
+    $php/bin/php -r 'exit(extension_loaded("imagick") ? 1 : 0);' && ok || nok
+
+    phpWithImagick="${php.withExtensions ({ all, ... }: [ all.imagick ])}"
+    checking "that imagick extension is present when enabled"
+    $phpWithImagick/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
+  '';
+
+  overrideAttrs-preserves-enabled-extensions =
+    let
+      customPhp =
+        (php.withExtensions ({ all, ... }: [ all.imagick ])).overrideAttrs (attrs: {
+          postInstall = attrs.postInstall or "" + ''
+            touch "$out/oApee-was-here"
+          '';
+        });
+    in
+    runTest "php-test-overrideAttrs-preserves-enabled-extensions" ''
+      php="${customPhp}"
+      phpUnwrapped="${customPhp.unwrapped}"
+
+      checking "if overrides took hold"
+      test -f "$phpUnwrapped/oApee-was-here" && ok || nok
+
+      checking "if imagick extension is still present"
+      $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
+
+      checking "if imagick extension is linked against the overridden PHP"
+      echo $php
+      $php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
+    '';
+
+  unwrapped-overrideAttrs-stacks =
+    let
+      customPhp =
+        lib.pipe php.unwrapped [
+          (pkg: pkg.overrideAttrs (attrs: {
+            postInstall = attrs.postInstall or "" + ''
+              touch "$out/oAs-first"
+            '';
+          }))
+
+          (pkg: pkg.overrideAttrs (attrs: {
+            postInstall = attrs.postInstall or "" + ''
+              touch "$out/oAs-second"
+            '';
+          }))
+        ];
+    in
+    runTest "php-test-unwrapped-overrideAttrs-stacks" ''
+      checking "if first override remained"
+      ${check (builtins.match ".*oAs-first.*" customPhp.postInstall != null)}
+
+      checking "if second override is there"
+      ${check (builtins.match ".*oAs-second.*" customPhp.postInstall != null)}
+    '';
+
+  wrapped-overrideAttrs-stacks =
+    let
+      customPhp =
+        lib.pipe php [
+          (pkg: pkg.overrideAttrs (attrs: {
+            postInstall = attrs.postInstall or "" + ''
+              touch "$out/oAs-first"
+            '';
+          }))
+
+          (pkg: pkg.overrideAttrs (attrs: {
+            postInstall = attrs.postInstall or "" + ''
+              touch "$out/oAs-second"
+            '';
+          }))
+        ];
+    in
+    runTest "php-test-wrapped-overrideAttrs-stacks" ''
+      checking "if first override remained"
+      ${check (builtins.match ".*oAs-first.*" customPhp.unwrapped.postInstall != null)}
+
+      checking "if second override is there"
+      ${check (builtins.match ".*oAs-second.*" customPhp.unwrapped.postInstall != null)}
+    '';
+}