llvm-project/clang-tools-extra/unittests/clang-modernize/UniqueHeaderNameTest.cpp

62 lines
2.1 KiB
C++
Raw Normal View History

//===- unittests/clang-modernize/UniqueHeaderNameTest.cpp -----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Test for the generateReplacementsFileName() in FileOverrides.h
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "Core/ReplacementHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
#include <system_error>
TEST(UniqueHeaderName, testUniqueHeaderName) {
using namespace llvm::sys::path;
llvm::SmallString<32> TmpDir;
system_temp_directory(true, TmpDir);
llvm::SmallString<128> SourceFile(TmpDir);
append(SourceFile, "project/lib/feature.cpp");
native(SourceFile.str().str(), SourceFile);
llvm::SmallString<128> DestDir(TmpDir);
append(DestDir, "replacements");
cpp11-migrate: Refactor for driver model of operation Re-commit of r189691 and r189689 now with a proper autoconf fix. Massive simplification of how replacements and file overrides are handled by the migrator: * Sources and headers are all treated the same. * All replacements for a given translation unit are stored in the same TranslationUnitReplacements structure. * Change tracking is updated only from main file; no need for propagating "is tracking" flag around. * Transform base class no longer responsible for applying replacements. They are simply stored and main() looks after deduplication and application. * Renamed -yaml-only to -serialize-replacements. Same restrictions apply: Can only request one transform. New restriction: formatting cannot also be turned on since it's basically a transform. * If -serialize-replacements is requested, changes to files will not be applied on disk. * Changed behaviour of function generating names for serialized replacements: Only the main source file goes into the name of the file since a file may contain changes for multiple different files. * Updated HeaderReplacements LIT test for new serialization behaviour. * Replaced old test that ensures replacements are not serialized if -serialize-replacements is not provided. New version ensures changes are made directly to all files in the translation unit. * Updated unit tests. * Due to major simplification of structures in FileOverrides.h, the FileOverridesTest is quite a bit simpler now. llvm-svn: 189798
2013-09-03 21:16:02 +08:00
llvm::SmallString<128> FullActualPath;
llvm::SmallString<128> Error;
bool Result = ReplacementHandling::generateReplacementsFileName(
DestDir, SourceFile, FullActualPath, Error);
ASSERT_TRUE(Result);
EXPECT_TRUE(Error.empty());
// We need to check the directory name and filename separately since on
// Windows, the path separator is '\' which is a regex escape character.
cpp11-migrate: Refactor for driver model of operation Re-commit of r189691 and r189689 now with a proper autoconf fix. Massive simplification of how replacements and file overrides are handled by the migrator: * Sources and headers are all treated the same. * All replacements for a given translation unit are stored in the same TranslationUnitReplacements structure. * Change tracking is updated only from main file; no need for propagating "is tracking" flag around. * Transform base class no longer responsible for applying replacements. They are simply stored and main() looks after deduplication and application. * Renamed -yaml-only to -serialize-replacements. Same restrictions apply: Can only request one transform. New restriction: formatting cannot also be turned on since it's basically a transform. * If -serialize-replacements is requested, changes to files will not be applied on disk. * Changed behaviour of function generating names for serialized replacements: Only the main source file goes into the name of the file since a file may contain changes for multiple different files. * Updated HeaderReplacements LIT test for new serialization behaviour. * Replaced old test that ensures replacements are not serialized if -serialize-replacements is not provided. New version ensures changes are made directly to all files in the translation unit. * Updated unit tests. * Due to major simplification of structures in FileOverrides.h, the FileOverridesTest is quite a bit simpler now. llvm-svn: 189798
2013-09-03 21:16:02 +08:00
llvm::SmallString<128> ExpectedPath =
llvm::sys::path::parent_path(SourceFile);
llvm::SmallString<128> ActualPath =
llvm::sys::path::parent_path(FullActualPath);
llvm::SmallString<128> ActualName =
llvm::sys::path::filename(FullActualPath);
EXPECT_STREQ(DestDir.c_str(), ActualPath.c_str());
cpp11-migrate: Refactor for driver model of operation Re-commit of r189691 and r189689 now with a proper autoconf fix. Massive simplification of how replacements and file overrides are handled by the migrator: * Sources and headers are all treated the same. * All replacements for a given translation unit are stored in the same TranslationUnitReplacements structure. * Change tracking is updated only from main file; no need for propagating "is tracking" flag around. * Transform base class no longer responsible for applying replacements. They are simply stored and main() looks after deduplication and application. * Renamed -yaml-only to -serialize-replacements. Same restrictions apply: Can only request one transform. New restriction: formatting cannot also be turned on since it's basically a transform. * If -serialize-replacements is requested, changes to files will not be applied on disk. * Changed behaviour of function generating names for serialized replacements: Only the main source file goes into the name of the file since a file may contain changes for multiple different files. * Updated HeaderReplacements LIT test for new serialization behaviour. * Replaced old test that ensures replacements are not serialized if -serialize-replacements is not provided. New version ensures changes are made directly to all files in the translation unit. * Updated unit tests. * Due to major simplification of structures in FileOverrides.h, the FileOverridesTest is quite a bit simpler now. llvm-svn: 189798
2013-09-03 21:16:02 +08:00
llvm::StringRef ExpectedName =
"^feature.cpp_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_[0-9a-f]{2}_["
"0-9a-f]{2}_[0-9a-f]{2}.yaml$";
llvm::Regex R(ExpectedName);
cpp11-migrate: Refactor for driver model of operation Re-commit of r189691 and r189689 now with a proper autoconf fix. Massive simplification of how replacements and file overrides are handled by the migrator: * Sources and headers are all treated the same. * All replacements for a given translation unit are stored in the same TranslationUnitReplacements structure. * Change tracking is updated only from main file; no need for propagating "is tracking" flag around. * Transform base class no longer responsible for applying replacements. They are simply stored and main() looks after deduplication and application. * Renamed -yaml-only to -serialize-replacements. Same restrictions apply: Can only request one transform. New restriction: formatting cannot also be turned on since it's basically a transform. * If -serialize-replacements is requested, changes to files will not be applied on disk. * Changed behaviour of function generating names for serialized replacements: Only the main source file goes into the name of the file since a file may contain changes for multiple different files. * Updated HeaderReplacements LIT test for new serialization behaviour. * Replaced old test that ensures replacements are not serialized if -serialize-replacements is not provided. New version ensures changes are made directly to all files in the translation unit. * Updated unit tests. * Due to major simplification of structures in FileOverrides.h, the FileOverridesTest is quite a bit simpler now. llvm-svn: 189798
2013-09-03 21:16:02 +08:00
ASSERT_TRUE(R.match(ActualName))
<< "ExpectedName: " << ExpectedName.data()
<< "\nActualName: " << ActualName.c_str();
ASSERT_TRUE(Error.empty()) << "Error: " << Error.c_str();
}