testing
Helpers for making test assertions
Macros and Functions
assert_contains
Generates a test target which fails if the file doesn't contain the string.
Depends on bash, as it creates an sh_test target.
Example usage (generated):
load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains")
assert_contains(
# target to create
name = "",
# Label of a file
actual = None,
# a string which should appear in the file
expected = None,
)
name
Required.
target to create
actual
Required.
Label of a file
expected
Required.
a string which should appear in the file
size
Optional. Default: "small"
standard attribute for tests
kwargs
Optional.
additional named arguments for the resulting sh_test
assert_outputs
Assert that the default outputs of a target are the expected ones.
Example usage (generated):
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
assert_outputs(
# name of the resulting diff_test
name = "",
# string of the label to check the outputs
actual = None,
# a list of rootpaths of expected outputs, as they would appear in a runfiles manifest
expected = None,
)
name
Required.
name of the resulting diff_test
actual
Required.
string of the label to check the outputs
expected
Required.
a list of rootpaths of expected outputs, as they would appear in a runfiles manifest
kwargs
Optional.
additional named arguments for the resulting diff_test
assert_json_matches
Assert that the given json files have the same semantic content.
Uses jq to filter each file. The default value of "."
as the filter
means to compare the whole file.
See the jq rule for more about the filter expressions as well as
setup notes for the jq
toolchain.
Example usage (generated):
load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")
assert_json_matches(
# name of resulting diff_test target
name = "",
# a json file
file1 = None,
# another json file
file2 = None,
)
name
Required.
name of resulting diff_test target
file1
Required.
a json file
file2
Required.
another json file
filter1
Optional. Default: "."
a jq filter to apply to file1
filter2
Optional. Default: "."
a jq filter to apply to file2
kwargs
Optional.
additional named arguments for the resulting diff_test
assert_archive_contains
Assert that an archive file contains at least the given file entries.
Example usage (generated):
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
assert_archive_contains(
# name of the resulting sh_test target
name = "",
# Label of the the .tar or .zip file
archive = None,
# a (partial) file listing, either as a Label of a file containing it, or a list of strings
expected = None,
)
name
Required.
name of the resulting sh_test target
archive
Required.
Label of the the .tar or .zip file
expected
Required.
a (partial) file listing, either as a Label of a file containing it, or a list of strings
type
Optional. Default: None
"tar" or "zip". If None, a type will be inferred from the filename.
kwargs
Optional.
additional named arguments for the resulting sh_test
assert_directory_contains
Assert that a directory contains at least the given file entries.
Example usage (generated):
load("@aspect_bazel_lib//lib:testing.bzl", "assert_directory_contains")
assert_directory_contains(
# name of the resulting sh_test target
name = "",
# Label of the directory artifact
directory = None,
# a (partial) file listing, either as a Label of a file containing it, or a list of strings
expected = None,
)
name
Required.
name of the resulting sh_test target
directory
Required.
Label of the directory artifact
expected
Required.
a (partial) file listing, either as a Label of a file containing it, or a list of strings
kwargs
Optional.
additional named arguments for the resulting sh_test