Skip to content

Commit

Permalink
[libc++] Remove workaround for .fail.cpp tests that don't have clang-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ldionne committed Apr 15, 2020
1 parent 443c244 commit 7a6aaf9
Show file tree
Hide file tree
Showing 277 changed files with 46 additions and 28 deletions.
Expand Up @@ -6,9 +6,10 @@
//
//===----------------------------------------------------------------------===//

// Make sure the test passes if it fails at compile-time, without verify
// Make sure the test passes if we don't have clang-verify support and
// the test fails to compile.

// UNSUPPORTED: verify-support

struct Foo { };
typedef Foo::x x;

int main() { }
Expand Up @@ -8,6 +8,9 @@

// XFAIL: *

// Make sure the test DOES NOT pass if it succeeds at compile-time
// Make sure the test DOES NOT pass if we don't have clang-verify support and
// the test compiles successfully.

// UNSUPPORTED: verify-support

int main() { }
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: verify-support

// XFAIL: *

// Make sure the test DOES NOT pass if there are no diagnostics, but we didn't
// use the 'expected-no-diagnostics' markup.
//
// Note: For the purpose of this test, make sure the file would otherwise
// compile to make sure we really fail due to a lack of markup.

int main() { }
@@ -1,4 +1,3 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -7,4 +6,9 @@
//
//===----------------------------------------------------------------------===//

#error This test should not compile.
// REQUIRES: verify-support

// Make sure the test passes if we expected no diagnostics and included
// the markup.

// expected-no-diagnostics
Expand Up @@ -6,7 +6,10 @@
//
//===----------------------------------------------------------------------===//

// Make sure the test passes if it fails at compile-time, with verify
// REQUIRES: verify-support

// Make sure the test passes if it fails at compile-time with the expected
// diagnostic.

struct Foo { };
typedef Foo::x x; // expected-error{{no type named 'x' in 'Foo'}}
Expand Down
Expand Up @@ -10,8 +10,7 @@

// XFAIL: *

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

struct Foo { };
typedef Foo::x x; // expected-error{{this is not found in the errors}}
Expand Down
27 changes: 8 additions & 19 deletions libcxx/utils/libcxx/test/newformat.py
Expand Up @@ -34,10 +34,10 @@ class CxxStandardLibraryTest(lit.formats.TestFormat):
FOO.verify.cpp - Compiles with clang-verify
FOO.fail.cpp - Does not compile successfully -- run with clang-verify
if any expected-meow appears in the file, otherwise
just test that compilation fails. This is supported
only for backwards compatibility with the test suite
FOO.fail.cpp - Compiled with clang-verify if clang-verify is
supported, and equivalent to a .compile.fail.cpp
test otherwise. This is supported only for backwards
compatibility with the test suite.
The test format operates by assuming that each test's configuration provides
the following substitutions, which it will reuse in the shell scripts it
Expand Down Expand Up @@ -109,25 +109,14 @@ def _checkSubstitutions(self, substitutions):
for s in ['%{cxx}', '%{compile_flags}', '%{link_flags}', '%{flags}', '%{exec}']:
assert s in substitutions, "Required substitution {} was not provided".format(s)

# Determine whether -verify should be used for a given test. We use -verify
# if the compiler supports it and there's at least one -verify tag in the
# source file.
#
# This is only supported for backwards compatibility with .fail.cpp tests.
def _useVerify(self, test, litConfig):
VERIFY_TAGS = (b'expected-note', b'expected-remark',
b'expected-warning', b'expected-error',
b'expected-no-diagnostics')
with open(test.getSourcePath(), 'rb') as f:
contents = f.read()
testContainsTags = any(tag in contents for tag in VERIFY_TAGS)

# Determine whether clang-verify is supported.
def _supportsVerify(self, test, litConfig):
command = "echo | %{cxx} -xc++ - -Werror -fsyntax-only -Xclang -verify-ignore-unexpected"
result = lit.TestRunner.executeShTest(test, litConfig,
useExternalSh=True,
preamble_commands=[command])
compilerSupportsVerify = result.code != lit.Test.FAIL
return compilerSupportsVerify and testContainsTags
return compilerSupportsVerify

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

0 comments on commit 7a6aaf9

Please sign in to comment.