Skip to content

Commit

Permalink
diff_test: add ability for caller to specify a message printed on fai… (
Browse files Browse the repository at this point in the history
#307)

Useful for the use case of a pair of .test and .update targets for checked-in golden files
  • Loading branch information
alexeagle committed Aug 18, 2021
1 parent 0c57e74 commit df3c9e2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rules/diff_test.bzl
Expand Up @@ -58,14 +58,15 @@ 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!"
exit /b %errorlevel%
)
)
""".format(
fail_msg = ctx.attr.failure_message,
file1 = _runfiles_path(ctx.file.file1),
file2 = _runfiles_path(ctx.file.file2),
),
Expand Down Expand Up @@ -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),
),
Expand All @@ -112,6 +114,7 @@ fi

_diff_test = rule(
attrs = {
"failure_message": attr.string(),
"file1": attr.label(
allow_single_file = True,
mandatory = True,
Expand Down

0 comments on commit df3c9e2

Please sign in to comment.