Skip to content

Commit

Permalink
Fix docs on test environment and add a test
Browse files Browse the repository at this point in the history
Fixes bazelbuild#1126.

--
MOS_MIGRATED_REVID=120707955
  • Loading branch information
kchodorow authored and meteorcloudy committed Apr 25, 2016
1 parent 6ba22c0 commit 06fb7ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions site/docs/test-encyclopedia.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ <h3>Initial Conditions</h3>
<tr><td><code>LOGNAME</code></td><td>value of <code>$USER</code></td><td>required</td></tr>

<tr><td><code>PATH</code></td><td><code>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.</code></td><td>recommended</td></tr>
<tr><td><code>PWD</code></td><td><code>$TEST_SRCDIR</code></td><td>recommended</td></tr>
<tr><td><code>PWD</code></td><td><code>$TEST_SRCDIR/<i>workspace-name</i></code></td><td>recommended</td></tr>
<tr><td><code>SHLVL</code></td><td><code>2</code></td><td>recommended</td></tr>
<tr><td><code>TEST_PREMATURE_EXIT_FILE</code></td><td>absolute path to a private file in a writable directory (used for catching calls to exit())</td><td>optional</td></tr>
<tr><td><code>TEST_RANDOM_SEED</code></td><td>See <a href="bazel-user-manual.html#other_options_for_blaze_test">this table</a>.</td><td>optional</td></tr>
Expand All @@ -222,13 +222,16 @@ <h3>Initial Conditions</h3>

<tr><td><code>USER</code></td><td>value of <code>getpwuid(getuid())-&gt;pw_name</code></td><td>required</td></tr>

<tr><td><code>XML_OUTPUT_FILE</code></td><td>Location of the <code>ANT</code>-like XML output file</td><td>optional</td></tr>
<tr><td><code>TEST_WORKSPACE</code></td><td>the local repository's workspace name</td><td>optional</td></tr>

</tbody>
</table>
<br>
<p>The environment may contain additional entries. Tests should not depend on the
presence, absence, or value of any environment variable not listed above.</p>

<p>The initial working directory shall be <code>$TEST_SRCDIR</code>.</p>
<p>The initial working directory shall be <code>$TEST_SRCDIR/$TEST_WORKSPACE</code>.</p>
<p> The current process id, process group id, session id, and parent process
id are unspecified. The process may or may not be a process group leader or a
session leader. The process may or may not have a controlling terminal. The
Expand Down
25 changes: 25 additions & 0 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ EOF
expect_log "TEST_TMPDIR=$TEST_TMPDIR"
}

function test_env_vars() {
cat > WORKSPACE <<EOF
workspace(name = "bar")
EOF
mkdir -p foo
cat > foo/testenv.sh <<'EOF'
#!/bin/bash
echo "pwd: $PWD"
echo "src: $TEST_SRCDIR"
echo "ws: $TEST_WORKSPACE"
EOF
chmod +x foo/testenv.sh
cat > foo/BUILD <<EOF
sh_test(
name = "foo",
srcs = ["testenv.sh"],
)
EOF

bazel test --test_output=all //foo &> $TEST_log || fail "Test failed"
expect_log "pwd: .*/foo.runfiles/bar$"
expect_log "src: .*/foo.runfiles$"
expect_log "ws: bar$"
}

function test_run_under_label_with_options() {
mkdir -p testing run || fail "mkdir testing run failed"
cat <<EOF > run/BUILD
Expand Down

0 comments on commit 06fb7ef

Please sign in to comment.