Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk committed Dec 21, 2024
1 parent 72f7646 commit bd01b5a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions examples/cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load(
"@rules_build_error//lang/cc:defs.bzl",
"cc_build_error",
"cc_build_error_test",
"inline_src",
)
load("@rules_build_error//matcher:defs.bzl", "matcher")

Expand Down Expand Up @@ -44,3 +45,53 @@ cc_build_error_test(
src = "link_error.cpp",
link_stderr = matcher.contains_basic_regex("Declared.*Undefined"),
)

# With `inline_src`, you can also provide the source as an inline string.

cc_build_error_test(
name = "compile_error_test_with_inline_c",
src = inline_src.c("""
#include <assert.h>
int main(void) {
static_assert(0, "Compile error message for inline src");
return 0;
}
"""),
compile_stderr = matcher.has_substr("static assertion failed"),
)

cc_build_error_test(
name = "compile_error_test_with_inline_cpp",
src = inline_src.cpp("""
constexpr bool Predicate() noexcept { return false; }
int main() {
static_assert(Predicate(), "Compile error message for inline src");
return 0;
}
"""),
compile_stderr = matcher.has_substr("static assertion failed"),
)

cc_build_error_test(
name = "link_error_test_with_inline_c",
src = inline_src.c("""
int DeclaredButUndefined();
int main(void) {
return DeclaredButUndefined();
}
"""),
link_stderr = matcher.has_substr("DeclaredButUndefined"),
)

cc_build_error_test(
name = "link_error_test_with_inline_cpp",
src = inline_src.cpp("""
int DeclaredButUndefined();
int main() {
return DeclaredButUndefined();
}
"""),
link_stderr = matcher.has_substr("DeclaredButUndefined"),
)

0 comments on commit bd01b5a

Please sign in to comment.