2012/5/23 Manuel Klimek <[email protected]>: > Author: klimek > Date: Tue May 22 12:01:35 2012 > New Revision: 157260 > > URL: http://llvm.org/viewvc/llvm-project?rev=157260&view=rev > Log: > Adds a method overwriteChangedFiles to the Rewriter. This is implemented by > first writing the changed files to a temporary location and then overwriting > the original files atomically. > > Also adds a RewriterTestContext to aid unit testing rewrting logic in general. > > > Added: > cfe/trunk/unittests/Tooling/RewriterTest.cpp (with props) > cfe/trunk/unittests/Tooling/RewriterTestContext.h (with props) > Modified: > cfe/trunk/include/clang/Rewrite/Rewriter.h > cfe/trunk/lib/Rewrite/Rewriter.cpp > cfe/trunk/unittests/CMakeLists.txt
> Added: cfe/trunk/unittests/Tooling/RewriterTestContext.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RewriterTestContext.h?rev=157260&view=auto > ============================================================================== > --- cfe/trunk/unittests/Tooling/RewriterTestContext.h (added) > +++ cfe/trunk/unittests/Tooling/RewriterTestContext.h Tue May 22 12:01:35 2012 > @@ -0,0 +1,120 @@ > +//===--- RewriterTestContext.h ----------------------------------*- C++ > -*-===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===----------------------------------------------------------------------===// > +// > +// This file defines a utility class for Rewriter related tests. > +// > +//===----------------------------------------------------------------------===// > + > +#ifndef LLVM_CLANG_REWRITER_TEST_CONTEXT_H > +#define LLVM_CLANG_REWRITER_TEST_CONTEXT_H > + > +#include "clang/Basic/Diagnostic.h" > +#include "clang/Basic/FileManager.h" > +#include "clang/Basic/LangOptions.h" > +#include "clang/Basic/SourceManager.h" > +#include "clang/Frontend/DiagnosticOptions.h" > +#include "clang/Frontend/TextDiagnosticPrinter.h" > +#include "clang/Rewrite/Rewriter.h" > +#include "llvm/Support/Path.h" > +#include "llvm/Support/raw_ostream.h" > + > +namespace clang { > + > +/// \brief A class that sets up a ready to use Rewriter. > +/// > +/// Useful in unit tests that need a Rewriter. Creates all dependencies > +/// of a Rewriter with default values for testing and provides convenience > +/// methods, which help with writing tests that change files. > +class RewriterTestContext { > + public: > + RewriterTestContext() > + : Diagnostics(llvm::IntrusiveRefCntPtr<DiagnosticIDs>()), > + DiagnosticPrinter(llvm::outs(), DiagnosticOptions()), > + Files((FileSystemOptions())), > + Sources(Diagnostics, Files), > + Rewrite(Sources, Options) { > + Diagnostics.setClient(&DiagnosticPrinter, false); > + } > + > + ~RewriterTestContext() { > + if (TemporaryDirectory.isValid()) { > + std::string ErrorInfo; > + TemporaryDirectory.eraseFromDisk(true, &ErrorInfo); > + assert(ErrorInfo.empty()); > + } > + } Don't try to remove the TemporaryDirectory given by PathV1. Fixed in r157530. See also r157529. ...Takumi _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
