diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-09-14 10:06:52 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-09-14 10:06:52 +0000 |
commit | b54ef6a2a4c84293f64f90ea344b129eabbb0cd1 (patch) | |
tree | beea03e3a80eaf8bc338ebb66b247f3363562975 /clang/test | |
parent | d7b3add7c4a25a558794bf1c1ca30f865b8c6dd7 (diff) | |
download | bcm5719-llvm-b54ef6a2a4c84293f64f90ea344b129eabbb0cd1.tar.gz bcm5719-llvm-b54ef6a2a4c84293f64f90ea344b129eabbb0cd1.zip |
[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:<file> 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:<file> 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
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/test/Refactor/LocalRename/Field.cpp | 9 | ||||
-rw-r--r-- | clang/test/Refactor/tool-common-options.c | 6 | ||||
-rw-r--r-- | clang/test/Refactor/tool-test-support.c | 41 | ||||
-rw-r--r-- | clang/test/clang-rename/Field.cpp | 15 |
5 files changed, 57 insertions, 15 deletions
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 084f405fee5..a3a70282a7d 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -48,6 +48,7 @@ list(APPEND CLANG_TEST_DEPS clang-offload-bundler clang-import-test clang-rename + clang-refactor clang-diff ) diff --git a/clang/test/Refactor/LocalRename/Field.cpp b/clang/test/Refactor/LocalRename/Field.cpp new file mode 100644 index 00000000000..db8ada5fcc0 --- /dev/null +++ b/clang/test/Refactor/LocalRename/Field.cpp @@ -0,0 +1,9 @@ +// RUN: clang-refactor local-rename -selection=test:%s -no-dbs %s | FileCheck %s + +class Baz { + int /*range=*/Foo; // CHECK: int /*range=*/Bar; +public: + Baz(); +}; + +Baz::Baz() : /*range=*/Foo(0) {} // CHECK: Baz::Baz() : /*range=*/Bar(0) {}; diff --git a/clang/test/Refactor/tool-common-options.c b/clang/test/Refactor/tool-common-options.c new file mode 100644 index 00000000000..e20c290ae77 --- /dev/null +++ b/clang/test/Refactor/tool-common-options.c @@ -0,0 +1,6 @@ +// RUN: not clang-refactor 2>&1 | FileCheck --check-prefix=MISSING_ACTION %s +// MISSING_ACTION: error: no refactoring action given +// MISSING_ACTION-NEXT: note: the following actions are supported: + +// RUN: not clang-refactor local-rename -no-dbs 2>&1 | FileCheck --check-prefix=MISSING_SOURCES %s +// MISSING_SOURCES: error: must provide paths to the source files when '-no-dbs' is used diff --git a/clang/test/Refactor/tool-test-support.c b/clang/test/Refactor/tool-test-support.c new file mode 100644 index 00000000000..3eb8d22f518 --- /dev/null +++ b/clang/test/Refactor/tool-test-support.c @@ -0,0 +1,41 @@ +// RUN: clang-refactor local-rename -selection=test:%s -no-dbs -v %s 2>&1 | FileCheck %s + +/*range=*/int test; + +/*range named=*/int test2; + +/*range= +1*/int test3; + +/* range = +100 */int test4; + +/*range named =+0*/int test5; + +// CHECK: Test selection group '': +// CHECK-NEXT: 100-100 +// CHECK-NEXT: 153-153 +// CHECK-NEXT: 192-192 +// CHECK-NEXT: Test selection group 'named': +// CHECK-NEXT: 127-127 +// CHECK-NEXT: 213-213 + +// The following invocations are in the default group: + +// CHECK: invoking action 'local-rename': +// CHECK-NEXT: -selection={{.*}}tool-test-support.c:3:11 + +// CHECK: invoking action 'local-rename': +// CHECK-NEXT: -selection={{.*}}tool-test-support.c:7:15 + +// CHECK: invoking action 'local-rename': +// CHECK-NEXT: -selection={{.*}}tool-test-support.c:9:29 + + +// The following invocations are in the 'named' group, and they follow +// the default invocation even if some of their ranges occur prior to the +// ranges from the default group because the groups are tested one-by-one: + +// CHECK: invoking action 'local-rename': +// CHECK-NEXT: -selection={{.*}}tool-test-support.c:5:17 + +// CHECK: invoking action 'local-rename': +// CHECK-NEXT: -selection={{.*}}tool-test-support.c:11:20 diff --git a/clang/test/clang-rename/Field.cpp b/clang/test/clang-rename/Field.cpp deleted file mode 100644 index c0e9a019e47..00000000000 --- a/clang/test/clang-rename/Field.cpp +++ /dev/null @@ -1,15 +0,0 @@ -class Baz { - int Foo; /* Test 1 */ // CHECK: int Bar; -public: - Baz(); -}; - -Baz::Baz() : Foo(0) /* Test 2 */ {} // CHECK: Baz::Baz() : Bar(0) - -// Test 1. -// RUN: clang-rename -offset=18 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s -// Test 2. -// RUN: clang-rename -offset=89 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s - -// To find offsets after modifying the file, use: -// grep -Ubo 'Foo.*' <file> |