@@ -24,10 +24,6 @@ namespace clang {
24
24
namespace move {
25
25
namespace {
26
26
27
- const char TestHeaderName[] = " foo.h" ;
28
-
29
- const char TestCCName[] = " foo.cc" ;
30
-
31
27
const char TestHeader[] = " namespace a {\n "
32
28
" class C1; // test\n "
33
29
" template <typename T> class C2;\n "
@@ -196,16 +192,25 @@ const char ExpectedNewCC[] = "namespace a {\n"
196
192
" } // namespace b\n "
197
193
" } // namespace a\n " ;
198
194
195
+ #ifdef _WIN32
196
+ const char WorkingDir[] = " C:\\ test" ;
197
+ #else
198
+ const char WorkingDir[] = " /test" ;
199
+ #endif
200
+
201
+ const char TestHeaderName[] = " foo.h" ;
202
+ const char TestCCName[] = " foo.cc" ;
203
+
199
204
std::map<std::string, std::string>
200
205
runClangMoveOnCode (const move::MoveDefinitionSpec &Spec,
201
206
const char *const Header = TestHeader,
202
207
const char *const CC = TestCC,
203
208
DeclarationReporter *const Reporter = nullptr ) {
204
209
clang::RewriterTestContext Context;
205
210
211
+ Context.InMemoryFileSystem ->setCurrentWorkingDirectory (WorkingDir);
212
+
206
213
std::map<llvm::StringRef, clang::FileID> FileToFileID;
207
- std::vector<std::pair<std::string, std::string>> FileToSourceText = {
208
- {TestHeaderName, Header}, {TestCCName, CC}};
209
214
210
215
auto CreateFiles = [&Context, &FileToFileID](llvm::StringRef Name,
211
216
llvm::StringRef Code) {
@@ -215,25 +220,21 @@ runClangMoveOnCode(const move::MoveDefinitionSpec &Spec,
215
220
};
216
221
CreateFiles (Spec.NewCC , " " );
217
222
CreateFiles (Spec.NewHeader , " " );
218
- CreateFiles (Spec. OldHeader , Header);
219
- CreateFiles (Spec. OldCC , CC);
223
+ CreateFiles (TestHeaderName , Header);
224
+ CreateFiles (TestCCName , CC);
220
225
221
226
std::map<std::string, tooling::Replacements> FileToReplacements;
222
- llvm::SmallString<128 > InitialDirectory;
223
- std::error_code EC = llvm::sys::fs::current_path (InitialDirectory);
224
- assert (!EC);
225
- (void )EC;
226
- ClangMoveContext MoveContext = {Spec, FileToReplacements,
227
- InitialDirectory.str (), " LLVM" ,
227
+ ClangMoveContext MoveContext = {Spec, FileToReplacements, WorkingDir, " LLVM" ,
228
228
Reporter != nullptr };
229
229
230
230
auto Factory = llvm::make_unique<clang::move::ClangMoveActionFactory>(
231
231
&MoveContext, Reporter);
232
232
233
+ // std::string IncludeArg = Twine("-I" + WorkingDir;
233
234
tooling::runToolOnCodeWithArgs (
234
- Factory->create (), CC, { " -std=c++11 " , " -fparse-all-comments " } ,
235
- TestCCName, " clang-move" , std::make_shared<PCHContainerOperations>() ,
236
- FileToSourceText );
235
+ Factory->create (), CC, Context. InMemoryFileSystem ,
236
+ { " -std=c++11 " , " -fparse-all-comments " , " -I. " }, TestCCName, " clang-move" ,
237
+ std::make_shared<PCHContainerOperations>() );
237
238
formatAndApplyAllReplacements (FileToReplacements, Context.Rewrite , " llvm" );
238
239
// The Key is file name, value is the new code after moving the class.
239
240
std::map<std::string, std::string> Results;
0 commit comments