Skip to content

Commit

Permalink
Update testing information for Bazel and Bazelisk
Browse files Browse the repository at this point in the history
  • Loading branch information
drinckes committed Dec 23, 2024
1 parent 1db90df commit a7dd8df
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Testing
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).
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).
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.

Create a `BUILD` file in your code directory with a [test rule](https://bazel.build/versions/master/docs/test-encyclopedia.html).
You can then test your code by running:
Expand All @@ -15,7 +17,8 @@ bazel test ...:all
```

## Automated Integration Testing
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).
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).

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

Expand Down Expand Up @@ -65,8 +68,17 @@ An example of a language using bazel is Python:
run: bazel test --test_output=all ${OLC_PATH}:all
```

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

### Adding Your Tests

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).
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).

## Bazel version

Currently (2004), Bazel version 8 or later cannot be used for testing. (See issue #662.)
The `js/closure` tests require using https://github.com/bazelbuild/rules_closure, which is not yet available as a Bazel module.
That dependency must be specified using a Bazel `WORKSPACE` file, and the version of Bazel to use is specified in the `.bazeliskrc` file.

0 comments on commit a7dd8df

Please sign in to comment.