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
32 lines
986 B
C++
32 lines
986 B
C++
struct foo {
|
|
typedef int type;
|
|
|
|
type method(type, foo::type, ::foo::type, ::foo::foo::type);
|
|
};
|
|
|
|
namespace ns {
|
|
struct bar {
|
|
};
|
|
|
|
struct baz {
|
|
};
|
|
|
|
int func(foo::type a, bar b, baz c);
|
|
}
|
|
|
|
typedef ns::bar bar;
|
|
|
|
int func(foo a, bar b, ns::bar c, ns::baz d);
|
|
using ns::func;
|
|
|
|
void test() {
|
|
foo().method(0, 0, 0, 0);
|
|
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):9 %s -o - | FileCheck %s --check-prefix=CHECK-1
|
|
// CHECK-1: COMPLETION: method : [#type#]method(<#type#>, <#foo::type#>, <#::foo::type#>, <#::foo::foo::type#>)
|
|
f
|
|
// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:%(line-1):3 %s -o - | FileCheck %s --check-prefix=CHECK-2
|
|
// FIXME(ibiryukov): We should get rid of CHECK-DAGs here when completion output is made deterministic (see PR35244).
|
|
// CHECK-2-DAG: COMPLETION: func : [#int#]func(<#foo a#>, <#bar b#>, <#ns::bar c#>, <#ns::baz d#>
|
|
// CHECK-2-DAG: COMPLETION: func : [#int#]func(<#foo::type a#>, <#bar b#>, <#baz c#>
|
|
}
|