|
144 | 144 | expect_log "ws: _main$" |
145 | 145 | } |
146 | 146 |
|
| 147 | +function test_env_vars_override() { |
| 148 | + cat > WORKSPACE <<EOF |
| 149 | +workspace(name = "bar") |
| 150 | +EOF |
| 151 | + add_rules_cc_to_workspace WORKSPACE |
| 152 | + mkdir -p foo |
| 153 | + cat > foo/testenv.sh <<'EOF' |
| 154 | +#!/bin/sh |
| 155 | +echo "foo: $FOO" |
| 156 | +echo "bar: $BAR" |
| 157 | +echo "baz: $BAZ" |
| 158 | +echo "test_size: $TEST_SIZE" |
| 159 | +echo "ws: $TEST_WORKSPACE" |
| 160 | +EOF |
| 161 | + chmod +x foo/testenv.sh |
| 162 | + cat > foo/BUILD <<EOF |
| 163 | +sh_test( |
| 164 | + name = "foo", |
| 165 | + srcs = ["testenv.sh"], |
| 166 | + size = "small", |
| 167 | + env = { |
| 168 | + "FOO": "frombuild", |
| 169 | + "TEST_SIZE": "ignored", |
| 170 | + }, |
| 171 | + env_inherit = [ |
| 172 | + "BAZ" |
| 173 | + ], |
| 174 | +) |
| 175 | +EOF |
| 176 | + |
| 177 | + # Test BAR is set from --action_env |
| 178 | + BAZ=fromaction bazel --ignore_all_rc_files test --test_output=all \ |
| 179 | + --action_env=BAR=fromcli --action_env=BAZ \ |
| 180 | + //foo &> $TEST_log || fail "Test failed" |
| 181 | + expect_log "foo: frombuild" |
| 182 | + expect_log "bar: fromcli" |
| 183 | + expect_log "baz: fromaction" |
| 184 | + expect_log "test_size: small" |
| 185 | + expect_log "ws: _main$" |
| 186 | + |
| 187 | + # Test FOO from the BUILD file wins |
| 188 | + # Test BAR is set from --test_env |
| 189 | + # Test BAZ is set from --test_env |
| 190 | + BAZ=fromtest bazel --ignore_all_rc_files test --test_output=all \ |
| 191 | + --action_env=FOO=fromcli --test_env=FOO=fromcli --test_env=BAR=fromcli \ |
| 192 | + --test_env=BAZ //foo &> $TEST_log || fail "Test failed" |
| 193 | + expect_log "foo: frombuild" |
| 194 | + expect_log "bar: fromcli" |
| 195 | + expect_log "baz: fromtest" |
| 196 | + expect_log "test_size: small" |
| 197 | + expect_log "ws: _main$" |
| 198 | +} |
| 199 | + |
147 | 200 | function test_runfiles_java_runfiles_merges_env_vars() { |
148 | 201 | runfiles_merges_runfiles_env_vars JAVA_RUNFILES PYTHON_RUNFILES |
149 | 202 | } |
|
0 commit comments