mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:40:11 +01:00
Reduce use of gmock matcher infrastructure for diagnosing mismatches,
and instead manually stream an explanation of the difference. The
gmock-style "EXPECT_THAT" approach adds an unsuppressable "Actual: ..."
line into the output that only contains unreadable and redundant noise.
We're getting zero value from using a matcher diagnostic here, so don't.
Before:
```
Value of: SplitOutput(test_file.actual_stdout)
Expected: matches elements with unified diff
Actual: { "--- else.carbon", "", "constants {", " %F.type: type = fn_type @F [concrete]", " %empty_tuple.type: type = tuple_type () [concrete]", " %F: %F.type = struct_value () [concrete]", " %H.type: type = fn_type @H [concrete]", " %H: %H.type = struct_value () [concrete]", " %pattern_type: type = pattern_type bool [concrete]", " %b.param_patt: %pattern_type = value_param_pattern [concrete]", " %b.patt: %pattern_type = at_binding_pattern b, %b.param_patt [concrete]", " %If.type: type = fn_type @If [concrete]", " %If: %If.type = struct_value () [concrete]", "}", "", "file {", " %If.decl: %If.type = fn_decl @If [concrete = constants.%If] {", " %b.param_patt: %pattern_type = value_param_pattern [concrete = constants.%b.param_patt]", " %b.patt: %pattern_type = at_binding_pattern b, %b.param_patt [concrete = constants.%b.patt]", " } {", " %b.param: bool = value_param call_param0", " %.loc8: type = type_literal bool [concrete = bool]", " %b: bool = wrapper_binding b, %b.param", " }", "}", "", "fn @If(%b.param: bool) {", "!entry:", " %b.ref: bool = name_ref b, %b", " if %b.ref br !if.then else br !if.else", "", "!if.then:", ... }, unified diff (- expected, + actual):
=== diff in expected elements 4 to 11 (1-based index):
%F.type: type = fn_type @F [concrete]
%empty_tuple.type: type = tuple_type () [concrete]
%F: %F.type = struct_value () [concrete]
- is equal to " %G.type: type = fn_type @G [concrete]"
- is equal to " %G: %G.type = struct_value () [concrete]"
%H.type: type = fn_type @H [concrete]
%H: %H.type = struct_value () [concrete]
%pattern_type: type = pattern_type bool [concrete]
=== diff in expected elements 37 to 44 (1-based index):
br !if.done
!if.else:
- is equal to " %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]"
- is equal to " %G.call: init %empty_tuple.type = call %G.ref()"
br !if.done
!if.done:
=== diff end
```
After:
```
Value of: testing::Value(SplitOutput(test_file.actual_stdout), testing::ElementsAreArray(test_file.expected_stdout))
Actual: false
Expected: true
unified diff (- expected, + actual):
=== diff in expected elements 4 to 11 (1-based index):
%F.type: type = fn_type @F [concrete]
%empty_tuple.type: type = tuple_type () [concrete]
%F: %F.type = struct_value () [concrete]
- %G.type: type = fn_type @G [concrete]
- %G: %G.type = struct_value () [concrete]
%H.type: type = fn_type @H [concrete]
%H: %H.type = struct_value () [concrete]
%pattern_type: type = pattern_type bool [concrete]
=== diff in expected elements 37 to 44 (1-based index):
br !if.done
!if.else:
- %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
- %G.call: init %empty_tuple.type = call %G.ref()
br !if.done
!if.done:
=== diff end
```
Assisted-by: Gemini via Antigravity
116 lines
2.8 KiB
Python
116 lines
2.8 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
#
|
|
# Trivial, single-file testing libraries. More complex libraries should get
|
|
# their own directory.
|
|
|
|
load("//bazel/cc_rules:defs.bzl", "cc_library", "cc_test")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
# This does extra initialization on top of googletest's gtest_main in order to
|
|
# provide stack traces on unexpected exits, because we normally rely on LLVM
|
|
# code for that.
|
|
#
|
|
# This replaces "@googletest//:gtest_main";
|
|
# "@googletest//:gtest" should still be used directly.
|
|
cc_library(
|
|
name = "gtest_main",
|
|
testonly = 1,
|
|
srcs = ["gtest_main.cpp"],
|
|
deps = [
|
|
":global_exe_path",
|
|
"//common:init_llvm",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
# This does extra initialization on top of Google benchmark's main in order to
|
|
# provide stack traces and setup LLVM.
|
|
#
|
|
# This replaces `@google_benchmark//:benchmark_main`;
|
|
# `@google_benchmark//:benchmark` should still be used directly.
|
|
cc_library(
|
|
name = "benchmark_main",
|
|
testonly = 1,
|
|
srcs = ["benchmark_main.cpp"],
|
|
deps = [
|
|
":global_exe_path",
|
|
"//common:init_llvm",
|
|
"@abseil-cpp//absl/flags:parse",
|
|
"@google_benchmark//:benchmark",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "capture_std_streams",
|
|
testonly = 1,
|
|
srcs = ["capture_std_streams.cpp"],
|
|
hdrs = ["capture_std_streams.h"],
|
|
deps = [
|
|
"//common:ostream",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "file_helpers",
|
|
testonly = 1,
|
|
srcs = ["file_helpers.cpp"],
|
|
hdrs = ["file_helpers.h"],
|
|
deps = [
|
|
"//common:error",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "global_exe_path",
|
|
testonly = 1,
|
|
srcs = ["global_exe_path.cpp"],
|
|
hdrs = ["global_exe_path.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:exe_path",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "global_exe_path_test",
|
|
size = "small",
|
|
srcs = ["global_exe_path_test.cpp"],
|
|
deps = [
|
|
":global_exe_path",
|
|
":gtest_main",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "unified_diff",
|
|
testonly = 1,
|
|
hdrs = ["unified_diff.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "unified_diff_test",
|
|
size = "small",
|
|
srcs = ["unified_diff_test.cpp"],
|
|
deps = [
|
|
":gtest_main",
|
|
":unified_diff",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|