aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Eagle <eagle@post.harvard.edu>2021-08-18 08:23:43 -0700
committerGitHub <noreply@github.com>2021-08-18 11:23:43 -0400
commitdf3c9e2735f02a7fe8cd80db4db00fec8e13d25f (patch)
tree4aae423b17e60b0ed1d11882967c82f6734ffa4e
parent0c57e74606b4e87606b0a9164fbfa4947e89e29c (diff)
downloadbazel-skylib-df3c9e2735f02a7fe8cd80db4db00fec8e13d25f.tar.gz
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
-rw-r--r--rules/diff_test.bzl7
1 files changed, 5 insertions, 2 deletions
diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl
index 71faf40..acde2ea 100644
--- a/rules/diff_test.bzl
+++ b/rules/diff_test.bzl
@@ -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,