You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TESTING.md
+22-10Lines changed: 22 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,31 @@
1
1
# 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.
3
5
4
6
Create a `BUILD` file in your code directory with a [test rule](https://bazel.build/versions/master/docs/test-encyclopedia.html).
5
7
You can then test your code by running:
6
8
7
9
```sh
8
-
bazeltest<dir>:<rule>
10
+
bazelisktest<dir>:<rule>
9
11
```
10
12
11
13
All tests can be run with:
12
14
13
15
```sh
14
-
bazeltest ...:all
16
+
bazelisktest ...:all
15
17
```
16
18
17
19
## 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).
19
22
20
23
The testing configuration is controlled by the [`.github/workflows/main.yml`](.github/workflows/main.yml) file.
This file defines each language configuration to be tested.
24
27
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.
26
29
27
30
An example of a language being tested natively is go:
28
31
@@ -43,10 +46,10 @@ An example of a language being tested natively is go:
43
46
44
47
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`.
45
48
46
-
An example of a language using bazel is Python:
49
+
An example of a language using Bazel is Python:
47
50
48
51
```
49
-
# Python implementation. Lives in python/, tested with bazel.
52
+
# Python implementation. Lives in python/, tested with Bazel.
50
53
test-python:
51
54
runs-on: ubuntu-latest
52
55
env:
@@ -62,11 +65,20 @@ An example of a language using bazel is Python:
62
65
with:
63
66
python-version: ${{ matrix.python }}
64
67
- name: test
65
-
run: bazel test --test_output=all ${OLC_PATH}:all
68
+
run: bazelisk test --test_output=all ${OLC_PATH}:all
66
69
```
67
70
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.
69
73
70
74
### Adding Your Tests
71
75
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.
0 commit comments