Skip to content

Commit

Permalink
Add test for Unicode console output
Browse files Browse the repository at this point in the history
Closes bazelbuild#24243.

PiperOrigin-RevId: 696968080
Change-Id: I8ad1dbe03c54b3a8d13f699026140f114f75e928
  • Loading branch information
fmeum authored and copybara-github committed Nov 15, 2024
1 parent 372980c commit 54a9c0b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/shell/bazel/bazel_ui_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <<EOF
print("str_${unicode_string}")
genrule(
name = "gen",
outs = ["out_${unicode_string}"],
cmd = "touch \$@",
)
EOF

bazel build //pkg:gen 2>$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"

0 comments on commit 54a9c0b

Please sign in to comment.