args attribute expansion handles shell expansion prematurely
- 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
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