Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass custom flags to `bazel test` command

Tags:

bazel

gflags

I have used gflags in my test to define custom flags. How can I pass such a flag to my test while running the test via bazel test command?

For example: I can run a test multiple times using:

bazel test //xyz:my_test --runs_per_test 10 

In the same command I would like to pass a flag defined in my_test say --use_xxx, how do I do so?

like image 487
Curious Avatar asked Jun 15 '18 14:06

Curious


People also ask

How do I run Bazel commands?

To run Bazel, go to your base workspace directory or any of its subdirectories and type bazel . % bazel help [Bazel release bazel-<version>] Usage: bazel <command> <options> ... Available commands: analyze-profile Analyzes build profile data.

Where do you put Bazelrc?

Path: On Linux/macOS/Unixes: /etc/bazel. bazelrc. On Windows: %ProgramData%\bazel.

What is Bazel command?

Bazel starts exactly one server per specified output base. Typically there is one output base per workspace - however, with this option you may have multiple output bases per workspace and thereby run multiple builds for the same client on the same machine concurrently.


1 Answers

Use the --test_arg flag.

bazel test //xyz:my_test --runs_per_test=10 --test_arg=--use_xxx --test_arg=--some_number=42

From the docs:

--test_arg arg: Passes command-line options/flags/arguments to each test process. This option can be used multiple times to pass several arguments, e.g. --test_arg=--logtostderr --test_arg=--v=3.

You can also specify arguments for the test as part of the BUILD definition:

cc_test(
    name = "my_test",
    srcs = [".."],
    deps = [".."],
    args = ["--use_xxx", "--some_number=42"],
)
like image 75
Jin Avatar answered Oct 28 '22 22:10

Jin