Przeglądaj źródła

Migrate //common test libraries to //testing/util. (#2890)

This is just a cleanup. Since we now have a testing directory, I think this is a better home for testonly libraries than //common. (I was thinking about this when I was considering adding more test_raw_ostream deps)
Jon Ross-Perkins 2 lat temu
rodzic
commit
8e940d9724

+ 7 - 43
common/BUILD

@@ -29,7 +29,7 @@ cc_test(
     srcs = ["check_test.cpp"],
     deps = [
         ":check",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
@@ -54,7 +54,7 @@ cc_test(
     deps = [
         ":enum_base",
         ":enum_base_test_def",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
@@ -74,27 +74,11 @@ cc_test(
     srcs = ["error_test.cpp"],
     deps = [
         ":error",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
 
-# 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 "@com_google_googletest//:gtest_main";
-# "@com_google_googletest//:gtest" should still be used directly.
-cc_library(
-    name = "gtest_main",
-    testonly = 1,
-    srcs = ["gtest_main.cpp"],
-    deps = [
-        "@com_google_googletest//:gtest",
-        "@llvm-project//llvm:Support",
-    ],
-)
-
 cc_library(
     name = "indirect_value",
     hdrs = ["indirect_value.h"],
@@ -105,7 +89,7 @@ cc_test(
     srcs = ["indirect_value_test.cpp"],
     deps = [
         ":indirect_value",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
@@ -120,7 +104,7 @@ cc_test(
     srcs = ["metaprogramming_test.cpp"],
     deps = [
         ":metaprogramming",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
@@ -151,32 +135,12 @@ cc_test(
     srcs = ["string_helpers_test.cpp"],
     deps = [
         ":string_helpers",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
 )
 
-cc_library(
-    name = "test_raw_ostream",
-    testonly = 1,
-    hdrs = ["test_raw_ostream.h"],
-    deps = [
-        ":ostream",
-        "@com_google_googletest//:gtest",
-    ],
-)
-
-cc_test(
-    name = "test_raw_ostream_test",
-    srcs = ["test_raw_ostream_test.cpp"],
-    deps = [
-        ":test_raw_ostream",
-        "//common:gtest_main",
-        "@com_google_googletest//:gtest",
-    ],
-)
-
 cc_library(
     name = "vlog",
     srcs = ["vlog_internal.h"],
@@ -191,7 +155,7 @@ cc_test(
     srcs = ["vlog_test.cpp"],
     deps = [
         ":vlog",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )

+ 1 - 1
common/fuzzing/BUILD

@@ -52,7 +52,7 @@ cc_test(
         ":carbon_cc_proto",
         ":proto_to_carbon_lib",
         "//common:error",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )

+ 4 - 4
explorer/ast/BUILD

@@ -80,8 +80,8 @@ cc_test(
     deps = [
         ":ast",
         ":ast_test_matchers",
-        "//common:gtest_main",
         "//explorer/common:arena",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
@@ -92,8 +92,8 @@ cc_test(
     deps = [
         ":ast",
         ":paren_contents",
-        "//common:gtest_main",
         "//explorer/common:arena",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
@@ -119,8 +119,8 @@ cc_test(
     deps = [
         ":ast",
         ":paren_contents",
-        "//common:gtest_main",
         "//explorer/common:arena",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
@@ -132,8 +132,8 @@ cc_test(
     deps = [
         ":ast",
         ":paren_contents",
-        "//common:gtest_main",
         "//explorer/common:arena",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],

+ 1 - 1
explorer/common/BUILD

@@ -27,7 +27,7 @@ cc_test(
     deps = [
         ":error_builders",
         ":source_location",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )

+ 1 - 1
explorer/fuzzing/BUILD

@@ -79,8 +79,8 @@ cc_test(
     ],
     deps = [
         ":fuzzer_util",
-        "//common:gtest_main",
         "//common/fuzzing:proto_to_carbon_lib",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@com_google_protobuf//:protobuf_headers",
         "@llvm-project//llvm:Support",

+ 1 - 1
explorer/parse_and_execute/BUILD

@@ -28,7 +28,7 @@ cc_test(
     srcs = ["parse_and_execute_test.cpp"],
     deps = [
         ":parse_and_execute",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )

+ 2 - 2
explorer/syntax/BUILD

@@ -15,8 +15,8 @@ cc_test(
     srcs = ["parse_test.cpp"],
     deps = [
         ":syntax",
-        "//common:gtest_main",
         "//explorer/common:arena",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )
@@ -145,8 +145,8 @@ cc_test(
     deps = [
         ":parse_test_matchers",
         ":syntax",
-        "//common:gtest_main",
         "//explorer/ast:ast_test_matchers",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
     ],
 )

+ 1 - 1
migrate_cpp/BUILD

@@ -47,7 +47,7 @@ cc_test(
     srcs = ["rewriter_test.cpp"],
     deps = [
         ":rewriter",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//clang:ast",
         "@llvm-project//clang:frontend",

+ 3 - 3
migrate_cpp/cpp_refactoring/BUILD

@@ -62,7 +62,7 @@ cc_test(
     deps = [
         ":fn_inserter",
         ":matcher_test_base",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//clang:tooling",
     ],
@@ -84,7 +84,7 @@ cc_test(
     deps = [
         ":for_range",
         ":matcher_test_base",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//clang:tooling",
     ],
@@ -108,7 +108,7 @@ cc_test(
     deps = [
         ":matcher_test_base",
         ":var_decl",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//clang:tooling",
     ],

+ 44 - 0
testing/util/BUILD

@@ -0,0 +1,44 @@
+# 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.
+
+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 "@com_google_googletest//:gtest_main";
+# "@com_google_googletest//:gtest" should still be used directly.
+cc_library(
+    name = "gtest_main",
+    testonly = 1,
+    srcs = ["gtest_main.cpp"],
+    deps = [
+        "@com_google_googletest//:gtest",
+        "@llvm-project//llvm:Support",
+    ],
+)
+
+cc_library(
+    name = "test_raw_ostream",
+    testonly = 1,
+    hdrs = ["test_raw_ostream.h"],
+    deps = [
+        "//common:ostream",
+        "@com_google_googletest//:gtest",
+    ],
+)
+
+cc_test(
+    name = "test_raw_ostream_test",
+    srcs = ["test_raw_ostream_test.cpp"],
+    deps = [
+        ":test_raw_ostream",
+        "//testing/util:gtest_main",
+        "@com_google_googletest//:gtest",
+    ],
+)

+ 0 - 0
common/gtest_main.cpp → testing/util/gtest_main.cpp


+ 3 - 3
common/test_raw_ostream.h → testing/util/test_raw_ostream.h

@@ -2,8 +2,8 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-#ifndef CARBON_COMMON_TEST_RAW_OSTREAM_H_
-#define CARBON_COMMON_TEST_RAW_OSTREAM_H_
+#ifndef CARBON_TESTING_UTIL_TEST_RAW_OSTREAM_H_
+#define CARBON_TESTING_UTIL_TEST_RAW_OSTREAM_H_
 
 #include <gtest/gtest.h>
 
@@ -38,4 +38,4 @@ class TestRawOstream : public llvm::raw_string_ostream {
 
 }  // namespace Carbon::Testing
 
-#endif  // CARBON_COMMON_TEST_RAW_OSTREAM_H_
+#endif  // CARBON_TESTING_UTIL_TEST_RAW_OSTREAM_H_

+ 1 - 1
common/test_raw_ostream_test.cpp → testing/util/test_raw_ostream_test.cpp

@@ -2,7 +2,7 @@
 // Exceptions. See /LICENSE for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-#include "common/test_raw_ostream.h"
+#include "testing/util/test_raw_ostream.h"
 
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>

+ 2 - 2
toolchain/diagnostics/BUILD

@@ -21,7 +21,7 @@ cc_test(
     deps = [
         ":diagnostic_emitter",
         ":mocks",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
@@ -66,7 +66,7 @@ cc_test(
         ":diagnostic_emitter",
         ":mocks",
         ":sorting_diagnostic_consumer",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],

+ 2 - 2
toolchain/driver/BUILD

@@ -32,8 +32,8 @@ cc_test(
     srcs = ["driver_test.cpp"],
     deps = [
         ":driver",
-        "//common:gtest_main",
-        "//common:test_raw_ostream",
+        "//testing/util:gtest_main",
+        "//testing/util:test_raw_ostream",
         "//toolchain/common:yaml_test_helpers",
         "//toolchain/diagnostics:diagnostic_emitter",
         "//toolchain/lexer:tokenized_buffer_test_helpers",

+ 1 - 1
toolchain/driver/driver_test.cpp

@@ -7,10 +7,10 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-#include "common/test_raw_ostream.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/SourceMgr.h"
+#include "testing/util/test_raw_ostream.h"
 #include "toolchain/common/yaml_test_helpers.h"
 #include "toolchain/diagnostics/diagnostic_emitter.h"
 

+ 4 - 4
toolchain/lexer/BUILD

@@ -26,7 +26,7 @@ cc_test(
     srcs = ["token_kind_test.cpp"],
     deps = [
         ":token_kind",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],
@@ -94,8 +94,8 @@ cc_test(
         ":numeric_literal",
         ":test_helpers",
         "//common:check",
-        "//common:gtest_main",
         "//common:ostream",
+        "//testing/util:gtest_main",
         "//toolchain/diagnostics:diagnostic_emitter",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
@@ -147,8 +147,8 @@ cc_test(
         ":string_literal",
         ":test_helpers",
         "//common:check",
-        "//common:gtest_main",
         "//common:ostream",
+        "//testing/util:gtest_main",
         "//toolchain/diagnostics:diagnostic_emitter",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
@@ -208,7 +208,7 @@ cc_test(
     deps = [
         ":tokenized_buffer",
         ":tokenized_buffer_test_helpers",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "//toolchain/common:yaml_test_helpers",
         "//toolchain/diagnostics:diagnostic_emitter",
         "//toolchain/diagnostics:mocks",

+ 2 - 2
toolchain/parser/BUILD

@@ -61,8 +61,8 @@ cc_test(
     deps = [
         ":parse_node_kind",
         ":parse_tree",
-        "//common:gtest_main",
         "//common:ostream",
+        "//testing/util:gtest_main",
         "//toolchain/common:yaml_test_helpers",
         "//toolchain/diagnostics:diagnostic_emitter",
         "//toolchain/diagnostics:mocks",
@@ -110,7 +110,7 @@ cc_test(
     srcs = ["precedence_test.cpp"],
     deps = [
         ":precedence",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "//toolchain/lexer:token_kind",
         "@com_google_googletest//:gtest",
     ],

+ 1 - 1
toolchain/semantics/BUILD

@@ -104,7 +104,7 @@ cc_test(
     size = "small",
     srcs = ["semantics_ir_test.cpp"],
     deps = [
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "//toolchain/common:yaml_test_helpers",
         "//toolchain/driver",
         "@com_google_googletest//:gtest",

+ 1 - 1
toolchain/source/BUILD

@@ -20,7 +20,7 @@ cc_test(
     srcs = ["source_buffer_test.cpp"],
     deps = [
         ":source_buffer",
-        "//common:gtest_main",
+        "//testing/util:gtest_main",
         "@com_google_googletest//:gtest",
         "@llvm-project//llvm:Support",
     ],