From b54ef6a2a4c84293f64f90ea344b129eabbb0cd1 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 14 Sep 2017 10:06:52 +0000 Subject: [refactor] add clang-refactor tool with initial testing support and local-rename action This commit introduces the clang-refactor tool alongside the local-rename action which uses the existing renaming engine used by clang-rename. The tool doesn't actually perform the source transformations yet, it just provides testing support. This commit also moves only one test from clang-rename over to test/Refactor. I will continue to move the other tests throughout development of clang-refactor. The following options are supported by clang-refactor: -v: use verbose output -selection: The source range that corresponds to the portion of the source that's selected (currently only special command test: is supported). Please note that a follow-up commit will migrate clang-refactor to libTooling's common option parser, so clang-refactor will be able to use the common interface with compilation database and options like -p, -extra-arg, etc. The testing support provided by clang-refactor is described below: When -selection=test: is given, clang-refactor will parse the selection commands from that file. The selection commands are grouped and the specified refactoring action invoked by the tool. Each command in a group is expected to produce an identical result. The precise syntax for the selection commands is described in a comment in TestSupport.h. Differential Revision: https://reviews.llvm.org/D36574 llvm-svn: 313244 --- .../unittests/Tooling/RefactoringActionRulesTest.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'clang/unittests/Tooling/RefactoringActionRulesTest.cpp') diff --git a/clang/unittests/Tooling/RefactoringActionRulesTest.cpp b/clang/unittests/Tooling/RefactoringActionRulesTest.cpp index 62c751ac12c..cf91b5fc8f4 100644 --- a/clang/unittests/Tooling/RefactoringActionRulesTest.cpp +++ b/clang/unittests/Tooling/RefactoringActionRulesTest.cpp @@ -57,7 +57,8 @@ createReplacements(const std::unique_ptr &Rule, TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) { auto ReplaceAWithB = - [](std::pair Selection) + [](const RefactoringRuleContext &, + std::pair Selection) -> Expected { const SourceManager &SM = Selection.first.getSources(); SourceLocation Loc = Selection.first.getRange().getBegin().getLocWithOffset( @@ -71,7 +72,8 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) { class SelectionRequirement : public selection::Requirement { public: std::pair - evaluateSelection(selection::SourceSelectionRange Selection) const { + evaluateSelection(const RefactoringRuleContext &, + selection::SourceSelectionRange Selection) const { return std::make_pair(Selection, 20); } }; @@ -127,8 +129,10 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) { } TEST_F(RefactoringActionRulesTest, ReturnError) { - Expected (*Func)(selection::SourceSelectionRange) = - [](selection::SourceSelectionRange) -> Expected { + Expected (*Func)(const RefactoringRuleContext &, + selection::SourceSelectionRange) = + [](const RefactoringRuleContext &, + selection::SourceSelectionRange) -> Expected { return llvm::make_error( "Error", llvm::make_error_code(llvm::errc::invalid_argument)); }; @@ -155,13 +159,14 @@ TEST_F(RefactoringActionRulesTest, ReturnInitiationDiagnostic) { class SelectionRequirement : public selection::Requirement { public: Expected> - evaluateSelection(selection::SourceSelectionRange Selection) const { + evaluateSelection(const RefactoringRuleContext &, + selection::SourceSelectionRange Selection) const { return llvm::make_error( "bad selection", llvm::make_error_code(llvm::errc::invalid_argument)); } }; auto Rule = createRefactoringRule( - [](int) -> Expected { + [](const RefactoringRuleContext &, int) -> Expected { llvm::report_fatal_error("Should not run!"); }, requiredSelection(SelectionRequirement())); @@ -201,7 +206,8 @@ Optional findOccurrences(RefactoringActionRule &Rule, TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) { auto Rule = createRefactoringRule( - [](selection::SourceSelectionRange Selection) + [](const RefactoringRuleContext &, + selection::SourceSelectionRange Selection) -> Expected { SymbolOccurrences Occurrences; Occurrences.push_back(SymbolOccurrence( -- cgit v1.2.3