Gazelle has a fantastically easy test fixture, using “golden” files. These can be used for extensions written either in Go or in Starlark (which is great since you can use the tests to verify a port from Go to Starlark)
Each test fixture is just a folder containing:
WORKSPACE
(just as a marker file)BUILD.in
- what the actual BUILD file looks like before running gazelleBUILD.out
- what the expected BUILD file looks like after running gazelle- Other files that exist in the package and gazelle may read
To turn a fixture into a test, use a gazelle_generation_test
rule. Here’s a convenient wrapper that we use in Aspect CLI to handle dotfiles: Embed GitHub
Note: Aspect CLI doesn’t yet expose a gazelle_binary
target including the starlark API
Example
Here’s a simple example, with JSON files that participate in a dependency graph. Imagine that our repository uses these to configure a code generator, and we want BUILD files to execute that generator using a custom rule called x_lib
.