diff_test: add ability for caller to specify a message printed on fai… (#307)

Useful for the use case of a pair of .test and .update targets for checked-in golden files
This commit is contained in:
Alex Eagle 2021-08-18 08:23:43 -07:00 committed by GitHub
parent 0c57e74606
commit df3c9e2735
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -58,7 +58,7 @@ if "!RF2!" equ "" (
fc.exe 2>NUL 1>NUL /B "!RF1!" "!RF2!"
if %ERRORLEVEL% neq 0 (
if %ERRORLEVEL% equ 1 (
echo>&2 FAIL: files "{file1}" and "{file2}" differ
echo>&2 FAIL: files "{file1}" and "{file2}" differ. {fail_msg}
exit /b 1
) else (
fc.exe /B "!RF1!" "!RF2!"
@ -66,6 +66,7 @@ if %ERRORLEVEL% neq 0 (
)
)
""".format(
fail_msg = ctx.attr.failure_message,
file1 = _runfiles_path(ctx.file.file1),
file2 = _runfiles_path(ctx.file.file2),
),
@ -95,10 +96,11 @@ else
exit 1
fi
if ! diff "$RF1" "$RF2"; then
echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ"
echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. {fail_msg}"
exit 1
fi
""".format(
fail_msg = ctx.attr.failure_message,
file1 = _runfiles_path(ctx.file.file1),
file2 = _runfiles_path(ctx.file.file2),
),
@ -112,6 +114,7 @@ fi
_diff_test = rule(
attrs = {
"failure_message": attr.string(),
"file1": attr.label(
allow_single_file = True,
mandatory = True,