From fc5c829532a9a275fe51959b1d0158622ee69ae6 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Thu, 18 Jul 2024 17:01:35 +0300 Subject: [PATCH] testers.testEqualContents: use diffoscope instead of diffing find output Before this change, testers.testEqualContents implementation had several bugs (e.g. executables at different paths were not considered equal). So we switch to diffoscope that that is designed to handle exactly these kinds of comparisons and gives more insights into the differences in the output. --- pkgs/build-support/testers/default.nix | 27 ++++++++------------------ 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 516ab90db503..20d2957134c3 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -1,4 +1,4 @@ -{ pkgs, pkgsLinux, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }: +{ pkgs, pkgsLinux, buildPackages, diffoscopeMinimal, lib, callPackage, runCommand, stdenv, substituteAll, testers }: # Documentation is in doc/build-helpers/testers.chapter.md { # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck @@ -27,33 +27,22 @@ expected, }: runCommand "equal-contents-${lib.strings.toLower assertion}" { inherit assertion actual expected; + nativeBuildInputs = [ diffoscopeMinimal ]; } '' echo "Checking:" - echo "$assertion" - if ! diff -U5 -r "$actual" "$expected" --color=always + printf '%s\n' "$assertion" + if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata=no -- "$actual" "$expected" then echo echo 'Contents must be equal, but were not!' echo echo "+: expected, at $expected" echo "-: unexpected, at $actual" - exit 1 + false 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 + echo "expected $expected and actual $actual match." + echo OK + touch -- "$out" fi '';