Files
carbon-lang/testing/file_test/BUILD
T
Richard Smith f776cf0744 Improve readability of test failures. (#7609)
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
2026-08-04 21:23:36 +00:00

111 lines
2.6 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
load("//bazel/cc_rules:defs.bzl", "cc_library", "cc_test")
load("rules.bzl", "file_test")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "autoupdate",
testonly = 1,
srcs = ["autoupdate.cpp"],
hdrs = [
"autoupdate.h",
"line.h",
],
deps = [
"//common:check",
"//common:ostream",
"//common:raw_string_ostream",
"//testing/base:file_helpers",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
"@llvm-project//llvm:Support",
"@re2",
],
)
cc_library(
name = "file_test_base",
testonly = 1,
srcs = [
"file_test_base.cpp",
"run_test.cpp",
"run_test.h",
"test_file.cpp",
],
hdrs = [
"file_test_base.h",
"test_file.h",
],
deps = [
":autoupdate",
":manifest",
"//common:build_data",
"//common:check",
"//common:error",
"//common:exe_path",
"//common:find",
"//common:init_llvm",
"//common:ostream",
"//common:pretty_stack_trace_function",
"//common:raw_string_ostream",
"//common:set",
"//testing/base:file_helpers",
"//testing/base:unified_diff",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
"@abseil-cpp//absl/strings",
"@googletest//:gtest",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "test_file_test",
size = "small",
srcs = ["test_file_test.cpp"],
deps = [
":file_test_base",
":manifest_impl",
"//common:error_test_helpers",
"//testing/base:file_helpers",
"@googletest//:gtest",
],
)
file_test(
name = "file_test_base_test",
size = "small",
srcs = ["file_test_base_test.cpp"],
data = glob(["testdata/include_files/**"]),
tests = glob(
["testdata/**"],
exclude = ["testdata/include_files/**"],
),
deps = [
":file_test_base",
"//common:ostream",
"@googletest//:gtest",
"@llvm-project//llvm:Support",
],
)
# Note this is separate from the implementation; see the .h file.
cc_library(
name = "manifest",
testonly = 1,
hdrs = ["manifest.h"],
deps = ["@llvm-project//llvm:Support"],
)
# Used through `file_test` in rules.bzl.
cc_library(
name = "manifest_impl",
testonly = 1,
srcs = ["manifest.cpp"],
deps = [":manifest"],
)