Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions development/cli/execute_unit_tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <assert.h>

// 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;
}
Loading