aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell/integration/action_env_test.sh
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-06-29 11:16:32 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-29 11:56:15 +0200
commit8a3cc9bb48026184b0c937f0ce7e37ab04621036 (patch)
tree80e70a6a821cfc7932fc2a0940d98dd46ecd18ea /src/test/shell/integration/action_env_test.sh
parent6a8a174bd09e8f124397db10f85cc22a510a782c (diff)
Add a test verifying that --action_env triggers a rerun of tests
Issue #3265 went unnoticed for a long time, till it was fixed as a sideeffect of d1c5329ba622b29afd3ab9f670fa17064d493bc0. To avoid that happing in the future, add a test. Closes #3265. Change-Id: Ie22a1d4a2f09fd3dcadcbd900795b3e12b7dc461 PiperOrigin-RevId: 160502516
Diffstat (limited to 'src/test/shell/integration/action_env_test.sh')
-rwxr-xr-xsrc/test/shell/integration/action_env_test.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/shell/integration/action_env_test.sh b/src/test/shell/integration/action_env_test.sh
index 2564a5a4cb..98e56de5bd 100755
--- a/src/test/shell/integration/action_env_test.sh
+++ b/src/test/shell/integration/action_env_test.sh
@@ -39,6 +39,11 @@ load("//pkg:build.bzl", "environ")
environ(name = "no_default_env", env = 0)
environ(name = "with_default_env", env = 1)
+
+sh_test(
+ name = "test_env_foo",
+ srcs = ["test_env_foo.sh"],
+)
EOF
cat > pkg/build.bzl <<EOF
def _impl(ctx):
@@ -55,6 +60,15 @@ environ = rule(
outputs={"out": "%{name}.env"},
)
EOF
+ cat > pkg/test_env_foo.sh <<'EOF'
+#!/bin/sh
+
+echo "FOO is >${FOO}<"
+
+{ echo "${FOO}" | grep foo; } || { echo "expected FOO to contain foo"; exit 1; }
+
+EOF
+ chmod u+x pkg/test_env_foo.sh
}
#### TESTS #############################################################
@@ -184,4 +198,24 @@ function test_use_default_shell_env {
&& fail "dynamic action_env used, even though requested not to") || true
}
+function test_action_env_changes_honored {
+ # Verify that changes to the explicitly specified action_env in honored in
+ # tests. Regression test for #3265.
+
+ # start with a fresh bazel, to have a reproducible starting point
+ bazel clean --expunge
+ bazel test --test_output=all --action_env=FOO=foo //pkg:test_env_foo \
+ || fail "expected to pass with correct value for FOO"
+ # While the test is cached, changing the environment should rerun it and
+ # detect the failure in the new environemnt.
+ (bazel test --test_output=all --action_env=FOO=bar //pkg:test_env_foo \
+ && fail "expected to fail with incorrect value for FOO") || true
+ # Redo the same FOO being taken from the environment
+ env FOO=foo bazel test --test_output=all --action_env=FOO //pkg:test_env_foo \
+ || fail "expected to pass with correct value for FOO from the environment"
+ (env FOO=bar bazel test --test_output=all --action_env=FOO=bar //pkg:test_env_foo \
+ && fail "expected to fail with incorrect value for FOO from the environment") || true
+
+}
+
run_suite "Tests for bazel's handling of environment variables in actions"