Skip to content

Commit 7a6aaf9

Browse files
committed
[libc++] Remove workaround for .fail.cpp tests that don't have clang-verify markup
By renaming .fail.cpp tests that don't need clang-verify to .compile.fail.cpp, the new test format will not try to compile these tests with clang-verify, and the old test format will work just the same. However, this allows removing a workaround that requires parsing each test looking for clang-verify markup. After this change, a .fail.cpp test should always have clang-verify markup. When clang-verify is not supported by the compiler, we will just check that these tests fail to compile. When clang-verify is supported, these tests will be compiled with clang-verify whether they have markup or not (so they should have markup, or they will fail). This simplifies the test suite and also ensures that all of our .fail.cpp tests provide clang-verify markup. If it's impossible for a test to have clang-verify markup, it can be moved to a .compile.fail.cpp test, which are unconditionally just checked for compilation failure.
1 parent 443c244 commit 7a6aaf9

File tree

277 files changed

+46
-28
lines changed

Some content is hidden

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

277 files changed

+46
-28
lines changed

libcxx/test/libcxx/selftest/newformat/fail.cpp/compile-error-without-verify.fail.cpp renamed to libcxx/test/libcxx/selftest/newformat/fail.cpp/compile-failure.fail.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Make sure the test passes if it fails at compile-time, without verify
9+
// Make sure the test passes if we don't have clang-verify support and
10+
// the test fails to compile.
11+
12+
// UNSUPPORTED: verify-support
1013

1114
struct Foo { };
1215
typedef Foo::x x;
13-
14-
int main() { }

libcxx/test/libcxx/selftest/newformat/fail.cpp/compile-success.fail.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
// XFAIL: *
1010

11-
// Make sure the test DOES NOT pass if it succeeds at compile-time
11+
// Make sure the test DOES NOT pass if we don't have clang-verify support and
12+
// the test compiles successfully.
13+
14+
// UNSUPPORTED: verify-support
1215

1316
int main() { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: verify-support
10+
11+
// XFAIL: *
12+
13+
// Make sure the test DOES NOT pass if there are no diagnostics, but we didn't
14+
// use the 'expected-no-diagnostics' markup.
15+
//
16+
// Note: For the purpose of this test, make sure the file would otherwise
17+
// compile to make sure we really fail due to a lack of markup.
18+
19+
int main() { }
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// -*- C++ -*-
21
//===----------------------------------------------------------------------===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,4 +6,9 @@
76
//
87
//===----------------------------------------------------------------------===//
98

10-
#error This test should not compile.
9+
// REQUIRES: verify-support
10+
11+
// Make sure the test passes if we expected no diagnostics and included
12+
// the markup.
13+
14+
// expected-no-diagnostics

libcxx/test/libcxx/selftest/newformat/fail.cpp/compile-error-with-verify.fail.cpp renamed to libcxx/test/libcxx/selftest/newformat/fail.cpp/right-diagnostic.fail.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Make sure the test passes if it fails at compile-time, with verify
9+
// REQUIRES: verify-support
10+
11+
// Make sure the test passes if it fails at compile-time with the expected
12+
// diagnostic.
1013

1114
struct Foo { };
1215
typedef Foo::x x; // expected-error{{no type named 'x' in 'Foo'}}

libcxx/test/libcxx/selftest/newformat/fail.cpp/wrong-expected.fail.cpp renamed to libcxx/test/libcxx/selftest/newformat/fail.cpp/wrong-diagnostic.fail.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
// XFAIL: *
1212

13-
// Make sure the test DOES NOT pass if it fails at compile-time, but the
14-
// expected-error is wrong.
13+
// Make sure the test DOES NOT pass if the expected diagnostic is wrong.
1514

1615
struct Foo { };
1716
typedef Foo::x x; // expected-error{{this is not found in the errors}}

libcxx/utils/libcxx/test/newformat.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class CxxStandardLibraryTest(lit.formats.TestFormat):
3434
3535
FOO.verify.cpp - Compiles with clang-verify
3636
37-
FOO.fail.cpp - Does not compile successfully -- run with clang-verify
38-
if any expected-meow appears in the file, otherwise
39-
just test that compilation fails. This is supported
40-
only for backwards compatibility with the test suite
37+
FOO.fail.cpp - Compiled with clang-verify if clang-verify is
38+
supported, and equivalent to a .compile.fail.cpp
39+
test otherwise. This is supported only for backwards
40+
compatibility with the test suite.
4141
4242
The test format operates by assuming that each test's configuration provides
4343
the following substitutions, which it will reuse in the shell scripts it
@@ -109,25 +109,14 @@ def _checkSubstitutions(self, substitutions):
109109
for s in ['%{cxx}', '%{compile_flags}', '%{link_flags}', '%{flags}', '%{exec}']:
110110
assert s in substitutions, "Required substitution {} was not provided".format(s)
111111

112-
# Determine whether -verify should be used for a given test. We use -verify
113-
# if the compiler supports it and there's at least one -verify tag in the
114-
# source file.
115-
#
116-
# This is only supported for backwards compatibility with .fail.cpp tests.
117-
def _useVerify(self, test, litConfig):
118-
VERIFY_TAGS = (b'expected-note', b'expected-remark',
119-
b'expected-warning', b'expected-error',
120-
b'expected-no-diagnostics')
121-
with open(test.getSourcePath(), 'rb') as f:
122-
contents = f.read()
123-
testContainsTags = any(tag in contents for tag in VERIFY_TAGS)
124-
112+
# Determine whether clang-verify is supported.
113+
def _supportsVerify(self, test, litConfig):
125114
command = "echo | %{cxx} -xc++ - -Werror -fsyntax-only -Xclang -verify-ignore-unexpected"
126115
result = lit.TestRunner.executeShTest(test, litConfig,
127116
useExternalSh=True,
128117
preamble_commands=[command])
129118
compilerSupportsVerify = result.code != lit.Test.FAIL
130-
return compilerSupportsVerify and testContainsTags
119+
return compilerSupportsVerify
131120

132121
def _disableWithModules(self, test, litConfig):
133122
with open(test.getSourcePath(), 'rb') as f:
@@ -194,7 +183,7 @@ def execute(self, test, litConfig):
194183
# otherwise it's like a .compile.fail.cpp test. This is only provided
195184
# for backwards compatibility with the test suite.
196185
elif filename.endswith('.fail.cpp'):
197-
if self._useVerify(test, litConfig):
186+
if self._supportsVerify(test, litConfig):
198187
steps = [
199188
"%dbg(COMPILED WITH) %{cxx} %s %{flags} %{compile_flags} -fsyntax-only " + VERIFY_FLAGS
200189
]

0 commit comments

Comments
 (0)