mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 02:26:05 +00:00

Tests where the RUN-lines/CHECK-ed output refer to line numbers in the test file are a maintenance burden, as inserting text in the appropriate place invalidates all the subsequent line numbers. Lit supports %(line+n) for this, and FileCheck supports [[@LINE+N]]. But many existing tests don't make use of it and still need to be modified. This commit adds a script that can find line numbers in tests according to a regex and replace them with the appropriate relative-line reference. It contains some options to avoid inappropriately rewriting tests where absolute numbers are appropriate: a "nearby" threshold and a refusal by default to replace only some matched line numbers. I've applied it to CodeComplete tests, this proves the concept but also are the single worst group of tests I've seen in this respect. These changes are likely to hit merge conflicts, but can be regenerated with: ``` find ../clang/test/CodeCompletion/ -type f | grep -v /Inputs/ | xargs ../llvm/utils/relative_lines.py --verbose --near=20 --pattern='-code-completion-at[ =]%s:(\\d+):' --pattern='requires fix-it: {(\d+):\d+-(\d+):\d+}' ```` As requested in https://reviews.llvm.org/D140044 Fixes https://github.com/llvm/llvm-project/issues/59553 Differential Revision: https://reviews.llvm.org/D140217
126 lines
5.6 KiB
C++
126 lines
5.6 KiB
C++
struct Base1 {
|
|
Base1() : {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
|
|
// CHECK-CC1: COMPLETION: Pattern : member1(<#int#>)
|
|
// CHECK-CC1: COMPLETION: Pattern : member2(<#float#>)
|
|
|
|
Base1(int) : member1(123), {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
|
|
// CHECK-CC2-NOT: COMPLETION: Pattern : member1(<#int#>)
|
|
// CHECK-CC2: COMPLETION: Pattern : member2(<#float#>)
|
|
|
|
int member1;
|
|
float member2;
|
|
};
|
|
|
|
struct Derived : public Base1 {
|
|
Derived();
|
|
Derived(int);
|
|
Derived(float);
|
|
int deriv1;
|
|
};
|
|
|
|
Derived::Derived() : {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
|
|
// CHECK-CC3: COMPLETION: Pattern : Base1()
|
|
// CHECK-CC3: COMPLETION: Pattern : Base1(<#int#>)
|
|
// CHECK-CC3: COMPLETION: Pattern : deriv1(<#int#>)
|
|
|
|
Derived::Derived(int) try : {
|
|
} catch (...) {
|
|
}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-3):29 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-4):29 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
|
|
|
|
Derived::Derived(float) try : Base1(),
|
|
{
|
|
} catch (...) {
|
|
}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-4):39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-5):39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
|
|
// CHECK-CC5-NOT: COMPLETION: Pattern : Base1
|
|
// CHECK-CC5: COMPLETION: Pattern : deriv1(<#int#>)
|
|
|
|
struct A {
|
|
A() : , member2() {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):9 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):9 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
|
|
// CHECK-CC6: COMPLETION: Pattern : member1(<#int#>)
|
|
int member1, member2;
|
|
};
|
|
|
|
struct B {
|
|
B() : member2() {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
|
|
// CHECK-CC7: COMPLETION: Pattern : member1(<#int#>)
|
|
// Check in the middle and at the end of identifier too.
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-5):13 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-6):16 %s -o - | FileCheck -check-prefix=CHECK-CC8 %s
|
|
// CHECK-CC8: COMPLETION: Pattern : member2(<#int#>)
|
|
int member1, member2;
|
|
};
|
|
|
|
struct Base2 {
|
|
Base2(int);
|
|
};
|
|
|
|
struct Composition1 {
|
|
Composition1() : b2_elem(2) {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):28 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):28 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
// CHECK-CC9: OVERLOAD: Base2(<#int#>)
|
|
// CHECK-CC9: OVERLOAD: Base2(<#const Base2 &#>)
|
|
// CHECK-CC9-NOT: OVERLOAD: Composition1
|
|
Composition1(Base2);
|
|
Base2 b2_elem;
|
|
};
|
|
|
|
struct Composition2 {
|
|
Composition2() : c1_elem(Base2(1)) {}
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-1):34 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-2):34 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-3):35 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-4):35 %s -o - | FileCheck -check-prefix=CHECK-CC9 %s
|
|
Composition1 c1_elem;
|
|
};
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-7):20 %s -o - | FileCheck -check-prefix=CHECK-CC10 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-8):20 %s -o - | FileCheck -check-prefix=CHECK-CC10 %s
|
|
// CHECK-CC10: Pattern : c1_elem()
|
|
// CHECK-CC10: Pattern : c1_elem(<#Base2#>)
|
|
|
|
template <class T>
|
|
struct Y : T {};
|
|
|
|
template <class T>
|
|
struct X : Y<T> {
|
|
X() : Y<T>() {};
|
|
};
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:%(line-3):9 %s -o - | FileCheck -check-prefix=CHECK-CC11 %s
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-4):9 %s -o - | FileCheck -check-prefix=CHECK-CC11 %s
|
|
// CHECK-CC11: Pattern : Y<T>(<#Y<T>#>)
|
|
|
|
// Test with incomplete init lists. (Relevant as parsing is *not* cut off).
|
|
struct Incomplete1 {
|
|
Incomplete1() : mem
|
|
|
|
int member1;
|
|
int member2;
|
|
};
|
|
// RUN: not %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-5):19 %s -o - | FileCheck -check-prefix=CHECK-CC12 %s
|
|
// CHECK-CC12: COMPLETION: Pattern : member1(<#int#>)
|
|
// CHECK-CC12: COMPLETION: Pattern : member2(<#int#>)
|
|
|
|
struct Incomplete2 {
|
|
Incomplete2() : member2(
|
|
|
|
int member1;
|
|
int member2;
|
|
};
|
|
// RUN: not %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:%(line-5):27 %s -o - | FileCheck -check-prefix=CHECK-CC13 %s
|
|
// CHECK-CC13: PREFERRED-TYPE: int
|