testers.testEqualContents: add checkMetadata option
Allows ignoring file metadata differences (permissions, ownership)
when comparing files.
This is especially useful on darwin, where we often run into subtle
issues like:
-Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ wheel)
+Device: 1,23 Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 350/ nixbld)
This commit is contained in:
@@ -421,6 +421,11 @@ Check that two paths have the same contents.
|
|||||||
|
|
||||||
: A message that is printed last if the file system object contents at the two paths don't match exactly.
|
: A message that is printed last if the file system object contents at the two paths don't match exactly.
|
||||||
|
|
||||||
|
`checkMetadata` (boolean)
|
||||||
|
|
||||||
|
: Whether to fail on metadata differences, such as permissions or ownership.
|
||||||
|
Defaults to `true`.
|
||||||
|
|
||||||
:::{.example #ex-testEqualContents-toyexample}
|
:::{.example #ex-testEqualContents-toyexample}
|
||||||
|
|
||||||
# Check that two paths have the same contents
|
# Check that two paths have the same contents
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
actual,
|
actual,
|
||||||
expected,
|
expected,
|
||||||
postFailureMessage ? null,
|
postFailureMessage ? null,
|
||||||
|
checkMetadata ? true,
|
||||||
}:
|
}:
|
||||||
runCommand "equal-contents-${lib.strings.toLower assertion}"
|
runCommand "equal-contents-${lib.strings.toLower assertion}"
|
||||||
{
|
{
|
||||||
@@ -66,12 +67,13 @@
|
|||||||
expected
|
expected
|
||||||
postFailureMessage
|
postFailureMessage
|
||||||
;
|
;
|
||||||
|
excludeMetadata = if checkMetadata then "no" else "yes";
|
||||||
nativeBuildInputs = [ diffoscopeMinimal ];
|
nativeBuildInputs = [ diffoscopeMinimal ];
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
echo "Checking:"
|
echo "Checking:"
|
||||||
printf '%s\n' "$assertion"
|
printf '%s\n' "$assertion"
|
||||||
if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata=no -- "$actual" "$expected"
|
if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata="$excludeMetadata" -- "$actual" "$expected"
|
||||||
then
|
then
|
||||||
echo
|
echo
|
||||||
echo 'Contents must be equal, but were not!'
|
echo 'Contents must be equal, but were not!'
|
||||||
|
|||||||
Reference in New Issue
Block a user