about summary refs log tree commit diff
path: root/pkgs/test/hooks
diff options
context:
space:
mode:
authorArtturin <Artturin@artturin.com>2022-12-09 08:45:38 +0200
committerArtturin <Artturin@artturin.com>2022-12-09 08:57:14 +0200
commit11b49fa7915f35251e18fe967fc63b4900dbad81 (patch)
tree44353693aecb074aebde08edfdf84ccf7fdb56a4 /pkgs/test/hooks
parent6c01681679f7d2da1d300b6d16d11d58ba8b2286 (diff)
tests.hooks.default-stdenv-hooks.make-symlinks-relative: init
Diffstat (limited to 'pkgs/test/hooks')
-rw-r--r--pkgs/test/hooks/default.nix28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkgs/test/hooks/default.nix b/pkgs/test/hooks/default.nix
new file mode 100644
index 0000000000000..fe3a9b2a21672
--- /dev/null
+++ b/pkgs/test/hooks/default.nix
@@ -0,0 +1,28 @@
+# To run these tests:
+# nix-build -A tests.hooks
+
+{ stdenv, pkgs, lib }:
+
+{
+  # this attrset is for hooks in `stdenv.defaultNativeBuildInputs`
+  default-stdenv-hooks = lib.recurseIntoAttrs {
+    make-symlinks-relative = stdenv.mkDerivation {
+      name = "test-make-symlinks-relative";
+      passAsFile = [ "buildCommand" ];
+      buildCommand = ''
+        mkdir -p $out/{bar,baz}
+        source1="$out/bar/foo"
+        destination1="$out/baz/foo"
+        echo foo > $source1
+        ln -s $source1 $destination1
+        echo "symlink before patching: $(readlink $destination1)"
+
+        _makeSymlinksRelative
+
+        echo "symlink after patching: $(readlink $destination1)"
+        ([[ -e $destination1 ]] && echo "symlink isn't broken") || (echo "symlink is broken" && exit 1)
+        ([[ $(readlink $destination1) == "../bar/foo" ]] && echo "absolute symlink was made relative") || (echo "symlink was not made relative" && exit 1)
+      '';
+    };
+  };
+}