Skip to content

bazel run test_target doesn't convey test exit code #18493

@jacobmou

Description

@jacobmou

Description of the bug:

In bazel 6.2 release, using bazel run test_taget to execute test doesn't convey test exit code when it's 1.
In older bazel (for example, bazel 5.4, 5.3 and bazel 6.1.2 i have tested), the exit code 1 from test will be conveyed

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I set up a toy repo with WORKSPACE AS

workspace(name = "bazel_run_bug")

a BUILD file as

sh_test(
    name = "example",
    srcs = ["example.sh"],
)

and example.sh as

exit 1

With bazel 5.3/5.4/6.1.2, i get

$ /usr/bin/bazel --nohome_rc run example
INFO: Analyzed target //:example (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:example up-to-date:
  bazel-bin/example
INFO: Elapsed time: 0.084s, Critical Path: 0.00s
INFO: 2 processes: 2 internal.
INFO: Build completed successfully, 2 total actions
INFO: Running command line: external/bazel_tools/tools/test/test-setup.sh ./example
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:example
-----------------------------------------------------------------------------
$ echo $?
1

With bazel 6.2

$ bazel --nohome_rc run example
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:example (39 packages loaded, 173 targets configured).
INFO: Found 1 target...
Target //:example up-to-date:
  bazel-bin/example
INFO: Elapsed time: 2.874s, Critical Path: 0.03s
INFO: 4 processes: 4 internal.
INFO: Build completed successfully, 4 total actions
INFO: Running command line: external/bazel_tools/tools/test/test-setup.sh ./example
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:example
-----------------------------------------------------------------------------
$ echo $?
0

Which operating system are you running Bazel on?

Ubuntu 22.04

What is the output of bazel info release?

release 6.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

$ git remote get-url origin; git rev-parse main; git rev-parse HEAD
[email protected]:jacobmou/bazel_run_bug.git
1c4d3f0bed52a452a9d59d4619ae6dd0e21bafe3
1c4d3f0bed52a452a9d59d4619ae6dd0e21bafe3


### Have you found anything relevant by searching the web?

The bazel doc does not give enough details about this case https://bazel.build/run/scripts. 
From the doc, for `bazel run` 1 means build failed. But when the execution of the binary also exit with 1, the expectation is not clear. Bazel 6.1.2, 5.4 and 5.3 will still return 1, while bazel 6.2 start to return 0.

### Any other information, logs, or outputs that you want to share?

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    team-OSSIssues for the Bazel OSS team: installation, release processBazel packaging, websitetype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions