mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
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.
This commit is contained in:
parent
b631366870
commit
fc5c829532
@ -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
|
||||
'';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user