Skip to content

Commit 4f68243

Browse files
committed
[Utils] Add --update-tests to lit
This adds a flag to lit for detecting and updating failing tests when possible to do so automatically. The flag uses a plugin architecture where config files can add additional auto-updaters for the types of tests in the test suite. When a test fails with --update-tests enabled lit passes the test RUN invocation and output to each registered test updater until one of them signals that it updated the test. As such it is the responsibility of the test updater to only update tests where it is reasonably certain that it will actually fix the test, or come close to doing so. Also adds two initial test updaters: one built into lit, which automatically updates the 'expected' file when a 'diff' command fails; and one specific to clang's Sema test suite, which updates the expected-[diag-kind] lines in tests using the -verify flag.
1 parent 4da171a commit 4f68243

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+682
-455
lines changed

clang/test/Sema/lit.local.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@ config.substitutions = list(config.substitutions)
22
config.substitutions.insert(
33
0, (r"%clang\b", """*** Do not use the driver in Sema tests. ***""")
44
)
5+
6+
if lit_config.update_tests:
7+
import sys
8+
import os
9+
10+
curdir = os.path.dirname(os.path.realpath(__file__))
11+
testdir = os.path.dirname(curdir)
12+
clangdir = os.path.dirname(testdir)
13+
utilspath = os.path.join(clangdir, "utils")
14+
sys.path.append(utilspath)
15+
from UpdateVerifyTests.litplugin import verify_test_updater
16+
lit_config.test_updaters.append(verify_test_updater)

clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{use of undeclared identifier 'a'}}
35
a = 2; a = 2;

clang/test/utils/update-verify-tests/Inputs/duplicate-diag.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1 2{{use of undeclared identifier 'a'}}
35
a = 2; a = 2;

clang/test/utils/update-verify-tests/Inputs/infer-indentation.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1 2 {{use of undeclared identifier 'a'}}
35
a = 2; a = 2; b = 2; b = 2; c = 2;

clang/test/utils/update-verify-tests/Inputs/infer-indentation.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+3 {{use of undeclared identifier 'c'}}
35
// expected-error@+2 2 {{use of undeclared identifier 'b'}}

clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2;
35
// expected-error@-1{{use of undeclared identifier 'a'}}
46
b = 2;// expected-error{{use of undeclared identifier 'b'}}
57
c = 2;
6-
// expected-error@5{{use of undeclared identifier 'c'}}
8+
// expected-error@7{{use of undeclared identifier 'c'}}
79
d = 2; // expected-error-re{{use of {{.*}} identifier 'd'}}
810

911
e = 2; // error to trigger mismatch

clang/test/utils/update-verify-tests/Inputs/leave-existing-diags.c.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2;
35
// expected-error@-1{{use of undeclared identifier 'a'}}
46
b = 2;// expected-error{{use of undeclared identifier 'b'}}
57
c = 2;
6-
// expected-error@5{{use of undeclared identifier 'c'}}
8+
// expected-error@7{{use of undeclared identifier 'c'}}
79
d = 2; // expected-error-re{{use of {{.*}} identifier 'd'}}
810

911
// expected-error@+1{{use of undeclared identifier 'e'}}

clang/test/utils/update-verify-tests/Inputs/multiple-errors.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2;
35
b = 2;

clang/test/utils/update-verify-tests/Inputs/multiple-errors.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{use of undeclared identifier 'a'}}
35
a = 2;

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2; b = 2; c = 2;
35
}

clang/test/utils/update-verify-tests/Inputs/multiple-missing-errors-same-line.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+3{{use of undeclared identifier 'c'}}
35
// expected-error@+2{{use of undeclared identifier 'b'}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
bar = 2;
35
}

clang/test/utils/update-verify-tests/Inputs/no-checks.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{use of undeclared identifier 'bar'}}
35
bar = 2;

clang/test/utils/update-verify-tests/Inputs/no-diags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{asdf}}
35
int a = 2;

clang/test/utils/update-verify-tests/Inputs/no-diags.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// expected-no-diagnostics
2+
// RUN: %clang_cc1 -verify %s
3+
// RUN: diff %s %s.expected
24
void foo() {
35
int a = 2;
46
}

clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
// expected-no-diagnostics
24
void foo() {
35
a = 2;

clang/test/utils/update-verify-tests/Inputs/no-expected-diags.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{use of undeclared identifier 'a'}}
35
a = 2;

clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify=check %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2; // check-error{{asdf}}
35
// expected-error@-1{ignored}}

clang/test/utils/update-verify-tests/Inputs/non-default-prefix.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify=check %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
a = 2; // check-error{{use of undeclared identifier 'a'}}
35
// expected-error@-1{ignored}}

clang/test/utils/update-verify-tests/Inputs/update-same-line.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
bar = 2; // expected-error {{asdf}}
35
}

clang/test/utils/update-verify-tests/Inputs/update-same-line.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
bar = 2; // expected-error {{use of undeclared identifier 'bar'}}
35
}

clang/test/utils/update-verify-tests/Inputs/update-single-check.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{asdf}}
35
bar = 2;

clang/test/utils/update-verify-tests/Inputs/update-single-check.c.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// RUN: %clang_cc1 -verify %s
2+
// RUN: diff %s %s.expected
13
void foo() {
24
// expected-error@+1{{use of undeclared identifier 'bar'}}
35
bar = 2;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.c
2+
*.c.expected
3+
.lit_test_times.txt
4+
Output
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import lit.formats
2+
import lit.llvm
3+
lit.llvm.initialize(lit_config, config)
4+
from lit.llvm import llvm_config
5+
from os.path import dirname
6+
7+
config.name = "Lit Update Verify Tests"
8+
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
9+
config.suffixes = [
10+
".c",
11+
]
12+
config.test_source_root = dirname(__file__)
13+
config.target_triple = None
14+
config.host_triple = None
15+
16+
config.llvm_tools_dir = lit_config.path[0] # --path is explicitly passed by lit-plugin.test
17+
llvm_config.use_default_substitutions()
18+
llvm_config.use_clang()
19+
config.substitutions.append(("%clang_cc1", "%clang -cc1"))
20+
21+
if lit_config.update_tests:
22+
import sys
23+
import os
24+
25+
config.clang_src_dir = dirname(dirname(dirname(dirname(config.test_source_root))))
26+
utilspath = os.path.join(config.clang_src_dir, "utils")
27+
sys.path.append(utilspath)
28+
from UpdateVerifyTests.litplugin import verify_test_updater
29+
# normally we'd append to the existing list, but when testing
30+
# verify_test_updater we don't want diff_test_updater to accidentally interfere
31+
lit_config.test_updaters = [verify_test_updater]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RUN: cp %S/Inputs/*.c %S/LitTests
2+
# RUN: cp %S/Inputs/*.c.expected %S/LitTests
3+
# RUN: not %{lit} %S/LitTests
4+
# RUN: not %{lit} %S/LitTests --update-tests
5+
# RUN: %{lit} %S/LitTests

clang/test/utils/update-verify-tests/lit.local.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if config.standalone_build:
1212
config.unsupported = True
1313
else:
1414
config.suffixes = [".test"]
15+
config.excludes.add("LitTests")
1516

1617
script_path = os.path.join(
1718
config.clang_src_dir, "utils", "update-verify-tests.py"
@@ -23,3 +24,13 @@ else:
2324
"%s %s" % (python, shell_quote(script_path)),
2425
)
2526
)
27+
config.substitutions.append(("%{lit}", "%{lit-no-order-opt} --order=lexical"))
28+
29+
lit_path = os.path.join(config.llvm_tools_dir, "llvm-lit")
30+
lit_path = os.path.abspath(lit_path)
31+
config.substitutions.append(
32+
(
33+
"%{lit-no-order-opt}",
34+
f"{python} {lit_path} -j1 --path {config.llvm_tools_dir}"
35+
)
36+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)