Bazel rules to test build errors.
rules_build_error
provides Bazel implementations that let developers verify code that should not compile.
When executing bazel test
, standard Bazel testing rules, like cc_test
, will result in an error if a test code doesn’t compile. With rules_build_error
, a bazel build
command will instead fail when code does compile, indicating that the target is expected to raise a compilation error.
For more examples, see the example module.
Load this module from the Bazel Central Registry to use it as a Bazel module.
load("@rules_build_error//lang/cc:defs.bzl", "cc_build_error")
load("@rules_build_error//matcher:defs.bzl", "matcher")
cc_build_error(
name = "cause_compile_error",
src = "cause_compile_error.cpp",
deps = [":library_to_successfully_link"], # `:library_to_successfully_link` must provide `CcInfo`, like `cc_library`
compile_stderr = matcher.has_substr("static assertion failed"),
)
See individual language implementations:
The matcher
struct allows specific error message matching criteria. Learn more in its readme.
Pull requests and issues are welcome! See DEVEL.md for development documentation.