Skip to content

Commit

Permalink
[clang-rename] merge tests when possible
Browse files Browse the repository at this point in the history
The only difference between some tests is -offset passed to clang-rename. It
makes sense to merge them into a single file and add multiple tool invocations.

Reviewers: alexfh

Differential Revision: https://reviews.llvm.org/D23158

llvm-svn: 278221
  • Loading branch information
kirillbobyrev committed Aug 10, 2016
1 parent e171ea8 commit 77f522c
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 160 deletions.
21 changes: 21 additions & 0 deletions clang-tools-extra/test/clang-rename/ClassAsTemplateArgument.cpp
@@ -0,0 +1,21 @@
class Foo /* Test 1 */ {}; // CHECK: class Bar /* Test 1 */ {};

template <typename T>
void func() {}

template <typename T>
class Baz {};

int main() {
func<Foo>(); // CHECK: func<Bar>();
Baz<Foo> /* Test 2 */ obj; // CHECK: Baz<Bar> /* Test 2 */ obj;
return 0;
}

// Test 1.
// RUN: clang-rename -offset=7 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=215 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
9 changes: 4 additions & 5 deletions clang-tools-extra/test/clang-rename/ClassFindByName.cpp
@@ -1,11 +1,10 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

class Foo { // CHECK: class Bar
class Foo { // CHECK: class Bar {
};

int main() {
Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
return 0;
}

// Test 1.
// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
21 changes: 11 additions & 10 deletions clang-tools-extra/test/clang-rename/ClassSimpleRenaming.cpp
@@ -1,13 +1,14 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Foo /* Test 1 */ { // CHECK: class Bar /* Test 1 */ {
public:
void foo(int x);
};

class Foo {}; // CHECK: class Bar
void Foo::foo(int x) /* Test 2 */ {} // CHECK: void Bar::foo(int x) /* Test 2 */ {}

int main() {
Foo *Pointer = 0; // CHECK: Bar *Pointer = 0;
return 0;
}
// Test 1.
// RUN: clang-rename -offset=6 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=109 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// Use grep -FUbo 'Foo' <file> to get the correct offset of Cla when changing
// this file.
// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
13 changes: 8 additions & 5 deletions clang-tools-extra/test/clang-rename/ClassTestMulti.cpp
@@ -1,8 +1,11 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -offset=174 -new-name=Bar1 -offset=212 -new-name=Bar2 %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Foo1 { // CHECK: class Bar1
class Foo1 /* Offset 1 */ { // CHECK: class Bar1 /* Offset 1 */ {
};

class Foo2 { // CHECK: class Bar2
class Foo2 /* Offset 2 */ { // CHECK: class Bar2 /* Offset 2 */ {
};

// Test 1.
// RUN: clang-rename rename-all -offset=6 -new-name=Bar1 -offset=76 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
6 changes: 3 additions & 3 deletions clang-tools-extra/test/clang-rename/ClassTestMultiByName.cpp
@@ -1,8 +1,8 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -old-name=Foo1 -new-name=Bar1 -old-name=Foo2 -new-name=Bar2 %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class Foo1 { // CHECK: class Bar1
};

class Foo2 { // CHECK: class Bar2
};

// Test 1.
// RUN: clang-rename rename-all -old-name=Foo1 -new-name=Bar1 -old-name=Foo2 -new-name=Bar2 %s -- | sed 's,//.*,,' | FileCheck %s
Expand Up @@ -3,5 +3,8 @@ class Foo1 { // CHECK: class Bar1

class Foo2 { // CHECK: class Bar2
};

// Test 1.
// RUN: clang-rename rename-all -input %S/Inputs/ClassTestMultiByNameYAMLRenameAll.yaml %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename rename-all -input %S/Inputs/ClassTestMultiByNameYAMLRenameAt.yaml %s -- | sed 's,//.*,,' | FileCheck %s
42 changes: 33 additions & 9 deletions clang-tools-extra/test/clang-rename/ComplexFunctionOverride.cpp
@@ -1,23 +1,47 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=307 -new-name=bar %t.cpp -i -- -std=c++11
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

struct A {
virtual void foo(); // CHECK: virtual void bar();
virtual void foo() {} /* Test 1 */ // CHECK: virtual void bar() {}
};

struct B : A {
void foo() override; // CHECK: void bar() override;
void foo() override {} /* Test 2 */ // CHECK: void bar() override {}
};

struct C : B {
void foo() override; // CHECK: void bar() override;
void foo() override {} /* Test 3 */ // CHECK: void bar() override {}
};

struct D : B {
void foo() override; // CHECK: void bar() override;
void foo() override {} /* Test 4 */ // CHECK: void bar() override {}
};

struct E : D {
void foo() override; // CHECK: void bar() override;
void foo() override {} /* Test 5 */ // CHECK: void bar() override {}
};

int main() {
A a;
a.foo(); // CHECK: a.bar();
B b;
b.foo(); // CHECK: b.bar();
C c;
c.foo(); // CHECK: c.bar();
D d;
d.foo(); // CHECK: d.bar();
E e;
e.foo(); // CHECK: e.bar();
return 0;
}

// Test 1.
// RUN: clang-rename -offset=26 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=109 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 3.
// RUN: clang-rename -offset=201 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 4.
// RUN: clang-rename -offset=293 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 5.
// RUN: clang-rename -offset=385 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'foo.*' <file>
44 changes: 38 additions & 6 deletions clang-tools-extra/test/clang-rename/ComplicatedClassType.cpp
@@ -1,11 +1,11 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=220 -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

// Forward declaration.
class Foo; // CHECK: class Bar;
class Foo; /* Test 1 */ // CHECK: class Bar; /* Test 1 */

class Baz {
virtual int getValue() const = 0;
};

class Foo { // CHECK: class Bar {
class Foo : public Baz { /* Test 2 */// CHECK: class Bar : public Baz {
public:
Foo(int value = 0) : x(value) {} // CHECK: Bar(int value = 0) : x(value) {}

Expand All @@ -18,6 +18,10 @@ class Foo { // CHECK: class Bar {
return this->x < rhs.x;
}

int getValue() const {
return 0;
}

private:
int x;
};
Expand All @@ -27,5 +31,33 @@ int main() {
Foo Variable = Foo(10); // CHECK: Bar Variable = Bar(10);
for (Foo it; it < Variable; it++) { // CHECK: for (Bar it; it < Variable; it++) {
}
const Foo *C = new Foo(); // CHECK: const Bar *C = new Bar();
const_cast<Foo *>(C)->getValue(); // CHECK: const_cast<Bar *>(C)->getValue();
Foo foo; // CHECK: Bar foo;
const Baz &BazReference = foo;
const Baz *BazPointer = &foo;
dynamic_cast<const Foo &>(BazReference).getValue(); /* Test 3 */ // CHECK: dynamic_cast<const Bar &>(BazReference).getValue();
dynamic_cast<const Foo *>(BazPointer)->getValue(); /* Test 4 */ // CHECK: dynamic_cast<const Bar *>(BazPointer)->getValue();
reinterpret_cast<const Foo *>(BazPointer)->getValue(); /* Test 5 */ // CHECK: reinterpret_cast<const Bar *>(BazPointer)->getValue();
static_cast<const Foo &>(BazReference).getValue(); /* Test 6 */ // CHECK: static_cast<const Bar &>(BazReference).getValue();
static_cast<const Foo *>(BazPointer)->getValue(); /* Test 7 */ // CHECK: static_cast<const Bar *>(BazPointer)->getValue();
return 0;
}

// Test 1.
// RUN: clang-rename -offset=30 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=155 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 3.
// RUN: clang-rename -offset=1133 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 4.
// RUN: clang-rename -offset=1266 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 5.
// RUN: clang-rename -offset=1402 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 6.
// RUN: clang-rename -offset=1533 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 7.
// RUN: clang-rename -offset=1665 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
14 changes: 14 additions & 0 deletions clang-tools-extra/test/clang-rename/Ctor.cpp
@@ -0,0 +1,14 @@
class Foo { // CHECK: class Bar {
public:
Foo(); /* Test 1 */ // CHECK: Bar();
};

Foo::Foo() /* Test 2 */ {} // CHECK: Bar::Bar() /* Test 2 */ {}

// Test 1.
// RUN: clang-rename -offset=62 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=116 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
17 changes: 9 additions & 8 deletions clang-tools-extra/test/clang-rename/CtorInitializer.cpp
@@ -1,16 +1,17 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=163 -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

class Baz {};

class Qux {
Baz Foo; // CHECK: Baz Bar;
Baz Foo; /* Test 1 */ // CHECK: Baz Bar;
public:
Qux();
};

Qux::Qux() : Foo() {} // CHECK: Qux::Qux() : Bar() {}
Qux::Qux() : Foo() /* Test 2 */ {} // CHECK: Qux::Qux() : Bar() /* Test 2 */ {}

// Test 1.
// RUN: clang-rename -offset=33 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=118 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// Use grep -FUbo 'Foo' <file> to get the correct offset of foo when changing
// this file.
// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
24 changes: 14 additions & 10 deletions clang-tools-extra/test/clang-rename/DeclRefExpr.cpp
@@ -1,20 +1,24 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=161 -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

class C {
public:
static int Foo; // CHECK: static int Bar;
static int Foo; /* Test 1 */ // CHECK: static int Bar;
};

int foo(int x) { return 0; }
#define MACRO(a) foo(a)

int main() {
C::Foo = 1; // CHECK: C::Bar
MACRO(C::Foo); // CHECK: C::Bar
int y = C::Foo; // CHECK: C::Bar
C::Foo = 1; /* Test 2 */ // CHECK: C::Bar = 1;
MACRO(C::Foo); // CHECK: MACRO(C::Bar);
int y = C::Foo; /* Test 3 */ // CHECK: int y = C::Bar;
return 0;
}

// Use grep -FUbo 'X' <file> to get the correct offset of foo when changing
// this file.
// Test 1.
// RUN: clang-rename -offset=31 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=152 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 3.
// RUN: clang-rename -offset=271 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>
19 changes: 9 additions & 10 deletions clang-tools-extra/test/clang-rename/FunctionMacro.cpp
@@ -1,21 +1,20 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=199 -new-name=macro_function %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
#define moo foo // CHECK: #define moo macro_function

#define moo foo // CHECK: #define moo macro_function

int foo() { // CHECK: int macro_function() {
int foo() /* Test 1 */ { // CHECK: int macro_function() /* Test 1 */ {
return 42;
}

void boo(int value) {}

void qoo() {
foo(); // CHECK: macro_function();
boo(foo()); // CHECK: boo(macro_function());
foo(); // CHECK: macro_function();
boo(foo()); // CHECK: boo(macro_function());
moo();
boo(moo());
}

// Use grep -FUbo 'foo;' <file> to get the correct offset of foo when changing
// this file.
// Test 1.
// RUN: clang-rename -offset=68 -new-name=macro_function %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'foo.*' <file>
19 changes: 11 additions & 8 deletions clang-tools-extra/test/clang-rename/FunctionOverride.cpp
@@ -1,10 +1,13 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=318 -new-name=bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s
class A { virtual void foo(); /* Test 1 */ }; // CHECK: class A { virtual void bar();
class B : public A { void foo(); /* Test 2 */ }; // CHECK: class B : public A { void bar();
class C : public B { void foo(); /* Test 3 */ }; // CHECK: class C : public B { void bar();

class A { virtual void foo(); }; // CHECK: class A { virtual void bar(); };
class B : public A { void foo(); }; // CHECK: class B : public A { void bar(); };
class C : public B { void foo(); }; // CHECK: class C : public B { void bar(); };
// Test 1.
// RUN: clang-rename -offset=23 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=116 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 3.
// RUN: clang-rename -offset=209 -new-name=bar %s -- | sed 's,//.*,,' | FileCheck %s

// Use grep -FUbo 'Foo' <file> to get the correct offset of Foo when changing
// this file.
// To find offsets after modifying the file, use:
// grep -Ubo 'foo.*' <file>
@@ -1,7 +1,3 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

void foo() {
}

Expand All @@ -13,3 +9,4 @@ int main() {
return 0;
}

// RUN: clang-rename rename-all -old-name=Foo -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
21 changes: 11 additions & 10 deletions clang-tools-extra/test/clang-rename/MemberExprMacro.cpp
@@ -1,21 +1,22 @@
// RUN: cat %s > %t.cpp
// RUN: clang-rename -offset=156 -new-name=Bar %t.cpp -i --
// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s

class Baz {
public:
int Foo; // CHECK: int Bar;
int Foo; /* Test 1 */ // CHECK: int Bar;
};

int qux(int x) { return 0; }
#define MACRO(a) qux(a)

int main() {
Baz baz;
baz.Foo = 1; // CHECK: baz.Bar = 1;
MACRO(baz.Foo); // CHECK: MACRO(baz.Bar);
int y = baz.Foo; // CHECK: int y = baz.Bar;
baz.Foo = 1; /* Test 2 */ // CHECK: baz.Bar = 1;
MACRO(baz.Foo); // CHECK: MACRO(baz.Bar);
int y = baz.Foo; // CHECK: int y = baz.Bar;
}

// Use grep -FUbo 'Foo' <file> to get the correct offset of foo when changing
// this file.
// Test 1.
// RUN: clang-rename -offset=26 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s
// Test 2.
// RUN: clang-rename -offset=155 -new-name=Bar %s -- | sed 's,//.*,,' | FileCheck %s

// To find offsets after modifying the file, use:
// grep -Ubo 'Foo.*' <file>

0 comments on commit 77f522c

Please sign in to comment.