Skip to content

yuyawk/rules_build_error

Repository files navigation

rules_build_error

Bazel rules to test build errors.

Description

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.

Usage

For more examples, see the example module.

Load this module from the Bazel Central Registry to use it as a Bazel module.

C/C++ example

load("@rules_build_error//lang/cc:defs.bzl", "cc_build_error_test")
load("@rules_build_error//matcher:defs.bzl", "matcher")

cc_build_error_test(
    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"),
)

Language-specific implementations

See individual language implementations:

Matcher

The matcher struct allows specific error message matching criteria. Learn more in its readme.

Contributing

Pull requests and issues are welcome! See DEVEL.md for development documentation.

CI status

Tests

Bazel Steward

Release