Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

args attribute expansion handles shell expansion prematurely #6274

Open
laszlocsomor opened this issue Oct 1, 2018 · 5 comments
Open

args attribute expansion handles shell expansion prematurely #6274

laszlocsomor opened this issue Oct 1, 2018 · 5 comments
Labels
not stale Issues or PRs that are inactive but not considered stale P2 We'll consider working on this in future. (Assignee optional) team-Local-Exec Issues and PRs for the Execution (Local) team type: bug

Comments

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Oct 1, 2018

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 <stdio.h>

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
@laszlocsomor laszlocsomor changed the title xx_test.args: empty string argument not passed to test xx_test.args: empty string not passed to test Oct 1, 2018
@jin jin added area-Windows Windows-specific issues and feature requests untriaged labels Oct 1, 2018
@laszlocsomor laszlocsomor self-assigned this Oct 5, 2018
@laszlocsomor laszlocsomor removed their assignment Oct 16, 2018
@laszlocsomor laszlocsomor added type: bug team-Execution and removed area-Windows Windows-specific issues and feature requests labels Oct 16, 2018
@philwo philwo added P2 We'll consider working on this in future. (Assignee optional) category: misc > testing and removed untriaged labels Oct 17, 2018
@jin jin added team-Local-Exec Issues and PRs for the Execution (Local) team and removed team-Execution labels Jan 14, 2019
@jmmv jmmv changed the title xx_test.args: empty string not passed to test args attribute expansion swallows empty values May 12, 2020
@jmmv jmmv changed the title args attribute expansion swallows empty values args attribute expansion handles shell expansion prematurely May 12, 2020
@jmmv
Copy link
Contributor

jmmv commented May 12, 2020

Given #6275, which reports similar problems with spaces in arguments... it seems that this code is going further and attempting to perform even more shell expansions on the arguments. I think the args list shouldn't be subject to any kind of shell expansion/handling and passed to the test program directly...

@jxramos
Copy link

jxramos commented Jan 6, 2022

I'm facing this with a py_test target that passes some marker expressions down to the underlying pytest invocation, eg something that would go like pytest -m "markerA and not markerB" is being placed in the py_test target like

py_test(
    name = "test_foo",
    args = [ "-m", "markerA and not markerB"],
    ....
)

In the pytest scenario it's taking the tokens individually and yielding

============================ no tests ran in 0.00s =============================
ERROR: file not found: and

Update
looks like I could resolve it by enclosing in single quotes

    args = [ "-m", "'markerA and not markerB'"],

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 13, 2023
@fmeum
Copy link
Collaborator

fmeum commented Jun 13, 2023

@bazelbuild/triage Not stale

@sgowroji sgowroji removed the stale Issues or PRs that are stale (no activity for 30 days) label Jun 13, 2023
@iancha1992 iancha1992 added the not stale Issues or PRs that are inactive but not considered stale label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not stale Issues or PRs that are inactive but not considered stale P2 We'll consider working on this in future. (Assignee optional) team-Local-Exec Issues and PRs for the Execution (Local) team type: bug
Projects
None yet
Development

No branches or pull requests

8 participants