From 8e940d97248e19e998abc6297514cd966f2e2357 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Tue, 13 Jun 2023 16:38:08 -0700 Subject: [PATCH] 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) --- common/BUILD | 50 +++---------------- common/fuzzing/BUILD | 2 +- explorer/ast/BUILD | 8 +-- explorer/common/BUILD | 2 +- explorer/fuzzing/BUILD | 2 +- explorer/parse_and_execute/BUILD | 2 +- explorer/syntax/BUILD | 4 +- migrate_cpp/BUILD | 2 +- migrate_cpp/cpp_refactoring/BUILD | 6 +-- testing/util/BUILD | 44 ++++++++++++++++ {common => testing/util}/gtest_main.cpp | 0 {common => testing/util}/test_raw_ostream.h | 6 +-- .../util}/test_raw_ostream_test.cpp | 2 +- toolchain/diagnostics/BUILD | 4 +- toolchain/driver/BUILD | 4 +- toolchain/driver/driver_test.cpp | 2 +- toolchain/lexer/BUILD | 8 +-- toolchain/parser/BUILD | 4 +- toolchain/semantics/BUILD | 2 +- toolchain/source/BUILD | 2 +- 20 files changed, 82 insertions(+), 74 deletions(-) create mode 100644 testing/util/BUILD rename {common => testing/util}/gtest_main.cpp (100%) rename {common => testing/util}/test_raw_ostream.h (86%) rename {common => testing/util}/test_raw_ostream_test.cpp (96%) diff --git a/common/BUILD b/common/BUILD index 7b460ef7c0e3..05ddac481212 100644 --- a/common/BUILD +++ b/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", ], ) diff --git a/common/fuzzing/BUILD b/common/fuzzing/BUILD index 98600ebf433c..11df36f7a995 100644 --- a/common/fuzzing/BUILD +++ b/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", ], ) diff --git a/explorer/ast/BUILD b/explorer/ast/BUILD index 01311d2a778b..0573410a31e1 100644 --- a/explorer/ast/BUILD +++ b/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", ], diff --git a/explorer/common/BUILD b/explorer/common/BUILD index 4159e1cead51..50e80e952d88 100644 --- a/explorer/common/BUILD +++ b/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", ], ) diff --git a/explorer/fuzzing/BUILD b/explorer/fuzzing/BUILD index 808f98b084a3..fb3dbf7f9f61 100644 --- a/explorer/fuzzing/BUILD +++ b/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", diff --git a/explorer/parse_and_execute/BUILD b/explorer/parse_and_execute/BUILD index db0b6cc7afd4..e9f7276306a4 100644 --- a/explorer/parse_and_execute/BUILD +++ b/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", ], ) diff --git a/explorer/syntax/BUILD b/explorer/syntax/BUILD index 03df0e9d1aa1..e2a402ee69d7 100644 --- a/explorer/syntax/BUILD +++ b/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", ], ) diff --git a/migrate_cpp/BUILD b/migrate_cpp/BUILD index c63a6ea03a88..084228b2cf8c 100644 --- a/migrate_cpp/BUILD +++ b/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", diff --git a/migrate_cpp/cpp_refactoring/BUILD b/migrate_cpp/cpp_refactoring/BUILD index 91391e72684a..4efe8247f049 100644 --- a/migrate_cpp/cpp_refactoring/BUILD +++ b/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", ], diff --git a/testing/util/BUILD b/testing/util/BUILD new file mode 100644 index 000000000000..5792f8e85490 --- /dev/null +++ b/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", + ], +) diff --git a/common/gtest_main.cpp b/testing/util/gtest_main.cpp similarity index 100% rename from common/gtest_main.cpp rename to testing/util/gtest_main.cpp diff --git a/common/test_raw_ostream.h b/testing/util/test_raw_ostream.h similarity index 86% rename from common/test_raw_ostream.h rename to testing/util/test_raw_ostream.h index 50e54b2de09b..5d22ab55b106 100644 --- a/common/test_raw_ostream.h +++ b/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 @@ -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_ diff --git a/common/test_raw_ostream_test.cpp b/testing/util/test_raw_ostream_test.cpp similarity index 96% rename from common/test_raw_ostream_test.cpp rename to testing/util/test_raw_ostream_test.cpp index e4c84034da3f..5023e795fe7a 100644 --- a/common/test_raw_ostream_test.cpp +++ b/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 #include diff --git a/toolchain/diagnostics/BUILD b/toolchain/diagnostics/BUILD index 4ed367dd831c..42a95802cc69 100644 --- a/toolchain/diagnostics/BUILD +++ b/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", ], diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index f54c84e9ae2d..1d89fa65e1a0 100644 --- a/toolchain/driver/BUILD +++ b/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", diff --git a/toolchain/driver/driver_test.cpp b/toolchain/driver/driver_test.cpp index ae7b9792d2c4..0fb5bb68bdd1 100644 --- a/toolchain/driver/driver_test.cpp +++ b/toolchain/driver/driver_test.cpp @@ -7,10 +7,10 @@ #include #include -#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" diff --git a/toolchain/lexer/BUILD b/toolchain/lexer/BUILD index 3daa25c4fbb6..e2ccd82ae1f7 100644 --- a/toolchain/lexer/BUILD +++ b/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", diff --git a/toolchain/parser/BUILD b/toolchain/parser/BUILD index 4eba4f0e496f..c55995813b4f 100644 --- a/toolchain/parser/BUILD +++ b/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", ], diff --git a/toolchain/semantics/BUILD b/toolchain/semantics/BUILD index ef658ee7ae50..93dfac865cf5 100644 --- a/toolchain/semantics/BUILD +++ b/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", diff --git a/toolchain/source/BUILD b/toolchain/source/BUILD index a33bb89400e4..be24c1d17ddd 100644 --- a/toolchain/source/BUILD +++ b/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", ],