2022-08-05 00:53:22 +00:00
|
|
|
"Helpers for making test assertions"
|
|
|
|
|
|
|
|
load("@bazel_skylib//rules:write_file.bzl", "write_file")
|
2022-08-20 19:53:12 +00:00
|
|
|
load("//lib:utils.bzl", "default_timeout")
|
2022-08-05 00:53:22 +00:00
|
|
|
|
2022-08-20 19:53:12 +00:00
|
|
|
def assert_contains(name, actual, expected, size = None, timeout = None):
|
2022-08-05 00:53:22 +00:00
|
|
|
"""Generates a test target which fails if the file doesn't contain the string.
|
|
|
|
|
|
|
|
Depends on bash, as it creates an sh_test target.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: target to create
|
|
|
|
actual: Label of a file
|
|
|
|
expected: a string which should appear in the file
|
2022-08-20 19:53:12 +00:00
|
|
|
size: the size attribute of the test target
|
|
|
|
timeout: the timeout attribute of the test target
|
2022-08-05 00:53:22 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
test_sh = "_{}_test.sh".format(name)
|
|
|
|
|
|
|
|
write_file(
|
|
|
|
name = "_" + name,
|
|
|
|
out = test_sh,
|
|
|
|
content = [
|
|
|
|
"#!/usr/bin/env bash",
|
|
|
|
"set -o errexit",
|
|
|
|
"grep --fixed-strings '{}' $1".format(expected),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
native.sh_test(
|
|
|
|
name = name,
|
|
|
|
srcs = [test_sh],
|
|
|
|
args = ["$(rootpath %s)" % actual],
|
2022-08-20 19:53:12 +00:00
|
|
|
size = size,
|
|
|
|
timeout = default_timeout(size, timeout),
|
2022-08-05 00:53:22 +00:00
|
|
|
data = [actual],
|
|
|
|
)
|