From ed33b446831fe95fb71048e3b28a1d6d7a931b3d Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 28 Jun 2024 19:15:55 -0400 Subject: [PATCH 1/9] feat: extend api for stable diff_test on windows --- docs/private/stardoc_with_diff_test.bzl | 2 + rules/diff_test.bzl | 50 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/docs/private/stardoc_with_diff_test.bzl b/docs/private/stardoc_with_diff_test.bzl index 32b471a7..2c3386ad 100644 --- a/docs/private/stardoc_with_diff_test.bzl +++ b/docs/private/stardoc_with_diff_test.bzl @@ -58,6 +58,8 @@ def stardoc_with_diff_test( file1 = out_label, # Output from stardoc rule above file2 = out_file.replace(".md", "-docgen.md"), + # Stardoc generates CRLF line endings on windows. file1 has LF endings. + file2_to_lf = True, tags = ["no_windows"], ) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 0f27f350..c048fe9d 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -35,8 +35,22 @@ def _diff_test_impl(ctx): @echo off SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION -set MF=%RUNFILES_MANIFEST_FILE:/=\\% set PATH=%SYSTEMROOT%\\system32 +if defined RUNFILES_MANIFEST_FILE ( + set MF=%RUNFILES_MANIFEST_FILE:/=\\% +) else ( + if exist MANIFEST ( + set MF=MANIFEST + ) else ( + if exist ..\\MANIFEST ( + set MF=..\\MANIFEST + ) + ) +) +if not exist %MF% ( + echo Manifest file %MF% not found + exit /b 1 +) set F1={file1} set F2={file2} if "!F1:~0,9!" equ "external/" (set F1=!F1:~9!) else (set F1=!TEST_WORKSPACE!/!F1!) @@ -79,10 +93,30 @@ if "!RF2!" equ "" ( exit /b 1 ) ) +rem use tr command from msys64 package, msys64 is a bazel prerequisite +rem todo: in future better to pull in a binary to do this +if "{f1_to_lf}"=="1" ( + for %%f in (!RF1!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf + for %%f in (!BAZEL_SH!) do set "TR=%%~pf\\tr" + rem echo type "!RF1!" ^| !TR! -d "\\r" + type "!RF1!" | !TR! -d "\\r" > "!RF_TEMP!" + rem echo original file !RF1! replaced by !RF_TEMP! + set "RF1=!RF_TEMP!" +) +if "{f2_to_lf}"=="1" ( + for %%f in (!RF2!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf + for %%f in (!BAZEL_SH!) do set "TR=%%~dpf\\tr" + rem echo type "!RF2!" ^| !TR! -d "\\r" + type "!RF2!" | !TR! -d "\\r" > "!RF_TEMP!" + rem echo original file !RF2! replaced by !RF_TEMP! + set "RF2=!RF_TEMP!" +) +rem echo fc.exe /B "!RF1!" "!RF2!" 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. {fail_msg} + echo why? diff "!RF1!" "!RF2!" ^| cat -v exit /b 1 ) else ( fc.exe /B "!RF1!" "!RF2!" @@ -94,6 +128,8 @@ if %ERRORLEVEL% neq 0 ( fail_msg = ctx.attr.failure_message, file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), + f1_to_lf = "1" if ctx.attr.file1_to_lf else "0", + f2_to_lf = "1" if ctx.attr.file2_to_lf else "0", ), is_executable = True, ) @@ -148,13 +184,19 @@ _diff_test = rule( allow_single_file = True, mandatory = True, ), + "file1_to_lf": attr.bool( + default = False, + ), + "file2_to_lf": attr.bool( + default = False, + ), "is_windows": attr.bool(mandatory = True), }, test = True, implementation = _diff_test_impl, ) -def diff_test(name, file1, file2, failure_message = None, **kwargs): +def diff_test(name, file1, file2, failure_message = None, file1_to_lf = None, file2_to_lf = None, **kwargs): """A test that compares two files. The test succeeds if the files' contents match. @@ -163,6 +205,8 @@ def diff_test(name, file1, file2, failure_message = None, **kwargs): name: The name of the test rule. file1: Label of the file to compare to `file2`. file2: Label of the file to compare to `file1`. + file1_to_lf: Convert file1 to LF line endings before comparison. + file2_to_lf: Convert file2 to LF line endings before comparison. failure_message: Additional message to log if the files' contents do not match. **kwargs: The [common attributes for tests](https://bazel.build/reference/be/common-definitions#common-attributes-tests). """ @@ -170,6 +214,8 @@ def diff_test(name, file1, file2, failure_message = None, **kwargs): name = name, file1 = file1, file2 = file2, + file1_to_lf = file1_to_lf, + file2_to_lf = file2_to_lf, failure_message = failure_message, is_windows = select({ "@bazel_tools//src/conditions:host_windows": True, From 374f04c2598361282037b9f6f17149510923d2bd Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 28 Jun 2024 19:32:13 -0400 Subject: [PATCH 2/9] use toolchain for msys path --- rules/diff_test.bzl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index c048fe9d..19f85777 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -28,6 +28,7 @@ def _runfiles_path(f): def _diff_test_impl(ctx): if ctx.attr.is_windows: + bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path test_bin = ctx.actions.declare_file(ctx.label.name + "-test.bat") ctx.actions.write( output = test_bin, @@ -97,16 +98,16 @@ rem use tr command from msys64 package, msys64 is a bazel prerequisite rem todo: in future better to pull in a binary to do this if "{f1_to_lf}"=="1" ( for %%f in (!RF1!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf - for %%f in (!BAZEL_SH!) do set "TR=%%~pf\\tr" - rem echo type "!RF1!" ^| !TR! -d "\\r" + for %%f in ({bash_bin}) do set "TR=%%~dpf\\tr" + echo type "!RF1!" ^| !TR! -d "\\r" type "!RF1!" | !TR! -d "\\r" > "!RF_TEMP!" rem echo original file !RF1! replaced by !RF_TEMP! set "RF1=!RF_TEMP!" ) if "{f2_to_lf}"=="1" ( for %%f in (!RF2!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf - for %%f in (!BAZEL_SH!) do set "TR=%%~dpf\\tr" - rem echo type "!RF2!" ^| !TR! -d "\\r" + for %%f in ({bash_bin}) do set "TR=%%~dpf\\tr" + echo type "!RF2!" ^| !TR! -d "\\r" type "!RF2!" | !TR! -d "\\r" > "!RF_TEMP!" rem echo original file !RF2! replaced by !RF_TEMP! set "RF2=!RF_TEMP!" @@ -130,6 +131,7 @@ if %ERRORLEVEL% neq 0 ( file2 = _runfiles_path(ctx.file.file2), f1_to_lf = "1" if ctx.attr.file1_to_lf else "0", f2_to_lf = "1" if ctx.attr.file2_to_lf else "0", + bash_bin = bash_bin ), is_executable = True, ) @@ -192,6 +194,9 @@ _diff_test = rule( ), "is_windows": attr.bool(mandatory = True), }, + toolchains = [ + "@bazel_tools//tools/sh:toolchain_type", + ], test = True, implementation = _diff_test_impl, ) From 64b9e2f758cd13825d85ac8800eadf72d84e6c0c Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 28 Jun 2024 20:05:27 -0400 Subject: [PATCH 3/9] symlinks on by default on windows --- .bazelrc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..1a8080d8 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,2 @@ +# symlinks required on windows by copy_directory +startup --windows_enable_symlinks From ab187cd5bff9b4833f72b5c457feba46a1166a80 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 28 Jun 2024 20:05:35 -0400 Subject: [PATCH 4/9] update docs --- docs/diff_test_doc.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index a8c4c573..d9c551fa 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -10,7 +10,7 @@ command (fc.exe) on Windows (no Bash is required). ## diff_test
-diff_test(name, file1, file2, failure_message, kwargs)
+diff_test(name, file1, file2, failure_message, file1_to_lf, file2_to_lf, kwargs)
 
A test that compares two files. @@ -27,6 +27,8 @@ The test succeeds if the files' contents match. | file1 | Label of the file to compare to `file2`. | none | | file2 | Label of the file to compare to `file1`. | none | | failure_message | Additional message to log if the files' contents do not match. | `None` | +| file1_to_lf | Convert file1 to LF line endings before comparison. | `None` | +| file2_to_lf | Convert file2 to LF line endings before comparison. | `None` | | kwargs | The [common attributes for tests](https://bazel.build/reference/be/common-definitions#common-attributes-tests). | none | From 6b7d66e8d186fa5cfbef97ea62c7c8914d634737 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 28 Jun 2024 20:05:47 -0400 Subject: [PATCH 5/9] fix bug in copy_directory --- rules/private/copy_directory_private.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/private/copy_directory_private.bzl b/rules/private/copy_directory_private.bzl index 650e17eb..f37f0420 100644 --- a/rules/private/copy_directory_private.bzl +++ b/rules/private/copy_directory_private.bzl @@ -34,9 +34,9 @@ def _copy_cmd(ctx, src, dst): # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy # NB: robocopy return non-zero exit codes on success so we must exit 0 after calling it cmd_tmpl = """\ -if not exist \"{src}\\\" ( - echo Error: \"{src}\" is not a directory - @exit 1 +@if not exist \"{src}\\*\" ( +@ echo Error: \"{src}\" is not a directory +@ exit 1 ) @robocopy \"{src}\" \"{dst}\" /E /MIR >NUL & @exit 0 """ From 88173c956e89b9186def812cb21774f0d065a9f0 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sat, 29 Jun 2024 03:59:22 -0400 Subject: [PATCH 6/9] all tests enabled on windows --- .bazelci/presubmit.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 176e9986..9511d90c 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -108,7 +108,6 @@ tasks: # TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after # https://github.com/bazelbuild/bazel/issues/7761 is fixed ? "--test_env=LOCALAPPDATA" - ? "--test_tag_filters=-no_windows" last_green: <<: *reusable_config @@ -126,6 +125,5 @@ tasks: # TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after # https://github.com/bazelbuild/bazel/issues/7761 is fixed ? "--test_env=LOCALAPPDATA" - ? "--test_tag_filters=-no_windows" buildifier: latest From d909db419f730b2e30ce10d9d9ce660f974c2466 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sat, 29 Jun 2024 04:00:05 -0400 Subject: [PATCH 7/9] simpler API for ignore line endings --- docs/diff_test_doc.md | 5 +- docs/private/stardoc_with_diff_test.bzl | 3 - rules/diff_test.bzl | 81 ++++++++++++++----------- tests/diff_test/diff_test_tests.sh | 19 +++--- 4 files changed, 59 insertions(+), 49 deletions(-) diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index d9c551fa..8ef84448 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -10,7 +10,7 @@ command (fc.exe) on Windows (no Bash is required). ## diff_test
-diff_test(name, file1, file2, failure_message, file1_to_lf, file2_to_lf, kwargs)
+diff_test(name, file1, file2, failure_message, ignore_line_endings, kwargs)
 
A test that compares two files. @@ -27,8 +27,7 @@ The test succeeds if the files' contents match. | file1 | Label of the file to compare to `file2`. | none | | file2 | Label of the file to compare to `file1`. | none | | failure_message | Additional message to log if the files' contents do not match. | `None` | -| file1_to_lf | Convert file1 to LF line endings before comparison. | `None` | -| file2_to_lf | Convert file2 to LF line endings before comparison. | `None` | +| ignore_line_endings | Ignore differences between CRLF and LF line endings. On windows, this is forced to False if the 'tr' command can't be found in the bash installation on the host. | `True` | | kwargs | The [common attributes for tests](https://bazel.build/reference/be/common-definitions#common-attributes-tests). | none | diff --git a/docs/private/stardoc_with_diff_test.bzl b/docs/private/stardoc_with_diff_test.bzl index 2c3386ad..3f3e3474 100644 --- a/docs/private/stardoc_with_diff_test.bzl +++ b/docs/private/stardoc_with_diff_test.bzl @@ -58,9 +58,6 @@ def stardoc_with_diff_test( file1 = out_label, # Output from stardoc rule above file2 = out_file.replace(".md", "-docgen.md"), - # Stardoc generates CRLF line endings on windows. file1 has LF endings. - file2_to_lf = True, - tags = ["no_windows"], ) def update_docs( diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 19f85777..72b98077 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -26,6 +26,12 @@ def _runfiles_path(f): else: return f.path # source file +def _ignore_line_endings(ctx): + ignore_line_endings = "0" + if ctx.attr.ignore_line_endings: + ignore_line_endings = "1" + return ignore_line_endings + def _diff_test_impl(ctx): if ctx.attr.is_windows: bash_bin = ctx.toolchains["@bazel_tools//tools/sh:toolchain_type"].path @@ -52,6 +58,7 @@ if not exist %MF% ( echo Manifest file %MF% not found exit /b 1 ) +echo using %MF% set F1={file1} set F2={file2} if "!F1:~0,9!" equ "external/" (set F1=!F1:~9!) else (set F1=!TEST_WORKSPACE!/!F1!) @@ -94,30 +101,36 @@ if "!RF2!" equ "" ( exit /b 1 ) ) -rem use tr command from msys64 package, msys64 is a bazel prerequisite -rem todo: in future better to pull in a binary to do this -if "{f1_to_lf}"=="1" ( - for %%f in (!RF1!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf - for %%f in ({bash_bin}) do set "TR=%%~dpf\\tr" - echo type "!RF1!" ^| !TR! -d "\\r" - type "!RF1!" | !TR! -d "\\r" > "!RF_TEMP!" - rem echo original file !RF1! replaced by !RF_TEMP! - set "RF1=!RF_TEMP!" -) -if "{f2_to_lf}"=="1" ( - for %%f in (!RF2!) do set RF_TEMP=%TEST_TMPDIR%\\%%~nxf_lf - for %%f in ({bash_bin}) do set "TR=%%~dpf\\tr" - echo type "!RF2!" ^| !TR! -d "\\r" - type "!RF2!" | !TR! -d "\\r" > "!RF_TEMP!" - rem echo original file !RF2! replaced by !RF_TEMP! - set "RF2=!RF_TEMP!" +rem use tr command from msys64 package, msys64 is a bazel recommendation +rem todo: in future better to pull in diff.exe to align with non-windows path +if "{ignore_line_endings}"=="1" ( + if exist {bash_bin} ( + for %%f in ({bash_bin}) do set "TR=%%~dpf\\tr.exe" + ) else ( + rem match bazel's algorithm to find unix tools + set "TR=C:\\msys64\\usr\\bin\\tr.exe" + ) + if not exist !TR! ( + echo>&2 WARNING: ignore_line_endings set but !TR! not found; line endings will be compared + ) else ( + for %%f in (!RF1!) do set RF1_TEMP=%TEST_TMPDIR%\\%%~nxf_lf1 + for %%f in (!RF2!) do set RF2_TEMP=%TEST_TMPDIR%\\%%~nxf_lf2 + type "!RF1!" | !TR! -d "\\r" > "!RF1_TEMP!" + type "!RF2!" | !TR! -d "\\r" > "!RF2_TEMP!" + set "RF1=!RF1_TEMP!" + set "RF2=!RF2_TEMP!" + rem echo original file !RF1! replaced by !RF1_TEMP! + rem echo original file !RF2! replaced by !RF2_TEMP! + ) ) -rem echo fc.exe /B "!RF1!" "!RF2!" 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. {fail_msg} - echo why? diff "!RF1!" "!RF2!" ^| cat -v + set "FAIL_MSG={fail_msg}" + if "!FAIL_MSG!"=="" ( + set "FAIL_MSG=why? diff ^"!RF1!^" ^"!RF2!^" ^| cat -v" + ) + echo>&2 FAIL: files "{file1}" and "{file2}" differ. !FAIL_MSG! exit /b 1 ) else ( fc.exe /B "!RF1!" "!RF2!" @@ -129,8 +142,7 @@ if %ERRORLEVEL% neq 0 ( fail_msg = ctx.attr.failure_message, file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), - f1_to_lf = "1" if ctx.attr.file1_to_lf else "0", - f2_to_lf = "1" if ctx.attr.file2_to_lf else "0", + ignore_line_endings = _ignore_line_endings(ctx), bash_bin = bash_bin ), is_executable = True, @@ -158,14 +170,19 @@ else echo >&2 "ERROR: could not find \"{file1}\" and \"{file2}\"" exit 1 fi -if ! diff "$RF1" "$RF2"; then - echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. "{fail_msg} +if ! diff {strip_trailing_cr}"$RF1" "$RF2"; then + MSG={fail_msg} + if [[ "${{MSG}}"=="" ( + MSG="why? diff {strip_trailing_cr}"${RF1}" "${RF2}" | cat -v" + ) + echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. ${MSG}" exit 1 fi """.format( fail_msg = shell.quote(ctx.attr.failure_message), file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), + strip_trailing_cr = "--strip-trailing-cr " if ctx.attr.ignore_line_endings else "" ), is_executable = True, ) @@ -186,11 +203,8 @@ _diff_test = rule( allow_single_file = True, mandatory = True, ), - "file1_to_lf": attr.bool( - default = False, - ), - "file2_to_lf": attr.bool( - default = False, + "ignore_line_endings": attr.bool( + default = True, ), "is_windows": attr.bool(mandatory = True), }, @@ -201,7 +215,7 @@ _diff_test = rule( implementation = _diff_test_impl, ) -def diff_test(name, file1, file2, failure_message = None, file1_to_lf = None, file2_to_lf = None, **kwargs): +def diff_test(name, file1, file2, failure_message = None, ignore_line_endings = True, **kwargs): """A test that compares two files. The test succeeds if the files' contents match. @@ -210,8 +224,8 @@ def diff_test(name, file1, file2, failure_message = None, file1_to_lf = None, fi name: The name of the test rule. file1: Label of the file to compare to `file2`. file2: Label of the file to compare to `file1`. - file1_to_lf: Convert file1 to LF line endings before comparison. - file2_to_lf: Convert file2 to LF line endings before comparison. + ignore_line_endings: Ignore differences between CRLF and LF line endings. On windows, this is + forced to False if the 'tr' command can't be found in the bash installation on the host. failure_message: Additional message to log if the files' contents do not match. **kwargs: The [common attributes for tests](https://bazel.build/reference/be/common-definitions#common-attributes-tests). """ @@ -219,8 +233,7 @@ def diff_test(name, file1, file2, failure_message = None, file1_to_lf = None, fi name = name, file1 = file1, file2 = file2, - file1_to_lf = file1_to_lf, - file2_to_lf = file2_to_lf, + ignore_line_endings = ignore_line_endings, failure_message = failure_message, is_windows = select({ "@bazel_tools//src/conditions:host_windows": True, diff --git a/tests/diff_test/diff_test_tests.sh b/tests/diff_test/diff_test_tests.sh index 9fffcc65..e37b6770 100755 --- a/tests/diff_test/diff_test_tests.sh +++ b/tests/diff_test/diff_test_tests.sh @@ -80,12 +80,13 @@ eof echo bar > "$ws/$subdir/b.txt" (cd "$ws" && \ - bazel test ${flags} "//${subdir%/}:same" --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} "//${subdir%/}:same" --test_output=errors --noshow_progress 1>>"$TEST_log" 2>&1 \ || fail "expected success") (cd "$ws" && \ - bazel test ${flags} "//${subdir%/}:different" --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} "//${subdir%/}:different" --test_output=all --noshow_progress 1>>"$TEST_log" 2>&1 \ && fail "expected failure" || true) + expect_log "FAIL: files \"${subdir}a.txt\" and \"${subdir}b.txt\" differ" } @@ -175,21 +176,21 @@ diff_test( eof (cd "$ws/main" && \ - bazel test ${flags} //:same --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} //:same --test_output=errors --noshow_progress 1>"$TEST_log" 2>&1 \ || fail "expected success") (cd "$ws/main" && \ - bazel test ${flags} //:different1 --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} //:different1 --test_output=all --noshow_progress 1>"$TEST_log" 2>&1 \ && fail "expected failure" || true) expect_log 'FAIL: files "external/ext1/foo/foo.txt" and "external/ext2/foo/bar.txt" differ' (cd "$ws/main" && \ - bazel test ${flags} //:different2 --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} //:different2 --test_output=all --noshow_progress 1>"$TEST_log" 2>&1 \ && fail "expected failure" || true) expect_log 'FAIL: files "external/ext1/foo/foo.txt" and "ext1/foo/foo.txt" differ' (cd "$ws/main" && \ - bazel test ${flags} //:different3 --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test ${flags} //:different3 --test_output=all --noshow_progress 1>"$TEST_log" 2>&1 \ && fail "expected failure" || true) expect_log 'FAIL: files "ext2/foo/foo.txt" and "external/ext2/foo/foo.txt" differ' } @@ -257,15 +258,15 @@ eof echo bar > "$ws/d.txt" (cd "$ws" && \ - bazel test //:different_with_message --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test //:different_with_message --test_output=errors --noshow_progress 1>"$TEST_log" 2>&1 \ && fail "expected failure" || true) # TODO(arostovtsev): also test Windows cmd.exe escapes when https://github.com/bazelbuild/bazel-skylib/pull/363 is merged expect_log "FAIL: files \"a.txt\" and \"b.txt\" differ. This is an \`\$error\`" (cd "$ws" && \ - bazel test //:different_without_message --test_output=errors 1>"$TEST_log" 2>&1 \ + bazel test //:different_without_message --test_output=all --noshow_progress 1>"$TEST_log" 2>&1 \ && fail "expected failure" || true) - expect_log "FAIL: files \"c.txt\" and \"d.txt\" differ. $" + expect_log "FAIL: files \"c.txt\" and \"d.txt\" differ. why? diff" } cd "$TEST_TMPDIR" From 63c2bc4c560ed1929e7e0a5fae23a1598bcc14cc Mon Sep 17 00:00:00 2001 From: Chris Brown <77508021+peakschris@users.noreply.github.com> Date: Sat, 29 Jun 2024 04:26:34 -0400 Subject: [PATCH 8/9] fix: substitution --- rules/diff_test.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 72b98077..453f9558 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -173,9 +173,9 @@ fi if ! diff {strip_trailing_cr}"$RF1" "$RF2"; then MSG={fail_msg} if [[ "${{MSG}}"=="" ( - MSG="why? diff {strip_trailing_cr}"${RF1}" "${RF2}" | cat -v" + MSG="why? diff {strip_trailing_cr}"${{RF1}}" "${{RF2}}" | cat -v" ) - echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. ${MSG}" + echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. ${{MSG}}" exit 1 fi """.format( From 601b76741c6c5a3ffb03b4f9b17fe4c016054449 Mon Sep 17 00:00:00 2001 From: Chris Brown <77508021+peakschris@users.noreply.github.com> Date: Sat, 29 Jun 2024 04:34:45 -0400 Subject: [PATCH 9/9] fix: linux --- rules/diff_test.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 453f9558..e60b27c5 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -143,7 +143,7 @@ if %ERRORLEVEL% neq 0 ( file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), ignore_line_endings = _ignore_line_endings(ctx), - bash_bin = bash_bin + bash_bin = bash_bin, ), is_executable = True, ) @@ -172,9 +172,9 @@ else fi if ! diff {strip_trailing_cr}"$RF1" "$RF2"; then MSG={fail_msg} - if [[ "${{MSG}}"=="" ( + if [[ "${{MSG}}" == "" ]]; then MSG="why? diff {strip_trailing_cr}"${{RF1}}" "${{RF2}}" | cat -v" - ) + fi echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. ${{MSG}}" exit 1 fi @@ -182,7 +182,7 @@ fi fail_msg = shell.quote(ctx.attr.failure_message), file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), - strip_trailing_cr = "--strip-trailing-cr " if ctx.attr.ignore_line_endings else "" + strip_trailing_cr = "--strip-trailing-cr " if ctx.attr.ignore_line_endings else "", ), is_executable = True, ) @@ -224,7 +224,7 @@ def diff_test(name, file1, file2, failure_message = None, ignore_line_endings = name: The name of the test rule. file1: Label of the file to compare to `file2`. file2: Label of the file to compare to `file1`. - ignore_line_endings: Ignore differences between CRLF and LF line endings. On windows, this is + ignore_line_endings: Ignore differences between CRLF and LF line endings. On windows, this is forced to False if the 'tr' command can't be found in the bash installation on the host. failure_message: Additional message to log if the files' contents do not match. **kwargs: The [common attributes for tests](https://bazel.build/reference/be/common-definitions#common-attributes-tests).