bazelbuild / bazelbuild/bazel

args attribute expansion handles shell expansion prematurely

Open
#6,274 5 comments 1 reaction 0 assignees View on GitHub
not stale P2 team-Local-Exec type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

Bazel does not pass empty test arguments from `*_test.args` to the test, but it does pass them from `--test_arg`.

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

`BUILD` file:
```
cc_test(
name = "x",
srcs = ["x.cc"],
args = [
"foo",
"",
"bar",
],
)
```

`x.cc` file:
```
#include

int main(int argc, char** argv) {
printf("TEST: argc=%d\n", argc);
for (int i = 0; i < argc; ++i) {
printf("TEST: argv[%d]=(%s)\n", i, argv[i]);
}
return 1; // make sure the test fails, so --test_output=errors prints the output
}
```

Repro:
```
$ bazel test //:x -s --test_output=errors --test_arg="baz" --test_arg="" --test_arg="qux"
(...)
external/bazel_tools/tools/test/test-setup.sh ./x foo bar baz '' qux)
FAIL: //:x (see (...)/testlogs/x/test.log)
INFO: From Testing //:x:
==================== Test output for //:x:
TEST: argc=6
TEST: argv[0]=((...)/x.runfiles/__main__/x)
TEST: argv[1]=(foo)
TEST: argv[2]=(bar)
TEST: argv[3]=(baz)
TEST: argv[4]=()
TEST: argv[5]=(qux)
(...)
```

As you see the command line does not contain the "" argument from the BUILD file, but does from the `--test_arg` flag.

### What operating system are you running Bazel on?

Linux

### What's the output of `bazel info release`?

```
$ bazel info release
release 0.17.2
```

Contributor guide

Open the contributing guide

Research direction

Use the BUILD and x.cc reproducer, then run the shown bazel test command and inspect external/bazel_tools/tools/test/test-setup.sh. Compare arguments from the BUILD file with --test_arg values; done means an empty argument from args reaches the test just like an empty --test_arg.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, shell
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.