From 7a8a7a5f2df5f683ac7ba3c6da59c8b996451702 Mon Sep 17 00:00:00 2001 From: yuyawk Date: Sun, 7 Apr 2024 15:10:56 +0900 Subject: [PATCH] add a test: tests/cc/cpp_compile_error_with_local_defines --- .../BUILD.bazel | 40 +++++++++++++++++++ .../cpp_compile_error.cpp | 8 ++++ 2 files changed, 48 insertions(+) create mode 100644 tests/cc/cpp_compile_error_with_local_defines/BUILD.bazel create mode 100644 tests/cc/cpp_compile_error_with_local_defines/cpp_compile_error.cpp diff --git a/tests/cc/cpp_compile_error_with_local_defines/BUILD.bazel b/tests/cc/cpp_compile_error_with_local_defines/BUILD.bazel new file mode 100644 index 0000000..eaabd2f --- /dev/null +++ b/tests/cc/cpp_compile_error_with_local_defines/BUILD.bazel @@ -0,0 +1,40 @@ +load("//lang/cc:defs.bzl", "cc_build_error") +load("//matcher:defs.bzl", "matcher") +load("@bazel_skylib//rules:build_test.bzl", "build_test") + +cc_build_error( + name = "plain", + src = "cpp_compile_error.cpp", + local_defines = ["MACRO_IN_LOCAL_DEFINES"], +) + +cc_build_error( + name = "with_substr_matcher", + src = "cpp_compile_error.cpp", + compile_stderr = matcher.has_substr("With local_defines, "), + local_defines = ["MACRO_IN_LOCAL_DEFINES"], +) + +cc_build_error( + name = "with_basic_regex_matcher", + src = "cpp_compile_error.cpp", + compile_stderr = matcher.contains_basic_regex("With local_defines, this.*"), + local_defines = ["MACRO_IN_LOCAL_DEFINES"], +) + +cc_build_error( + name = "with_extended_regex_matcher", + src = "cpp_compile_error.cpp", + compile_stderr = matcher.contains_extended_regex("With local_defines, this.*"), + local_defines = ["MACRO_IN_LOCAL_DEFINES"], +) + +build_test( + name = "build_test", + targets = [ + ":plain", + ":with_substr_matcher", + ":with_basic_regex_matcher", + ":with_extended_regex_matcher", + ], +) diff --git a/tests/cc/cpp_compile_error_with_local_defines/cpp_compile_error.cpp b/tests/cc/cpp_compile_error_with_local_defines/cpp_compile_error.cpp new file mode 100644 index 0000000..7d734fe --- /dev/null +++ b/tests/cc/cpp_compile_error_with_local_defines/cpp_compile_error.cpp @@ -0,0 +1,8 @@ +int main() +{ + +#ifdef MACRO_IN_LOCAL_DEFINES + static_assert(false, "With local_defines, this error must show up"); +#endif + return 0; +}