diff options
Diffstat (limited to 'rules/diff_test.bzl')
-rw-r--r-- | rules/diff_test.bzl | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 93cf363..49a1968 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -44,21 +44,31 @@ for /F "tokens=2* usebackq" %%i in (`findstr.exe /l /c:"!F1! " "%MF%"`) do ( set RF1=!RF1:/=\\! ) if "!RF1!" equ "" ( - echo>&2 ERROR: !F1! not found - exit /b 1 + if exist "{file1}" ( + set RF1="{file1}" + set RF1=!RF1:/=\\! + ) else ( + echo>&2 ERROR: !F1! not found + exit /b 1 + ) ) for /F "tokens=2* usebackq" %%i in (`findstr.exe /l /c:"!F2! " "%MF%"`) do ( set RF2=%%i set RF2=!RF2:/=\\! ) if "!RF2!" equ "" ( - echo>&2 ERROR: !F2! not found - exit /b 1 + if exist "{file2}" ( + set RF2="{file2}" + set RF2=!RF2:/=\\! + ) else ( + echo>&2 ERROR: !F2! not found + exit /b 1 + ) ) 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 +76,7 @@ if %ERRORLEVEL% neq 0 ( ) ) """.format( + fail_msg = ctx.attr.failure_message, file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), ), @@ -75,7 +86,7 @@ if %ERRORLEVEL% neq 0 ( test_bin = ctx.actions.declare_file(ctx.label.name + "-test.sh") ctx.actions.write( output = test_bin, - content = r"""#!/bin/bash + content = r"""#!/usr/bin/env bash set -euo pipefail F1="{file1}" F2="{file2}" @@ -95,10 +106,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 +124,7 @@ fi _diff_test = rule( attrs = { + "failure_message": attr.string(), "file1": attr.label( allow_single_file = True, mandatory = True, @@ -135,7 +148,7 @@ def diff_test(name, file1, file2, **kwargs): name: The name of the test rule. file1: Label of the file to compare to <code>file2</code>. file2: Label of the file to compare to <code>file1</code>. - **kwargs: The <a href="https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. + **kwargs: The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. """ _diff_test( name = name, |