diff --git a/lib/private/diff_test.bzl b/lib/private/diff_test.bzl index cbdc5a0..3908dd7 100644 --- a/lib/private/diff_test.bzl +++ b/lib/private/diff_test.bzl @@ -64,6 +64,7 @@ def _diff_test_impl(ctx): template = template, output = test_bin, substitutions = { + "{name}": ctx.attr.name, "{fail_msg}": ctx.attr.failure_message, "{file1}": file1_path, "{file2}": file2_path, diff --git a/lib/private/diff_test_tmpl.sh b/lib/private/diff_test_tmpl.sh index 7a964e2..4051dc5 100644 --- a/lib/private/diff_test_tmpl.sh +++ b/lib/private/diff_test_tmpl.sh @@ -1,5 +1,24 @@ #!/usr/bin/env bash set -euo pipefail +escape() { + echo "$1" \ + | sed 's/&/\&/g; s//\>/g; s/"/\"/g; s/'"'"'/\'/g' \ + | awk 1 ORS=' ' # preserve newlines +} +fail() { + cat << EOF >"${XML_OUTPUT_FILE:-/dev/null}" + + + + + + + + +EOF + echo >&2 "FAIL: $1" + exit 1 +} F1="{file1}" F2="{file2}" [[ "$F1" =~ ^external/ ]] && F1="${F1#external/}" || F1="$TEST_WORKSPACE/$F1" @@ -31,13 +50,11 @@ if [[ ! "$DF1" ]] && [[ "$DF2" ]]; then fi if [[ "$DF1" ]] || [[ "$DF2" ]]; then if ! diff -r "$RF1" "$RF2"; then - echo >&2 "FAIL: directories \"{file1}\" and \"{file2}\" differ. {fail_msg}" - exit 1 + fail "directories \"{file1}\" and \"{file2}\" differ. {fail_msg}" fi else if ! diff "$RF1" "$RF2"; then - echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. {fail_msg}" - exit 1 + fail "files \"{file1}\" and \"{file2}\" differ. {fail_msg}" fi fi