From 3febb9cfc8d32d0d692d97feb37aaeb11e653ed7 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 10 Oct 2024 23:41:41 +0000 Subject: [PATCH] [bazel] Add include-cleaner tests --- .../include-cleaner/BUILD.bazel | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/include-cleaner/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/include-cleaner/BUILD.bazel index 28f90efb3ba7f..5b210ad80c874 100644 --- a/utils/bazel/llvm-project-overlay/clang-tools-extra/include-cleaner/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/include-cleaner/BUILD.bazel @@ -2,7 +2,9 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("//llvm:lit_test.bzl", "lit_test", "package_path") package( default_visibility = ["//visibility:public"], @@ -61,3 +63,71 @@ cc_binary( "//llvm:Support", ], ) + +cc_test( + name = "unittests", + srcs = glob(["unittests/*.cpp"]), + deps = [ + ":include_cleaner", + ":include_cleaner_internal", + "//clang:ast", + "//clang:basic", + "//clang:format", + "//clang:frontend", + "//clang:lex", + "//clang:serialization", + "//clang:testing", + "//clang:tooling", + "//clang:tooling_inclusions", + "//llvm:Support", + "//llvm:TestingAnnotations", + "//third-party/unittest:gmock", + "//third-party/unittest:gtest", + ], +) + +LLVM_LIT_PATH_FUNCTION = " " + \ + "# Allow generated file to be relocatable.\n" + \ + "from pathlib import Path\n" + \ + "def path(p):\n" + \ + " p = Path(p)\n" + \ + " if p.exists: return str(p.resolve())\n" + \ + " if not p: return ''\n" + \ + " return str((Path(__file__).parent / p).resolve())\n" + +LIT_SITE_CFG_IN_HEADER = "# Autogenerated, do not edit." + LLVM_LIT_PATH_FUNCTION + +expand_template( + name = "lit_site_cfg_py", + testonly = True, + out = "test/lit.site.cfg.py", + substitutions = { + "@CMAKE_CURRENT_BINARY_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test", + "@CMAKE_CURRENT_SOURCE_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD") + "/test", + "@CURRENT_TOOLS_DIR@": package_path("//clang-tools-extra/include-cleaner:BUILD"), + "@LIT_SITE_CFG_IN_HEADER@": LIT_SITE_CFG_IN_HEADER, + "@LLVM_LIBS_DIR@": package_path("//llvm:BUILD"), + "@LLVM_LIT_TOOLS_DIR@": package_path("//llvm:BUILD"), + "@LLVM_TOOLS_DIR@": package_path("//llvm:BUILD"), + "@TARGET_TRIPLE@": "", + '"@Python3_EXECUTABLE@"': "sys.executable", + }, + template = "test/lit.site.cfg.py.in", +) + +[ + lit_test( + name = "%s.test" % src, + srcs = [src], + data = glob(["test/Inputs/**/*"]) + [ + "test/lit.cfg.py", + "test/lit.site.cfg.py", + ":clang-include-cleaner", + "//llvm:FileCheck", + "//llvm:count", + "//llvm:not", + ], + args = ["-svv"], + ) + for src in glob(["test/*.cpp"]) +]