From 7b375f28b8a37a41d0c2704206c404093b55ef66 Mon Sep 17 00:00:00 2001 From: yuyawk Date: Fri, 30 Jan 2026 22:17:51 +0900 Subject: [PATCH] add a test --- development/cli/execute_unit_tests.bash | 6 ++-- .../BUILD.bazel | 33 +++++++++++++++++++ .../c_compile_error.c | 0 .../BUILD.bazel | 0 .../c_compile_error.c | 19 +++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/BUILD.bazel rename tests/unit/cc/{c_compile_error_matcher_using_select => c_compile_error_matcher_using_select_in_pattern}/c_compile_error.c (100%) rename tests/unit/cc/{c_compile_error_matcher_using_select => c_compile_error_matcher_using_select_switching_matcher}/BUILD.bazel (100%) create mode 100644 tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/c_compile_error.c diff --git a/development/cli/execute_unit_tests.bash b/development/cli/execute_unit_tests.bash index 1d5e8d7..8ac7999 100755 --- a/development/cli/execute_unit_tests.bash +++ b/development/cli/execute_unit_tests.bash @@ -57,5 +57,7 @@ check_bazel_build_error //tests/unit/cc/cpp_inline_src:incorrect_extension check_bazel_build_error //tests/unit/cc/cpp_inline_src:incorrect_extension.test check_bazel_build_error //tests/unit/cc/c_inline_src:incorrect_extension check_bazel_build_error //tests/unit/cc/c_inline_src:incorrect_extension.test -check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select:incorrect_matcher -check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select:incorrect_matcher.test +check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select_in_pattern:incorrect_matcher +check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select_in_pattern:incorrect_matcher.test +check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher:incorrect_matcher +check_bazel_build_error //tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher:incorrect_matcher.test diff --git a/tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/BUILD.bazel b/tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/BUILD.bazel new file mode 100644 index 0000000..faa4b9c --- /dev/null +++ b/tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/BUILD.bazel @@ -0,0 +1,33 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("//matcher:defs.bzl", "matcher") +load("//tests/unit/cc:utils.bzl", "check_build_and_test") + +check_build_and_test( + name = "with_select_switching_matcher", + src = "c_compile_error.c", + compile_stderr = select({ + "@platforms//os:linux": matcher.has_substr("The target platform is linux"), + "@platforms//os:windows": matcher.contains_basic_regex(r"The[[:space:]]target \(p\|P\)latform is Windows"), + "@platforms//os:macos": matcher.contains_extended_regex("The[[:space:]]target (p|P)latform is macOS"), + "//conditions:default": None, + }), +) + +build_test( + name = "build_test", + targets = [ + ":with_select_switching_matcher", + ], +) + +# Test case which should fail to build +check_build_and_test( + name = "incorrect_matcher", + src = "c_compile_error.c", + compile_stderr = select({ + "@platforms//os:linux": matcher.has_substr("The target platform is Windows"), + "@platforms//os:windows": matcher.contains_basic_regex(r"The[[:space:]]target \(p\|P\)latform is macOS"), + "@platforms//os:macos": matcher.contains_extended_regex("The[[:space:]]target (p|P)latform is linux"), + }), + tags = ["manual"], +) diff --git a/tests/unit/cc/c_compile_error_matcher_using_select/c_compile_error.c b/tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/c_compile_error.c similarity index 100% rename from tests/unit/cc/c_compile_error_matcher_using_select/c_compile_error.c rename to tests/unit/cc/c_compile_error_matcher_using_select_in_pattern/c_compile_error.c diff --git a/tests/unit/cc/c_compile_error_matcher_using_select/BUILD.bazel b/tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/BUILD.bazel similarity index 100% rename from tests/unit/cc/c_compile_error_matcher_using_select/BUILD.bazel rename to tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/BUILD.bazel diff --git a/tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/c_compile_error.c b/tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/c_compile_error.c new file mode 100644 index 0000000..6bd86fe --- /dev/null +++ b/tests/unit/cc/c_compile_error_matcher_using_select_switching_matcher/c_compile_error.c @@ -0,0 +1,19 @@ +#include + +// Select the error message based on the target platform. + +#if defined(__linux__) +#define ERROR_MESSAGE "The target platform is linux" +#elif defined(_WIN32) || defined(_WIN64) +#define ERROR_MESSAGE "The target platform is Windows" +#elif defined(__APPLE__) && defined(__MACH__) +#define ERROR_MESSAGE "The target platform is macOS" +#else +#define ERROR_MESSAGE "The target platform is unknown" +#endif + +int main() +{ + static_assert(0, ERROR_MESSAGE); + return 0; +}