summary refs log tree commit diff
path: root/pkgs/build-support/testers/default.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-10-15 17:24:09 +0200
committerRobert Hensing <robert@roberthensing.nl>2022-10-27 14:06:38 +0200
commite20a362908fa6d4393efb05390e7dd38a64237da (patch)
tree37f40c77337a6c1126f9ae2cf3372736c36c7f81 /pkgs/build-support/testers/default.nix
parent44d0f3783387cdd7dfe05a32ff9c623eeebd0b57 (diff)
downloadnixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar.gz
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar.bz2
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar.lz
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar.xz
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.tar.zst
nixpkgs-e20a362908fa6d4393efb05390e7dd38a64237da.zip
testers.testEqualContents: init
Diffstat (limited to 'pkgs/build-support/testers/default.nix')
-rw-r--r--pkgs/build-support/testers/default.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix
index fd08e9c6c47..c565b6e7253 100644
--- a/pkgs/build-support/testers/default.nix
+++ b/pkgs/build-support/testers/default.nix
@@ -13,6 +13,44 @@
 
   testEqualDerivation = callPackage ./test-equal-derivation.nix { };
 
+  # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualContents
+  # or doc/builders/testers.chapter.md
+  testEqualContents = {
+    assertion,
+    actual,
+    expected,
+  }: runCommand "equal-contents-${lib.strings.toLower assertion}" {
+    inherit assertion actual expected;
+  } ''
+    echo "Checking:"
+    echo "$assertion"
+    if ! diff -U5 -r "$actual" "$expected" --color=always
+    then
+      echo
+      echo 'Contents must be equal, but were not!'
+      echo
+      echo "+: expected,   at $expected"
+      echo "-: unexpected, at $actual"
+      exit 1
+    else
+      find "$expected" -type f -executable > expected-executables | sort
+      find "$actual" -type f -executable > actual-executables | sort
+      if ! diff -U0 actual-executables expected-executables --color=always
+      then
+        echo
+        echo "Contents must be equal, but some files' executable bits don't match"
+        echo
+        echo "+: make this file executable in the actual contents"
+        echo "-: make this file non-executable in the actual contents"
+        exit 1
+      else
+        echo "expected $expected and actual $actual match."
+        echo 'OK'
+        touch $out
+      fi
+    fi
+  '';
+
   testVersion =
     { package,
       command ? "${package.meta.mainProgram or package.pname or package.name} --version",