From 54a9c0b7e8b23eb7338bf38022745e9095b80641 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 15 Nov 2024 12:32:21 -0800 Subject: [PATCH] Add test for Unicode console output Closes #24243. PiperOrigin-RevId: 696968080 Change-Id: I8ad1dbe03c54b3a8d13f699026140f114f75e928 --- src/test/shell/bazel/bazel_ui_test.sh | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/shell/bazel/bazel_ui_test.sh b/src/test/shell/bazel/bazel_ui_test.sh index fe84f5867e271e..ee58820ed34393 100755 --- a/src/test/shell/bazel/bazel_ui_test.sh +++ b/src/test/shell/bazel/bazel_ui_test.sh @@ -56,6 +56,14 @@ msys*) ;; esac +if $is_windows; then + export LC_ALL=C.utf8 +elif [[ "$(uname -s)" == "Linux" ]]; then + export LC_ALL=C.UTF-8 +else + export LC_ALL=en_US.UTF-8 +fi + #### SETUP ############################################################# add_to_bazelrc "build --genrule_strategy=local" @@ -86,4 +94,36 @@ function test_fetch { expect_log 'Fetching.*remote_file' } +function expect_log_with_msys_unicode_fix() { + if $is_windows; then + # MSYS grep for some reason doesn't find Unicode characters, so we convert + # both the pattern and the log to hex and search for the hex pattern. + # https://github.com/msys2/MSYS2-packages/issues/5001 + local -r pattern_hex="$(echo -n "$1" | hexdump -ve '1/1 "%.2x"')" + hexdump -ve '1/1 "%.2x"' $TEST_log | grep -q -F "$pattern_hex" || + fail "Could not find \"$1\" in \"$(cat $TEST_log)\" (via hexdump)" + else + expect_log "$1" + fi +} + +function test_unicode_output { + local -r unicode_string="äöüÄÖÜß🌱" + + mkdir -p pkg + cat > pkg/BUILD <$TEST_log || fail "bazel build failed" + expect_log_with_msys_unicode_fix "str_${unicode_string}" + expect_log_with_msys_unicode_fix "out_${unicode_string}" +} + run_suite "Bazel-specific integration tests for the UI"