https://github.com/aviralg updated https://github.com/llvm/llvm-project/pull/182523
>From 7b5e97d93001a816ff545fe64ce9073dff3d38e1 Mon Sep 17 00:00:00 2001 From: Aviral Goel <[email protected]> Date: Fri, 20 Feb 2026 08:09:47 -0800 Subject: [PATCH 1/4] Refactor --- .../Analysis/Scalable/CMakeLists.txt | 2 +- .../JSONFormatTest/JSONFormatTest.h | 148 +++++++++++ .../TUSummaryTest.cpp} | 245 +++++------------- 3 files changed, 210 insertions(+), 185 deletions(-) create mode 100644 clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h rename clang/unittests/Analysis/Scalable/Serialization/{JSONFormatTest.cpp => JSONFormatTest/TUSummaryTest.cpp} (88%) diff --git a/clang/unittests/Analysis/Scalable/CMakeLists.txt b/clang/unittests/Analysis/Scalable/CMakeLists.txt index 5529ca06de170..bf0d0e2f3fdea 100644 --- a/clang/unittests/Analysis/Scalable/CMakeLists.txt +++ b/clang/unittests/Analysis/Scalable/CMakeLists.txt @@ -11,7 +11,7 @@ add_distinct_clang_unittest(ClangScalableAnalysisTests Registries/MockSummaryExtractor2.cpp Registries/SerializationFormatRegistryTest.cpp Registries/SummaryExtractorRegistryTest.cpp - Serialization/JSONFormatTest.cpp + Serialization/JSONFormatTest/TUSummaryTest.cpp SummaryNameTest.cpp TestFixture.cpp TUSummaryBuilderTest.cpp diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h new file mode 100644 index 0000000000000..4abcecb63b2d5 --- /dev/null +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h @@ -0,0 +1,148 @@ +//===- unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h +//-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Test fixture and helpers for SSAF JSON serialization format unit tests. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H +#define LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H + +#include "clang/Analysis/Scalable/Serialization/JSONFormat.h" +#include "clang/Analysis/Scalable/TUSummary/TUSummary.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Testing/Support/Error.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include <memory> +#include <string> + +using namespace clang::ssaf; +using namespace llvm; +using ::testing::AllOf; +using ::testing::HasSubstr; + +// ============================================================================ +// Test Fixture +// ============================================================================ + +class JSONFormatTest : public ::testing::Test { +public: + using PathString = SmallString<128>; + +protected: + SmallString<128> TestDir; + + void SetUp() override { + std::error_code EC = + sys::fs::createUniqueDirectory("json-format-test", TestDir); + ASSERT_FALSE(EC) << "Failed to create temp directory: " << EC.message(); + } + + void TearDown() override { sys::fs::remove_directories(TestDir); } + + PathString makePath(StringRef FileOrDirectoryName) const { + PathString FullPath = TestDir; + sys::path::append(FullPath, FileOrDirectoryName); + + return FullPath; + } + + PathString makePath(StringRef Dir, StringRef FileName) const { + PathString FullPath = TestDir; + sys::path::append(FullPath, Dir, FileName); + + return FullPath; + } + + Expected<PathString> makeDirectory(StringRef DirectoryName) const { + PathString DirPath = makePath(DirectoryName); + + std::error_code EC = sys::fs::create_directory(DirPath); + if (EC) { + return createStringError(EC, "Failed to create directory '%s': %s", + DirPath.c_str(), EC.message().c_str()); + } + + return DirPath; + } + + Expected<PathString> makeSymlink(StringRef TargetFileName, + StringRef SymlinkFileName) const { + PathString TargetPath = makePath(TargetFileName); + PathString SymlinkPath = makePath(SymlinkFileName); + + std::error_code EC = sys::fs::create_link(TargetPath, SymlinkPath); + if (EC) { + return createStringError(EC, "Failed to create symlink '%s' -> '%s': %s", + SymlinkPath.c_str(), TargetPath.c_str(), + EC.message().c_str()); + } + + return SymlinkPath; + } + + llvm::Error setPermission(StringRef FileName, + const sys::fs::perms Perms) const { + PathString Path = makePath(FileName); + + std::error_code EC = sys::fs::setPermissions(Path, Perms); + if (EC) { + return createStringError(EC, "Failed to set permissions on '%s': %s", + Path.c_str(), EC.message().c_str()); + } + + return llvm::Error::success(); + } + + Expected<json::Value> readJSONFromFile(StringRef FileName) const { + PathString FilePath = makePath(FileName); + + auto BufferOrError = MemoryBuffer::getFile(FilePath); + if (!BufferOrError) { + return createStringError(BufferOrError.getError(), + "Failed to read file: %s", FilePath.c_str()); + } + + Expected<json::Value> ExpectedValue = + json::parse(BufferOrError.get()->getBuffer()); + if (!ExpectedValue) + return ExpectedValue.takeError(); + + return *ExpectedValue; + } + + Expected<PathString> writeJSON(StringRef JSON, StringRef FileName) const { + PathString FilePath = makePath(FileName); + + std::error_code EC; + llvm::raw_fd_ostream OS(FilePath, EC); + if (EC) { + return createStringError(EC, "Failed to create file '%s': %s", + FilePath.c_str(), EC.message().c_str()); + } + + OS << JSON; + OS.close(); + + if (OS.has_error()) { + return createStringError(OS.error(), "Failed to write to file '%s': %s", + FilePath.c_str(), OS.error().message().c_str()); + } + + return FilePath; + } +}; + +#endif // LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest.cpp b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp similarity index 88% rename from clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest.cpp rename to clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp index 62890da28e248..e953c7d883fdb 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest.cpp +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp @@ -1,4 +1,6 @@ -//===- unittests/Analysis/Scalable/JSONFormatTest.cpp --------------------===// +//===- +//unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp +//===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,32 +8,16 @@ // //===----------------------------------------------------------------------===// // -// Unit tests for SSAF JSON serialization format reading and writing. +// Unit tests for SSAF JSON serialization format reading and writing of +// TUSummary. // //===----------------------------------------------------------------------===// -#include "clang/Analysis/Scalable/Serialization/JSONFormat.h" -#include "clang/Analysis/Scalable/TUSummary/TUSummary.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Path.h" +#include "JSONFormatTest.h" #include "llvm/Support/Registry.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Testing/Support/Error.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include <algorithm> #include <memory> -#include <string> #include <vector> -using namespace clang::ssaf; -using namespace llvm; -using ::testing::AllOf; -using ::testing::HasSubstr; - namespace { // ============================================================================ @@ -108,117 +94,8 @@ static llvm::Registry<JSONFormat::FormatInfo>::Add< "PairsEntitySummaryForJSONFormatTest", "Format info for PairsArrayEntitySummary"); -// ============================================================================ -// Test Fixture -// ============================================================================ - -class JSONFormatTest : public ::testing::Test { -public: - using PathString = SmallString<128>; - +class TUSummaryTest : public JSONFormatTest { protected: - SmallString<128> TestDir; - - void SetUp() override { - std::error_code EC = - sys::fs::createUniqueDirectory("json-format-test", TestDir); - ASSERT_FALSE(EC) << "Failed to create temp directory: " << EC.message(); - } - - void TearDown() override { sys::fs::remove_directories(TestDir); } - - PathString makePath(StringRef FileOrDirectoryName) const { - PathString FullPath = TestDir; - sys::path::append(FullPath, FileOrDirectoryName); - - return FullPath; - } - - PathString makePath(StringRef Dir, StringRef FileName) const { - PathString FullPath = TestDir; - sys::path::append(FullPath, Dir, FileName); - - return FullPath; - } - - Expected<PathString> makeDirectory(StringRef DirectoryName) const { - PathString DirPath = makePath(DirectoryName); - - std::error_code EC = sys::fs::create_directory(DirPath); - if (EC) { - return createStringError(EC, "Failed to create directory '%s': %s", - DirPath.c_str(), EC.message().c_str()); - } - - return DirPath; - } - - Expected<PathString> makeSymlink(StringRef TargetFileName, - StringRef SymlinkFileName) const { - PathString TargetPath = makePath(TargetFileName); - PathString SymlinkPath = makePath(SymlinkFileName); - - std::error_code EC = sys::fs::create_link(TargetPath, SymlinkPath); - if (EC) { - return createStringError(EC, "Failed to create symlink '%s' -> '%s': %s", - SymlinkPath.c_str(), TargetPath.c_str(), - EC.message().c_str()); - } - - return SymlinkPath; - } - - llvm::Error setPermission(StringRef FileName, - const sys::fs::perms Perms) const { - PathString Path = makePath(FileName); - - std::error_code EC = sys::fs::setPermissions(Path, Perms); - if (EC) { - return createStringError(EC, "Failed to set permissions on '%s': %s", - Path.c_str(), EC.message().c_str()); - } - - return llvm::Error::success(); - } - - Expected<json::Value> readJSONFromFile(StringRef FileName) const { - PathString FilePath = makePath(FileName); - - auto BufferOrError = MemoryBuffer::getFile(FilePath); - if (!BufferOrError) { - return createStringError(BufferOrError.getError(), - "Failed to read file: %s", FilePath.c_str()); - } - - Expected<json::Value> ExpectedValue = - json::parse(BufferOrError.get()->getBuffer()); - if (!ExpectedValue) - return ExpectedValue.takeError(); - - return *ExpectedValue; - } - - Expected<PathString> writeJSON(StringRef JSON, StringRef FileName) const { - PathString FilePath = makePath(FileName); - - std::error_code EC; - llvm::raw_fd_ostream OS(FilePath, EC); - if (EC) { - return createStringError(EC, "Failed to create file '%s': %s", - FilePath.c_str(), EC.message().c_str()); - } - - OS << JSON; - OS.close(); - - if (OS.has_error()) { - return createStringError(OS.error(), "Failed to write to file '%s': %s", - FilePath.c_str(), OS.error().message().c_str()); - } - - return FilePath; - } - llvm::Expected<TUSummary> readTUSummaryFromFile(StringRef FileName) const { PathString FilePath = makePath(FileName); @@ -362,7 +239,7 @@ class JSONFormatTest : public ::testing::Test { // readJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, NonexistentFile) { +TEST_F(TUSummaryTest, NonexistentFile) { auto Result = readTUSummaryFromFile("nonexistent.json"); EXPECT_THAT_EXPECTED( @@ -370,7 +247,7 @@ TEST_F(JSONFormatTest, NonexistentFile) { HasSubstr("file does not exist")))); } -TEST_F(JSONFormatTest, PathIsDirectory) { +TEST_F(TUSummaryTest, PathIsDirectory) { PathString DirName("test_directory.json"); auto ExpectedDirPath = makeDirectory(DirName); @@ -384,7 +261,7 @@ TEST_F(JSONFormatTest, PathIsDirectory) { HasSubstr("path is a directory, not a file")))); } -TEST_F(JSONFormatTest, NotJsonExtension) { +TEST_F(TUSummaryTest, NotJsonExtension) { PathString FileName("test.txt"); auto ExpectedFilePath = writeJSON("{}", FileName); @@ -399,7 +276,7 @@ TEST_F(JSONFormatTest, NotJsonExtension) { HasSubstr("file does not end with '.json' extension")))); } -TEST_F(JSONFormatTest, BrokenSymlink) { +TEST_F(TUSummaryTest, BrokenSymlink) { #ifdef _WIN32 GTEST_SKIP() << "Symlink model differs on Windows"; #endif @@ -416,7 +293,7 @@ TEST_F(JSONFormatTest, BrokenSymlink) { HasSubstr("failed to read file")))); } -TEST_F(JSONFormatTest, NoReadPermission) { +TEST_F(TUSummaryTest, NoReadPermission) { #ifdef _WIN32 GTEST_SKIP() << "Permission model differs on Windows"; #endif @@ -449,7 +326,7 @@ TEST_F(JSONFormatTest, NoReadPermission) { EXPECT_THAT_ERROR(std::move(RestoreError), Succeeded()); } -TEST_F(JSONFormatTest, InvalidSyntax) { +TEST_F(TUSummaryTest, InvalidSyntax) { auto Result = readTUSummaryFromString("{ invalid json }"); EXPECT_THAT_EXPECTED( @@ -457,7 +334,7 @@ TEST_F(JSONFormatTest, InvalidSyntax) { HasSubstr("Expected object key")))); } -TEST_F(JSONFormatTest, NotObject) { +TEST_F(TUSummaryTest, NotObject) { auto Result = readTUSummaryFromString("[]"); EXPECT_THAT_EXPECTED( @@ -470,7 +347,7 @@ TEST_F(JSONFormatTest, NotObject) { // JSONFormat::buildNamespaceKindFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, InvalidKind) { +TEST_F(TUSummaryTest, InvalidKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "invalid_kind", @@ -494,7 +371,7 @@ TEST_F(JSONFormatTest, InvalidKind) { // JSONFormat::buildNamespaceFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, MissingKind) { +TEST_F(TUSummaryTest, MissingKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "name": "test.cpp" @@ -512,7 +389,7 @@ TEST_F(JSONFormatTest, MissingKind) { HasSubstr("expected JSON string")))); } -TEST_F(JSONFormatTest, MissingName) { +TEST_F(TUSummaryTest, MissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit" @@ -534,7 +411,7 @@ TEST_F(JSONFormatTest, MissingName) { // JSONFormat::nestedBuildNamespaceFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, NamespaceElementNotObject) { +TEST_F(TUSummaryTest, NamespaceElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -565,7 +442,7 @@ TEST_F(JSONFormatTest, NamespaceElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, NamespaceElementMissingKind) { +TEST_F(TUSummaryTest, NamespaceElementMissingKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -601,7 +478,7 @@ TEST_F(JSONFormatTest, NamespaceElementMissingKind) { HasSubstr("expected JSON string")))); } -TEST_F(JSONFormatTest, NamespaceElementInvalidKind) { +TEST_F(TUSummaryTest, NamespaceElementInvalidKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -639,7 +516,7 @@ TEST_F(JSONFormatTest, NamespaceElementInvalidKind) { "invalid 'kind' BuildNamespaceKind value 'invalid_kind'")))); } -TEST_F(JSONFormatTest, NamespaceElementMissingName) { +TEST_F(TUSummaryTest, NamespaceElementMissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -679,7 +556,7 @@ TEST_F(JSONFormatTest, NamespaceElementMissingName) { // JSONFormat::entityNameFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, EntityNameMissingUSR) { +TEST_F(TUSummaryTest, EntityNameMissingUSR) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -707,7 +584,7 @@ TEST_F(JSONFormatTest, EntityNameMissingUSR) { HasSubstr("expected JSON string")))); } -TEST_F(JSONFormatTest, EntityNameMissingSuffix) { +TEST_F(TUSummaryTest, EntityNameMissingSuffix) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -735,7 +612,7 @@ TEST_F(JSONFormatTest, EntityNameMissingSuffix) { HasSubstr("expected JSON string")))); } -TEST_F(JSONFormatTest, EntityNameMissingNamespace) { +TEST_F(TUSummaryTest, EntityNameMissingNamespace) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -769,7 +646,7 @@ TEST_F(JSONFormatTest, EntityNameMissingNamespace) { // JSONFormat::entityIdTableEntryFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, IDTableEntryMissingID) { +TEST_F(TUSummaryTest, IDTableEntryMissingID) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -797,7 +674,7 @@ TEST_F(JSONFormatTest, IDTableEntryMissingID) { HasSubstr("expected JSON number (unsigned 64-bit integer)")))); } -TEST_F(JSONFormatTest, IDTableEntryMissingName) { +TEST_F(TUSummaryTest, IDTableEntryMissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -820,7 +697,7 @@ TEST_F(JSONFormatTest, IDTableEntryMissingName) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, IDTableEntryIDNotUInt64) { +TEST_F(TUSummaryTest, IDTableEntryIDNotUInt64) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -853,7 +730,7 @@ TEST_F(JSONFormatTest, IDTableEntryIDNotUInt64) { // JSONFormat::entityIdTableFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, IDTableNotArray) { +TEST_F(TUSummaryTest, IDTableNotArray) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -870,7 +747,7 @@ TEST_F(JSONFormatTest, IDTableNotArray) { HasSubstr("expected JSON array")))); } -TEST_F(JSONFormatTest, IDTableElementNotObject) { +TEST_F(TUSummaryTest, IDTableElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -889,7 +766,7 @@ TEST_F(JSONFormatTest, IDTableElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, DuplicateEntity) { +TEST_F(TUSummaryTest, DuplicateEntity) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -939,7 +816,7 @@ TEST_F(JSONFormatTest, DuplicateEntity) { // JSONFormat::entitySummaryFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, EntitySummaryNoFormatInfo) { +TEST_F(TUSummaryTest, EntitySummaryNoFormatInfo) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -977,7 +854,7 @@ TEST_F(JSONFormatTest, EntitySummaryNoFormatInfo) { // PairsEntitySummaryForJSONFormatTest Deserialization Error Tests // ============================================================================ -TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingPairsField) { +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingPairsField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1009,7 +886,7 @@ TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingPairsField) { HasSubstr("missing or invalid field 'pairs'")))); } -TEST_F(JSONFormatTest, +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidPairsFieldType) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { @@ -1044,7 +921,7 @@ TEST_F(JSONFormatTest, HasSubstr("missing or invalid field 'pairs'")))); } -TEST_F(JSONFormatTest, +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestPairsElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { @@ -1079,7 +956,7 @@ TEST_F(JSONFormatTest, HasSubstr("pairs element at index 0 is not a JSON object")))); } -TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingFirstField) { +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingFirstField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1117,7 +994,7 @@ TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingFirstField) { HasSubstr("missing or invalid 'first' field at index '0'")))); } -TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestInvalidFirstField) { +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidFirstField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1156,7 +1033,7 @@ TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestInvalidFirstField) { HasSubstr("missing or invalid 'first' field at index '0'")))); } -TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingSecondField) { +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingSecondField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1194,7 +1071,7 @@ TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestMissingSecondField) { HasSubstr("missing or invalid 'second' field at index '0'")))); } -TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestInvalidSecondField) { +TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidSecondField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1237,7 +1114,7 @@ TEST_F(JSONFormatTest, PairsEntitySummaryForJSONFormatTestInvalidSecondField) { // JSONFormat::entityDataMapEntryFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, EntityDataMissingEntityID) { +TEST_F(TUSummaryTest, EntityDataMissingEntityID) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1268,7 +1145,7 @@ TEST_F(JSONFormatTest, EntityDataMissingEntityID) { HasSubstr("expected JSON number (unsigned 64-bit integer)")))); } -TEST_F(JSONFormatTest, EntityDataMissingEntitySummary) { +TEST_F(TUSummaryTest, EntityDataMissingEntitySummary) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1299,7 +1176,7 @@ TEST_F(JSONFormatTest, EntityDataMissingEntitySummary) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, EntityIDNotUInt64) { +TEST_F(TUSummaryTest, EntityIDNotUInt64) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1335,7 +1212,7 @@ TEST_F(JSONFormatTest, EntityIDNotUInt64) { // JSONFormat::entityDataMapFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, EntityDataElementNotObject) { +TEST_F(TUSummaryTest, EntityDataElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1361,7 +1238,7 @@ TEST_F(JSONFormatTest, EntityDataElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, DuplicateEntityIdInDataMap) { +TEST_F(TUSummaryTest, DuplicateEntityIdInDataMap) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1413,7 +1290,7 @@ TEST_F(JSONFormatTest, DuplicateEntityIdInDataMap) { // JSONFormat::summaryDataMapEntryFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, DataEntryMissingSummaryName) { +TEST_F(TUSummaryTest, DataEntryMissingSummaryName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1437,7 +1314,7 @@ TEST_F(JSONFormatTest, DataEntryMissingSummaryName) { HasSubstr("expected JSON string")))); } -TEST_F(JSONFormatTest, DataEntryMissingData) { +TEST_F(TUSummaryTest, DataEntryMissingData) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1466,7 +1343,7 @@ TEST_F(JSONFormatTest, DataEntryMissingData) { // JSONFormat::summaryDataMapFromJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, DataNotArray) { +TEST_F(TUSummaryTest, DataNotArray) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1484,7 +1361,7 @@ TEST_F(JSONFormatTest, DataNotArray) { HasSubstr("expected JSON array")))); } -TEST_F(JSONFormatTest, DataElementNotObject) { +TEST_F(TUSummaryTest, DataElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1502,7 +1379,7 @@ TEST_F(JSONFormatTest, DataElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, DuplicateSummaryName) { +TEST_F(TUSummaryTest, DuplicateSummaryName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1534,7 +1411,7 @@ TEST_F(JSONFormatTest, DuplicateSummaryName) { // JSONFormat::readTUSummary() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, MissingTUNamespace) { +TEST_F(TUSummaryTest, MissingTUNamespace) { auto Result = readTUSummaryFromString(R"({ "id_table": [], "data": [] @@ -1548,7 +1425,7 @@ TEST_F(JSONFormatTest, MissingTUNamespace) { HasSubstr("expected JSON object")))); } -TEST_F(JSONFormatTest, MissingIDTable) { +TEST_F(TUSummaryTest, MissingIDTable) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1564,7 +1441,7 @@ TEST_F(JSONFormatTest, MissingIDTable) { HasSubstr("expected JSON array")))); } -TEST_F(JSONFormatTest, MissingData) { +TEST_F(TUSummaryTest, MissingData) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1585,7 +1462,7 @@ TEST_F(JSONFormatTest, MissingData) { // JSONFormat::writeJSON() Error Tests // ============================================================================ -TEST_F(JSONFormatTest, WriteFileAlreadyExists) { +TEST_F(TUSummaryTest, WriteFileAlreadyExists) { PathString FileName("existing.json"); auto ExpectedFilePath = writeJSON("{}", FileName); @@ -1604,7 +1481,7 @@ TEST_F(JSONFormatTest, WriteFileAlreadyExists) { HasSubstr("file already exists")))); } -TEST_F(JSONFormatTest, WriteParentDirectoryNotFound) { +TEST_F(TUSummaryTest, WriteParentDirectoryNotFound) { PathString FilePath = makePath("nonexistent-dir", "test.json"); TUSummary Summary( @@ -1619,7 +1496,7 @@ TEST_F(JSONFormatTest, WriteParentDirectoryNotFound) { HasSubstr("parent directory does not exist")))); } -TEST_F(JSONFormatTest, WriteNotJsonExtension) { +TEST_F(TUSummaryTest, WriteNotJsonExtension) { TUSummary Summary( BuildNamespace(BuildNamespaceKind::CompilationUnit, "test.cpp")); @@ -1633,7 +1510,7 @@ TEST_F(JSONFormatTest, WriteNotJsonExtension) { HasSubstr("file does not end with '.json' extension")))); } -TEST_F(JSONFormatTest, WriteStreamOpenFailure) { +TEST_F(TUSummaryTest, WriteStreamOpenFailure) { #ifdef _WIN32 GTEST_SKIP() << "Permission model differs on Windows"; #endif @@ -1668,7 +1545,7 @@ TEST_F(JSONFormatTest, WriteStreamOpenFailure) { // Round-Trip Tests - Serialization Verification // ============================================================================ -TEST_F(JSONFormatTest, Empty) { +TEST_F(TUSummaryTest, Empty) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1679,7 +1556,7 @@ TEST_F(JSONFormatTest, Empty) { })"); } -TEST_F(JSONFormatTest, LinkUnit) { +TEST_F(TUSummaryTest, LinkUnit) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "link_unit", @@ -1690,7 +1567,7 @@ TEST_F(JSONFormatTest, LinkUnit) { })"); } -TEST_F(JSONFormatTest, WithIDTable) { +TEST_F(TUSummaryTest, WithIDTable) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1732,7 +1609,7 @@ TEST_F(JSONFormatTest, WithIDTable) { })"); } -TEST_F(JSONFormatTest, WithEmptyDataEntry) { +TEST_F(TUSummaryTest, WithEmptyDataEntry) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1748,7 +1625,7 @@ TEST_F(JSONFormatTest, WithEmptyDataEntry) { })"); } -TEST_F(JSONFormatTest, RoundTripWithIDTable) { +TEST_F(TUSummaryTest, RoundTripWithIDTable) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1773,7 +1650,7 @@ TEST_F(JSONFormatTest, RoundTripWithIDTable) { })"); } -TEST_F(JSONFormatTest, RoundTripPairsEntitySummaryForJSONFormatTest) { +TEST_F(TUSummaryTest, RoundTripPairsEntitySummaryForJSONFormatTest) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", >From 292ce3810f795cfb5283fab96720ba040e6e433a Mon Sep 17 00:00:00 2001 From: Aviral Goel <[email protected]> Date: Fri, 20 Feb 2026 08:58:24 -0800 Subject: [PATCH 2/4] Fix formatting --- .../Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp index e953c7d883fdb..b1c89a899f3e3 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp @@ -1,5 +1,5 @@ //===- -//unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp +// unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp //===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. >From 3252d170f399feb0c9b5481ac775d725e2818c9f Mon Sep 17 00:00:00 2001 From: Aviral Goel <[email protected]> Date: Fri, 20 Feb 2026 10:37:09 -0800 Subject: [PATCH 3/4] Fix headers --- .../JSONFormatTest/JSONFormatTest.h | 3 +- .../JSONFormatTest/TUSummaryTest.cpp | 119 +++++++++--------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h index 4abcecb63b2d5..ae5e632a4952e 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h @@ -1,5 +1,4 @@ -//===- unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h -//-*- C++ -*-===// +//===- JSONFormatTest.h -----------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp index b1c89a899f3e3..0f3c05d4849ac 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp @@ -1,6 +1,4 @@ -//===- -// unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp -//===// +//===- TUSummaryTest.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -94,7 +92,7 @@ static llvm::Registry<JSONFormat::FormatInfo>::Add< "PairsEntitySummaryForJSONFormatTest", "Format info for PairsArrayEntitySummary"); -class TUSummaryTest : public JSONFormatTest { +class JSONFormatTUSummaryTest final : public JSONFormatTest { protected: llvm::Expected<TUSummary> readTUSummaryFromFile(StringRef FileName) const { PathString FilePath = makePath(FileName); @@ -239,7 +237,7 @@ class TUSummaryTest : public JSONFormatTest { // readJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, NonexistentFile) { +TEST_F(JSONFormatTUSummaryTest, NonexistentFile) { auto Result = readTUSummaryFromFile("nonexistent.json"); EXPECT_THAT_EXPECTED( @@ -247,7 +245,7 @@ TEST_F(TUSummaryTest, NonexistentFile) { HasSubstr("file does not exist")))); } -TEST_F(TUSummaryTest, PathIsDirectory) { +TEST_F(JSONFormatTUSummaryTest, PathIsDirectory) { PathString DirName("test_directory.json"); auto ExpectedDirPath = makeDirectory(DirName); @@ -261,7 +259,7 @@ TEST_F(TUSummaryTest, PathIsDirectory) { HasSubstr("path is a directory, not a file")))); } -TEST_F(TUSummaryTest, NotJsonExtension) { +TEST_F(JSONFormatTUSummaryTest, NotJsonExtension) { PathString FileName("test.txt"); auto ExpectedFilePath = writeJSON("{}", FileName); @@ -276,7 +274,7 @@ TEST_F(TUSummaryTest, NotJsonExtension) { HasSubstr("file does not end with '.json' extension")))); } -TEST_F(TUSummaryTest, BrokenSymlink) { +TEST_F(JSONFormatTUSummaryTest, BrokenSymlink) { #ifdef _WIN32 GTEST_SKIP() << "Symlink model differs on Windows"; #endif @@ -293,7 +291,7 @@ TEST_F(TUSummaryTest, BrokenSymlink) { HasSubstr("failed to read file")))); } -TEST_F(TUSummaryTest, NoReadPermission) { +TEST_F(JSONFormatTUSummaryTest, NoReadPermission) { #ifdef _WIN32 GTEST_SKIP() << "Permission model differs on Windows"; #endif @@ -326,7 +324,7 @@ TEST_F(TUSummaryTest, NoReadPermission) { EXPECT_THAT_ERROR(std::move(RestoreError), Succeeded()); } -TEST_F(TUSummaryTest, InvalidSyntax) { +TEST_F(JSONFormatTUSummaryTest, InvalidSyntax) { auto Result = readTUSummaryFromString("{ invalid json }"); EXPECT_THAT_EXPECTED( @@ -334,7 +332,7 @@ TEST_F(TUSummaryTest, InvalidSyntax) { HasSubstr("Expected object key")))); } -TEST_F(TUSummaryTest, NotObject) { +TEST_F(JSONFormatTUSummaryTest, NotObject) { auto Result = readTUSummaryFromString("[]"); EXPECT_THAT_EXPECTED( @@ -347,7 +345,7 @@ TEST_F(TUSummaryTest, NotObject) { // JSONFormat::buildNamespaceKindFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, InvalidKind) { +TEST_F(JSONFormatTUSummaryTest, InvalidKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "invalid_kind", @@ -371,7 +369,7 @@ TEST_F(TUSummaryTest, InvalidKind) { // JSONFormat::buildNamespaceFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, MissingKind) { +TEST_F(JSONFormatTUSummaryTest, MissingKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "name": "test.cpp" @@ -389,7 +387,7 @@ TEST_F(TUSummaryTest, MissingKind) { HasSubstr("expected JSON string")))); } -TEST_F(TUSummaryTest, MissingName) { +TEST_F(JSONFormatTUSummaryTest, MissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit" @@ -411,7 +409,7 @@ TEST_F(TUSummaryTest, MissingName) { // JSONFormat::nestedBuildNamespaceFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, NamespaceElementNotObject) { +TEST_F(JSONFormatTUSummaryTest, NamespaceElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -442,7 +440,7 @@ TEST_F(TUSummaryTest, NamespaceElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, NamespaceElementMissingKind) { +TEST_F(JSONFormatTUSummaryTest, NamespaceElementMissingKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -478,7 +476,7 @@ TEST_F(TUSummaryTest, NamespaceElementMissingKind) { HasSubstr("expected JSON string")))); } -TEST_F(TUSummaryTest, NamespaceElementInvalidKind) { +TEST_F(JSONFormatTUSummaryTest, NamespaceElementInvalidKind) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -516,7 +514,7 @@ TEST_F(TUSummaryTest, NamespaceElementInvalidKind) { "invalid 'kind' BuildNamespaceKind value 'invalid_kind'")))); } -TEST_F(TUSummaryTest, NamespaceElementMissingName) { +TEST_F(JSONFormatTUSummaryTest, NamespaceElementMissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -556,7 +554,7 @@ TEST_F(TUSummaryTest, NamespaceElementMissingName) { // JSONFormat::entityNameFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, EntityNameMissingUSR) { +TEST_F(JSONFormatTUSummaryTest, EntityNameMissingUSR) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -584,7 +582,7 @@ TEST_F(TUSummaryTest, EntityNameMissingUSR) { HasSubstr("expected JSON string")))); } -TEST_F(TUSummaryTest, EntityNameMissingSuffix) { +TEST_F(JSONFormatTUSummaryTest, EntityNameMissingSuffix) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -612,7 +610,7 @@ TEST_F(TUSummaryTest, EntityNameMissingSuffix) { HasSubstr("expected JSON string")))); } -TEST_F(TUSummaryTest, EntityNameMissingNamespace) { +TEST_F(JSONFormatTUSummaryTest, EntityNameMissingNamespace) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -646,7 +644,7 @@ TEST_F(TUSummaryTest, EntityNameMissingNamespace) { // JSONFormat::entityIdTableEntryFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, IDTableEntryMissingID) { +TEST_F(JSONFormatTUSummaryTest, IDTableEntryMissingID) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -674,7 +672,7 @@ TEST_F(TUSummaryTest, IDTableEntryMissingID) { HasSubstr("expected JSON number (unsigned 64-bit integer)")))); } -TEST_F(TUSummaryTest, IDTableEntryMissingName) { +TEST_F(JSONFormatTUSummaryTest, IDTableEntryMissingName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -697,7 +695,7 @@ TEST_F(TUSummaryTest, IDTableEntryMissingName) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, IDTableEntryIDNotUInt64) { +TEST_F(JSONFormatTUSummaryTest, IDTableEntryIDNotUInt64) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -730,7 +728,7 @@ TEST_F(TUSummaryTest, IDTableEntryIDNotUInt64) { // JSONFormat::entityIdTableFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, IDTableNotArray) { +TEST_F(JSONFormatTUSummaryTest, IDTableNotArray) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -747,7 +745,7 @@ TEST_F(TUSummaryTest, IDTableNotArray) { HasSubstr("expected JSON array")))); } -TEST_F(TUSummaryTest, IDTableElementNotObject) { +TEST_F(JSONFormatTUSummaryTest, IDTableElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -766,7 +764,7 @@ TEST_F(TUSummaryTest, IDTableElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, DuplicateEntity) { +TEST_F(JSONFormatTUSummaryTest, DuplicateEntity) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -816,7 +814,7 @@ TEST_F(TUSummaryTest, DuplicateEntity) { // JSONFormat::entitySummaryFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, EntitySummaryNoFormatInfo) { +TEST_F(JSONFormatTUSummaryTest, EntitySummaryNoFormatInfo) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -854,7 +852,8 @@ TEST_F(TUSummaryTest, EntitySummaryNoFormatInfo) { // PairsEntitySummaryForJSONFormatTest Deserialization Error Tests // ============================================================================ -TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingPairsField) { +TEST_F(JSONFormatTUSummaryTest, + PairsEntitySummaryForJSONFormatTestMissingPairsField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -886,7 +885,7 @@ TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingPairsField) { HasSubstr("missing or invalid field 'pairs'")))); } -TEST_F(TUSummaryTest, +TEST_F(JSONFormatTUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidPairsFieldType) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { @@ -921,7 +920,7 @@ TEST_F(TUSummaryTest, HasSubstr("missing or invalid field 'pairs'")))); } -TEST_F(TUSummaryTest, +TEST_F(JSONFormatTUSummaryTest, PairsEntitySummaryForJSONFormatTestPairsElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { @@ -956,7 +955,8 @@ TEST_F(TUSummaryTest, HasSubstr("pairs element at index 0 is not a JSON object")))); } -TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingFirstField) { +TEST_F(JSONFormatTUSummaryTest, + PairsEntitySummaryForJSONFormatTestMissingFirstField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -994,7 +994,8 @@ TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingFirstField) { HasSubstr("missing or invalid 'first' field at index '0'")))); } -TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidFirstField) { +TEST_F(JSONFormatTUSummaryTest, + PairsEntitySummaryForJSONFormatTestInvalidFirstField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1033,7 +1034,8 @@ TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidFirstField) { HasSubstr("missing or invalid 'first' field at index '0'")))); } -TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingSecondField) { +TEST_F(JSONFormatTUSummaryTest, + PairsEntitySummaryForJSONFormatTestMissingSecondField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1071,7 +1073,8 @@ TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestMissingSecondField) { HasSubstr("missing or invalid 'second' field at index '0'")))); } -TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidSecondField) { +TEST_F(JSONFormatTUSummaryTest, + PairsEntitySummaryForJSONFormatTestInvalidSecondField) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1114,7 +1117,7 @@ TEST_F(TUSummaryTest, PairsEntitySummaryForJSONFormatTestInvalidSecondField) { // JSONFormat::entityDataMapEntryFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, EntityDataMissingEntityID) { +TEST_F(JSONFormatTUSummaryTest, EntityDataMissingEntityID) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1145,7 +1148,7 @@ TEST_F(TUSummaryTest, EntityDataMissingEntityID) { HasSubstr("expected JSON number (unsigned 64-bit integer)")))); } -TEST_F(TUSummaryTest, EntityDataMissingEntitySummary) { +TEST_F(JSONFormatTUSummaryTest, EntityDataMissingEntitySummary) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1176,7 +1179,7 @@ TEST_F(TUSummaryTest, EntityDataMissingEntitySummary) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, EntityIDNotUInt64) { +TEST_F(JSONFormatTUSummaryTest, EntityIDNotUInt64) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1212,7 +1215,7 @@ TEST_F(TUSummaryTest, EntityIDNotUInt64) { // JSONFormat::entityDataMapFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, EntityDataElementNotObject) { +TEST_F(JSONFormatTUSummaryTest, EntityDataElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1238,7 +1241,7 @@ TEST_F(TUSummaryTest, EntityDataElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, DuplicateEntityIdInDataMap) { +TEST_F(JSONFormatTUSummaryTest, DuplicateEntityIdInDataMap) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1290,7 +1293,7 @@ TEST_F(TUSummaryTest, DuplicateEntityIdInDataMap) { // JSONFormat::summaryDataMapEntryFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, DataEntryMissingSummaryName) { +TEST_F(JSONFormatTUSummaryTest, DataEntryMissingSummaryName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1314,7 +1317,7 @@ TEST_F(TUSummaryTest, DataEntryMissingSummaryName) { HasSubstr("expected JSON string")))); } -TEST_F(TUSummaryTest, DataEntryMissingData) { +TEST_F(JSONFormatTUSummaryTest, DataEntryMissingData) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1343,7 +1346,7 @@ TEST_F(TUSummaryTest, DataEntryMissingData) { // JSONFormat::summaryDataMapFromJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, DataNotArray) { +TEST_F(JSONFormatTUSummaryTest, DataNotArray) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1361,7 +1364,7 @@ TEST_F(TUSummaryTest, DataNotArray) { HasSubstr("expected JSON array")))); } -TEST_F(TUSummaryTest, DataElementNotObject) { +TEST_F(JSONFormatTUSummaryTest, DataElementNotObject) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1379,7 +1382,7 @@ TEST_F(TUSummaryTest, DataElementNotObject) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, DuplicateSummaryName) { +TEST_F(JSONFormatTUSummaryTest, DuplicateSummaryName) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1411,7 +1414,7 @@ TEST_F(TUSummaryTest, DuplicateSummaryName) { // JSONFormat::readTUSummary() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, MissingTUNamespace) { +TEST_F(JSONFormatTUSummaryTest, MissingTUNamespace) { auto Result = readTUSummaryFromString(R"({ "id_table": [], "data": [] @@ -1425,7 +1428,7 @@ TEST_F(TUSummaryTest, MissingTUNamespace) { HasSubstr("expected JSON object")))); } -TEST_F(TUSummaryTest, MissingIDTable) { +TEST_F(JSONFormatTUSummaryTest, MissingIDTable) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1441,7 +1444,7 @@ TEST_F(TUSummaryTest, MissingIDTable) { HasSubstr("expected JSON array")))); } -TEST_F(TUSummaryTest, MissingData) { +TEST_F(JSONFormatTUSummaryTest, MissingData) { auto Result = readTUSummaryFromString(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1462,7 +1465,7 @@ TEST_F(TUSummaryTest, MissingData) { // JSONFormat::writeJSON() Error Tests // ============================================================================ -TEST_F(TUSummaryTest, WriteFileAlreadyExists) { +TEST_F(JSONFormatTUSummaryTest, WriteFileAlreadyExists) { PathString FileName("existing.json"); auto ExpectedFilePath = writeJSON("{}", FileName); @@ -1481,7 +1484,7 @@ TEST_F(TUSummaryTest, WriteFileAlreadyExists) { HasSubstr("file already exists")))); } -TEST_F(TUSummaryTest, WriteParentDirectoryNotFound) { +TEST_F(JSONFormatTUSummaryTest, WriteParentDirectoryNotFound) { PathString FilePath = makePath("nonexistent-dir", "test.json"); TUSummary Summary( @@ -1496,7 +1499,7 @@ TEST_F(TUSummaryTest, WriteParentDirectoryNotFound) { HasSubstr("parent directory does not exist")))); } -TEST_F(TUSummaryTest, WriteNotJsonExtension) { +TEST_F(JSONFormatTUSummaryTest, WriteNotJsonExtension) { TUSummary Summary( BuildNamespace(BuildNamespaceKind::CompilationUnit, "test.cpp")); @@ -1510,7 +1513,7 @@ TEST_F(TUSummaryTest, WriteNotJsonExtension) { HasSubstr("file does not end with '.json' extension")))); } -TEST_F(TUSummaryTest, WriteStreamOpenFailure) { +TEST_F(JSONFormatTUSummaryTest, WriteStreamOpenFailure) { #ifdef _WIN32 GTEST_SKIP() << "Permission model differs on Windows"; #endif @@ -1545,7 +1548,7 @@ TEST_F(TUSummaryTest, WriteStreamOpenFailure) { // Round-Trip Tests - Serialization Verification // ============================================================================ -TEST_F(TUSummaryTest, Empty) { +TEST_F(JSONFormatTUSummaryTest, Empty) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1556,7 +1559,7 @@ TEST_F(TUSummaryTest, Empty) { })"); } -TEST_F(TUSummaryTest, LinkUnit) { +TEST_F(JSONFormatTUSummaryTest, LinkUnit) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "link_unit", @@ -1567,7 +1570,7 @@ TEST_F(TUSummaryTest, LinkUnit) { })"); } -TEST_F(TUSummaryTest, WithIDTable) { +TEST_F(JSONFormatTUSummaryTest, WithIDTable) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1609,7 +1612,7 @@ TEST_F(TUSummaryTest, WithIDTable) { })"); } -TEST_F(TUSummaryTest, WithEmptyDataEntry) { +TEST_F(JSONFormatTUSummaryTest, WithEmptyDataEntry) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1625,7 +1628,7 @@ TEST_F(TUSummaryTest, WithEmptyDataEntry) { })"); } -TEST_F(TUSummaryTest, RoundTripWithIDTable) { +TEST_F(JSONFormatTUSummaryTest, RoundTripWithIDTable) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", @@ -1650,7 +1653,7 @@ TEST_F(TUSummaryTest, RoundTripWithIDTable) { })"); } -TEST_F(TUSummaryTest, RoundTripPairsEntitySummaryForJSONFormatTest) { +TEST_F(JSONFormatTUSummaryTest, RoundTripPairsEntitySummaryForJSONFormatTest) { readWriteCompareTUSummary(R"({ "tu_namespace": { "kind": "compilation_unit", >From 11a61fdc2a842554cceeab1b75f848f45e38a81f Mon Sep 17 00:00:00 2001 From: Aviral Goel <[email protected]> Date: Fri, 20 Feb 2026 11:02:34 -0800 Subject: [PATCH 4/4] Fixes --- .../JSONFormatTest/JSONFormatTest.h | 93 +++++++++---------- .../JSONFormatTest/TUSummaryTest.cpp | 10 +- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h index ae5e632a4952e..f0d733d874afa 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/JSONFormatTest.h @@ -10,27 +10,17 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H -#define LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H +#ifndef LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_JSONFORMATTEST_H +#define LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_JSONFORMATTEST_H -#include "clang/Analysis/Scalable/Serialization/JSONFormat.h" -#include "clang/Analysis/Scalable/TUSummary/TUSummary.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Error.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/JSON.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Testing/Support/Error.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" -#include <memory> -#include <string> - -using namespace clang::ssaf; -using namespace llvm; -using ::testing::AllOf; -using ::testing::HasSubstr; // ============================================================================ // Test Fixture @@ -38,110 +28,117 @@ using ::testing::HasSubstr; class JSONFormatTest : public ::testing::Test { public: - using PathString = SmallString<128>; + using PathString = llvm::SmallString<128>; protected: - SmallString<128> TestDir; + llvm::SmallString<128> TestDir; void SetUp() override { std::error_code EC = - sys::fs::createUniqueDirectory("json-format-test", TestDir); + llvm::sys::fs::createUniqueDirectory("json-format-test", TestDir); ASSERT_FALSE(EC) << "Failed to create temp directory: " << EC.message(); } - void TearDown() override { sys::fs::remove_directories(TestDir); } + void TearDown() override { llvm::sys::fs::remove_directories(TestDir); } - PathString makePath(StringRef FileOrDirectoryName) const { + PathString makePath(llvm::StringRef FileOrDirectoryName) const { PathString FullPath = TestDir; - sys::path::append(FullPath, FileOrDirectoryName); + llvm::sys::path::append(FullPath, FileOrDirectoryName); return FullPath; } - PathString makePath(StringRef Dir, StringRef FileName) const { + PathString makePath(llvm::StringRef Dir, llvm::StringRef FileName) const { PathString FullPath = TestDir; - sys::path::append(FullPath, Dir, FileName); + llvm::sys::path::append(FullPath, Dir, FileName); return FullPath; } - Expected<PathString> makeDirectory(StringRef DirectoryName) const { + llvm::Expected<PathString> + makeDirectory(llvm::StringRef DirectoryName) const { PathString DirPath = makePath(DirectoryName); - std::error_code EC = sys::fs::create_directory(DirPath); + std::error_code EC = llvm::sys::fs::create_directory(DirPath); if (EC) { - return createStringError(EC, "Failed to create directory '%s': %s", - DirPath.c_str(), EC.message().c_str()); + return llvm::createStringError(EC, "Failed to create directory '%s': %s", + DirPath.c_str(), EC.message().c_str()); } return DirPath; } - Expected<PathString> makeSymlink(StringRef TargetFileName, - StringRef SymlinkFileName) const { + llvm::Expected<PathString> + makeSymlink(llvm::StringRef TargetFileName, + llvm::StringRef SymlinkFileName) const { PathString TargetPath = makePath(TargetFileName); PathString SymlinkPath = makePath(SymlinkFileName); - std::error_code EC = sys::fs::create_link(TargetPath, SymlinkPath); + std::error_code EC = llvm::sys::fs::create_link(TargetPath, SymlinkPath); if (EC) { - return createStringError(EC, "Failed to create symlink '%s' -> '%s': %s", - SymlinkPath.c_str(), TargetPath.c_str(), - EC.message().c_str()); + return llvm::createStringError( + EC, "Failed to create symlink '%s' -> '%s': %s", SymlinkPath.c_str(), + TargetPath.c_str(), EC.message().c_str()); } return SymlinkPath; } - llvm::Error setPermission(StringRef FileName, - const sys::fs::perms Perms) const { + llvm::Error setPermission(llvm::StringRef FileName, + llvm::sys::fs::perms Perms) const { PathString Path = makePath(FileName); - std::error_code EC = sys::fs::setPermissions(Path, Perms); + std::error_code EC = llvm::sys::fs::setPermissions(Path, Perms); if (EC) { - return createStringError(EC, "Failed to set permissions on '%s': %s", - Path.c_str(), EC.message().c_str()); + return llvm::createStringError(EC, + "Failed to set permissions on '%s': %s", + Path.c_str(), EC.message().c_str()); } return llvm::Error::success(); } - Expected<json::Value> readJSONFromFile(StringRef FileName) const { + llvm::Expected<llvm::json::Value> + readJSONFromFile(llvm::StringRef FileName) const { PathString FilePath = makePath(FileName); - auto BufferOrError = MemoryBuffer::getFile(FilePath); + auto BufferOrError = llvm::MemoryBuffer::getFile(FilePath); if (!BufferOrError) { - return createStringError(BufferOrError.getError(), - "Failed to read file: %s", FilePath.c_str()); + return llvm::createStringError(BufferOrError.getError(), + "Failed to read file: %s", + FilePath.c_str()); } - Expected<json::Value> ExpectedValue = - json::parse(BufferOrError.get()->getBuffer()); + llvm::Expected<llvm::json::Value> ExpectedValue = + llvm::json::parse(BufferOrError.get()->getBuffer()); if (!ExpectedValue) return ExpectedValue.takeError(); return *ExpectedValue; } - Expected<PathString> writeJSON(StringRef JSON, StringRef FileName) const { + llvm::Expected<PathString> writeJSON(llvm::StringRef JSON, + llvm::StringRef FileName) const { PathString FilePath = makePath(FileName); std::error_code EC; llvm::raw_fd_ostream OS(FilePath, EC); if (EC) { - return createStringError(EC, "Failed to create file '%s': %s", - FilePath.c_str(), EC.message().c_str()); + return llvm::createStringError(EC, "Failed to create file '%s': %s", + FilePath.c_str(), EC.message().c_str()); } OS << JSON; OS.close(); if (OS.has_error()) { - return createStringError(OS.error(), "Failed to write to file '%s': %s", - FilePath.c_str(), OS.error().message().c_str()); + return llvm::createStringError( + OS.error(), "Failed to write to file '%s': %s", FilePath.c_str(), + OS.error().message().c_str()); } return FilePath; } }; -#endif // LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_H +#endif // LLVM_CLANG_UNITTESTS_ANALYSIS_SCALABLE_SERIALIZATION_JSONFORMATTEST_JSONFORMATTEST_H \ No newline at end of file diff --git a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp index 0f3c05d4849ac..2cdbec9675662 100644 --- a/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp +++ b/clang/unittests/Analysis/Scalable/Serialization/JSONFormatTest/TUSummaryTest.cpp @@ -11,11 +11,19 @@ // //===----------------------------------------------------------------------===// +#include "clang/Analysis/Scalable/TUSummary/TUSummary.h" #include "JSONFormatTest.h" +#include "clang/Analysis/Scalable/Serialization/JSONFormat.h" #include "llvm/Support/Registry.h" +#include "llvm/Testing/Support/Error.h" +#include "gmock/gmock.h" #include <memory> #include <vector> +using namespace clang::ssaf; +using namespace llvm; +using ::testing::AllOf; +using ::testing::HasSubstr; namespace { // ============================================================================ @@ -92,7 +100,7 @@ static llvm::Registry<JSONFormat::FormatInfo>::Add< "PairsEntitySummaryForJSONFormatTest", "Format info for PairsArrayEntitySummary"); -class JSONFormatTUSummaryTest final : public JSONFormatTest { +class JSONFormatTUSummaryTest : public JSONFormatTest { protected: llvm::Expected<TUSummary> readTUSummaryFromFile(StringRef FileName) const { PathString FilePath = makePath(FileName); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
