Skip to content

Commit 7ad8ce0

Browse files
authored
Update testing information for Bazel and Bazelisk (#663)
* Update testing information for Bazel and Bazelisk * use bazelisk as example commands * link issue number
1 parent 1db90df commit 7ad8ce0

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

TESTING.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
# Testing
2-
The preferred mechanism for testing is using the [Bazel](https://bazel.build/) build system. This uses files called `BUILD` ([example](https://github.com/google/open-location-code/blob/main/python/BUILD) to provide rules to build code and run tests).
2+
The preferred mechanism for testing is using the [Bazel](https://bazel.build/) build system.
3+
This uses files called `BUILD` ([example](https://github.com/google/open-location-code/blob/main/python/BUILD) to provide rules to build code and run tests).
4+
Rather than installing Bazel directly, install [Bazelisk](https://github.com/bazelbuild/bazelisk), a launcher for Bazel that allows configuration of the specific version to use.
35

46
Create a `BUILD` file in your code directory with a [test rule](https://bazel.build/versions/master/docs/test-encyclopedia.html).
57
You can then test your code by running:
68

79
```sh
8-
bazel test <dir>:<rule>
10+
bazelisk test <dir>:<rule>
911
```
1012

1113
All tests can be run with:
1214

1315
```sh
14-
bazel test ...:all
16+
bazelisk test ...:all
1517
```
1618

1719
## Automated Integration Testing
18-
On pushes and pull requests changes are tested via GitHub Actions. You can see the current test status in the [Actions tab](https://github.com/google/open-location-code/actions/workflows/main.yml?query=branch%3Amain).
20+
On pushes and pull requests changes are tested via GitHub Actions.
21+
You can see the current test status in the [Actions tab](https://github.com/google/open-location-code/actions/workflows/main.yml?query=branch%3Amain).
1922

2023
The testing configuration is controlled by the [`.github/workflows/main.yml`](.github/workflows/main.yml) file.
2124

2225
### [.github/workflows/main.yml](.github/workflows/main.yml)
2326
This file defines each language configuration to be tested.
2427

25-
Some languages can be tested natively, others are built and tested using bazel BUILD files.
28+
Some languages can be tested natively, others are built and tested using Bazel BUILD files.
2629

2730
An example of a language being tested natively is go:
2831

@@ -43,10 +46,10 @@ An example of a language being tested natively is go:
4346

4447
This defines the language, uses the `1.17` version, sets an environment variable with the path and then runs the testing command `go test ./go`.
4548

46-
An example of a language using bazel is Python:
49+
An example of a language using Bazel is Python:
4750

4851
```
49-
# Python implementation. Lives in python/, tested with bazel.
52+
# Python implementation. Lives in python/, tested with Bazel.
5053
test-python:
5154
runs-on: ubuntu-latest
5255
env:
@@ -62,11 +65,20 @@ An example of a language using bazel is Python:
6265
with:
6366
python-version: ${{ matrix.python }}
6467
- name: test
65-
run: bazel test --test_output=all ${OLC_PATH}:all
68+
run: bazelisk test --test_output=all ${OLC_PATH}:all
6669
```
6770

68-
Bazel is pre-installed on GitHub-hosted runners which are used to run CI, so there's no need to install it. This example also shows how to test with multiple versions of a language.
71+
Bazel is pre-installed on GitHub-hosted runners which are used to run CI, so there's no need to install it.
72+
This example also shows how to test with multiple versions of a language.
6973

7074
### Adding Your Tests
7175

72-
Simply add a new section to the `.github/workflows/main.yml` file with the appropriate language, and either the native test command or call `bazel test` like the other examples. More information about GitHub actions can be found in the [documentation](https://docs.github.com/en/actions/quickstart).
76+
Simply add a new section to the `.github/workflows/main.yml` file with the appropriate language, and either the native test command or call `bazelisk test` like the other examples.
77+
More information about GitHub actions can be found in the [documentation](https://docs.github.com/en/actions/quickstart).
78+
79+
## Bazel version
80+
81+
Currently (2004), Bazel version 8 or later cannot be used for testing. (See issue google/open-location-code#662.)
82+
The `js/closure` tests require using https://github.com/bazelbuild/rules_closure, which is not yet available as a Bazel module.
83+
That dependency must be specified using a Bazel `WORKSPACE` file, and the version of Bazel to use is specified in the `.bazeliskrc` file.
84+

0 commit comments

Comments
 (0)