2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-12-02 10:15:22 +00:00
bazel-lib/lib/testing.bzl
Alex Eagle 896ee0c1f0 chore: set test timeouts to short
I recently enabled --test_verbose_timeout_warnings and that caused a bunch of warnings in our build.
This fixes it, and adds a utility for us or others to make test-wrapping macros that set to short by default.
2022-08-20 13:58:43 -07:00

39 lines
1.1 KiB
Python

"Helpers for making test assertions"
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib:utils.bzl", "default_timeout")
def assert_contains(name, actual, expected, size = None, timeout = None):
"""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
size: the size attribute of the test target
timeout: the timeout attribute of the test target
"""
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],
size = size,
timeout = default_timeout(size, timeout),
data = [actual],
)