blob: d4108c86ac6827b356d58d609a4733daa202f435 [file] [log] [blame]
Googlerf00439d2023-06-29 08:39:42 -07001#!/bin/bash
2#
3# Copyright 2023 The Bazel Authors. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Test of Bazel's unicode i/o in actions
18
19# --- begin runfiles.bash initialization v3 ---
20# Copy-pasted from the Bazel Bash runfiles library v3.
21set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
22source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
23 source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
24 source "$0.runfiles/$f" 2>/dev/null || \
25 source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
26 source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
27 { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
28# --- end runfiles.bash initialization v3 ---
29
30source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
31 || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
32
Googlerdac17802023-06-29 13:48:48 -070033export LC_ALL="C.UTF-8"
34
35function set_up {
36 touch WORKSPACE
37 cp -f "$(rlocation "io_bazel/src/test/shell/integration/unicode_test_BUILD")" BUILD
38 cp -f "$(rlocation "io_bazel/src/test/shell/integration/unicode_test.bzl")" .
39 cp -f "$(rlocation "io_bazel/src/test/shell/integration/unicode_test_expected.txt")" .
40}
Googlerf00439d2023-06-29 08:39:42 -070041
42function test_unicode_genrule_cmd {
43 local test_name="genrule_cmd"
44 bazel build --genrule_strategy=local --spawn_strategy=local \
Googlerdac17802023-06-29 13:48:48 -070045 --verbose_failures "//:${test_name}" >& "$TEST_log" \
Googlerf00439d2023-06-29 08:39:42 -070046 || fail "expected build to succeed"
47
48 diff -u "${PRODUCT_NAME}-genfiles/${test_name}.out" \
49 unicode_test_expected.txt \
50 >>"${TEST_log}" 2>&1 || fail "Output not as expected"
51}
52
53function test_unicode_action_run_argument {
54 local test_name="action_run_argument"
55 bazel build --genrule_strategy=local --spawn_strategy=local \
Googlerdac17802023-06-29 13:48:48 -070056 --verbose_failures "//:${test_name}" >& "$TEST_log" \
Googlerf00439d2023-06-29 08:39:42 -070057 || fail "expected build to succeed"
58
59 diff -u "${PRODUCT_NAME}-bin/${test_name}.out" \
60 unicode_test_expected.txt \
61 >>"${TEST_log}" 2>&1 || fail "Output not as expected"
62}
63
64function test_unicode_action_write_content {
65 local test_name="action_write_content"
66 bazel build --genrule_strategy=local --spawn_strategy=local \
Googlerdac17802023-06-29 13:48:48 -070067 --verbose_failures "//:${test_name}" >& "$TEST_log" \
Googlerf00439d2023-06-29 08:39:42 -070068 || fail "expected build to succeed"
69
70 diff -u "${PRODUCT_NAME}-bin/${test_name}.out" \
71 unicode_test_expected.txt \
72 >>"${TEST_log}" 2>&1 || fail "Output not as expected"
73}
74
Googlerdc80fa72023-07-21 08:08:43 -070075function test_unicode_action_run_param_file {
76 local test_name="action_run_param_file"
77 bazel build --genrule_strategy=local --spawn_strategy=local \
78 "//:${test_name}" >& "$TEST_log" \
79 || fail "expected build to succeed"
80
81 quoted_unicode_test_expected="'$(cat unicode_test_expected.txt)'"
82
83 echo "Expected: ${quoted_unicode_test_expected}"
84
85 cat_output=$(cat "${PRODUCT_NAME}-bin/${test_name}.out")
86 assert_equals "${cat_output}" \
87 "${quoted_unicode_test_expected}" \
88 || fail "Output not as expected"
89
90 param_file_output=$(cat "${PRODUCT_NAME}-bin/${test_name}.out-0.params")
91 assert_equals "${param_file_output}" \
92 "${quoted_unicode_test_expected}" \
93 || fail "Output not as expected"
94}
95
Googlerf00439d2023-06-29 08:39:42 -070096run_suite "Integration tests for ${PRODUCT_NAME}'s unicode i/o in actions"