Skip to content

Commit 03b0045

Browse files
fmeumcopybara-github
authored andcommitted
Set HOME in Unix test environment
This is mandated by the test encyclopedia, but HOME wasn't exported and isn't set by the test action. Fixes #10652 Fixes bazel-contrib/rules_go#4108 Closes #26697. PiperOrigin-RevId: 792171303 Change-Id: I60297936a9562fb61ca7aca9bb9591ea86e8f5aa
1 parent 407e045 commit 03b0045

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/test/shell/bazel/bazel_test_test.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function test_tmpdir() {
9191
#!/bin/sh
9292
set -e
9393
echo TEST_TMPDIR=$TEST_TMPDIR
94+
echo HOME=$HOME
9495
touch "$TEST_TMPDIR/foo"
96+
touch "$HOME/bar"
9597
EOF
9698
chmod +x foo/bar_test.sh
9799
cat > foo/BUILD <<EOF
@@ -105,10 +107,12 @@ EOF
105107
bazel test --test_output=all //foo:bar_test >& $TEST_log || \
106108
fail "Running sh_test failed"
107109
expect_log "TEST_TMPDIR=/.*"
110+
expect_log "HOME=/.*"
108111

109112
bazel test --nocache_test_results --test_output=all --test_tmpdir=$TEST_TMPDIR //foo:bar_test \
110113
>& $TEST_log || fail "Running sh_test failed"
111114
expect_log "TEST_TMPDIR=$TEST_TMPDIR"
115+
expect_log "HOME=$TEST_TMPDIR"
112116
}
113117

114118
function test_env_vars() {
@@ -118,6 +122,7 @@ function test_env_vars() {
118122
#!/bin/sh
119123
echo "pwd: $PWD"
120124
echo "src: $TEST_SRCDIR"
125+
echo "rd: $RUNFILES_DIR"
121126
echo "ws: $TEST_WORKSPACE"
122127
EOF
123128
chmod +x foo/testenv.sh
@@ -131,8 +136,9 @@ sh_test(
131136
EOF
132137

133138
bazel test --test_output=all //foo &> $TEST_log || fail "Test failed"
134-
expect_log "pwd: .*/foo.runfiles/_main$"
135-
expect_log "src: .*/foo.runfiles$"
139+
expect_log "pwd: /.*/foo.runfiles/_main$"
140+
expect_log "src: /.*/foo.runfiles$"
141+
expect_log "rd: /.*/foo.runfiles$"
136142
expect_log "ws: _main$"
137143
}
138144

tools/test/test-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ is_absolute "$TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR" ||
6464
is_absolute "$TEST_SRCDIR" || TEST_SRCDIR="$PWD/$TEST_SRCDIR"
6565
is_absolute "$TEST_TMPDIR" || TEST_TMPDIR="$PWD/$TEST_TMPDIR"
6666
is_absolute "$HOME" || HOME="$TEST_TMPDIR"
67+
export HOME
6768
is_absolute "$XML_OUTPUT_FILE" || XML_OUTPUT_FILE="$PWD/$XML_OUTPUT_FILE"
6869

6970
# Set USER to the current user, unless passed by Bazel via --test_env.

0 commit comments

Comments
 (0)