Search code examples
bazel

How to specify "default" target labels when running bazel test


We're considering migrating to Bazel from Make. To make the transition easier I would like to have bazel test (no flags / options) run the current directory's tests, if any.

So instead of bazel test my_tests bazel test would find the current directory's BUILD file, find any *_test rules and run those.


Solution

  • If you want to do exactly as you said then you can use your own script. When you run “bazel” it actually looks to see if there is a script named “bazel” under tools directory of the current workspace. So if you have an executable under “$workspace/tools/bazel” bazel will run that instead of the bazel binary itself. This means you can write a script that checks if the only argument is “test” and if so calls “bazel-real test :all” It can also check the exit code to see if there were no tests (it’s a specific error code) and return 0 instead