test: Allow using clang -verify for failures rather than exit 1

Currently, failure tests work by checking that compilation exits 1.
This can lead to tests that fail for the wrong reason, so it'd be
preferable to convert them to check for specific errors.

This adds use_clang_verify parameter that runs failure tests using
clang's -verify flag. I'll convert some tests in subsequent commits,
and once all of the tests are converted we should key this on whether
cxx_under_test is clang.

I've also converted one of the unique.ptr tests, since it's the one
that motivated the idea of using clang -verify when possible in the
review of r216317.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@217009 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner 2014-09-03 04:32:08 +00:00
parent fc685481dc
commit 837cfe50fe
2 changed files with 38 additions and 16 deletions

View File

@ -28,8 +28,10 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
FOO.fail.cpp - Negative test case which is expected to fail compilation.
"""
def __init__(self, cxx_under_test, cpp_flags, ld_flags, exec_env):
def __init__(self, cxx_under_test, use_verify_for_fail,
cpp_flags, ld_flags, exec_env):
self.cxx_under_test = cxx_under_test
self.use_verify_for_fail = use_verify_for_fail
self.cpp_flags = list(cpp_flags)
self.ld_flags = list(ld_flags)
self.exec_env = dict(exec_env)
@ -116,13 +118,17 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
if expected_compile_fail:
cmd = [self.cxx_under_test, '-c',
'-o', '/dev/null', source_path] + self.cpp_flags
out, err, exitCode = self.execute_command(cmd)
if exitCode == 1:
expected_rc = 1
if self.use_verify_for_fail:
cmd += ['-Xclang', '-verify']
expected_rc = 0
out, err, rc = self.execute_command(cmd)
if rc == expected_rc:
return lit.Test.PASS, ""
else:
report = """Command: %s\n""" % ' '.join(["'%s'" % a
for a in cmd])
report += """Exit Code: %d\n""" % exitCode
report += """Exit Code: %d\n""" % rc
if out:
report += """Standard Output:\n--\n%s--""" % out
if err:
@ -190,6 +196,7 @@ class Configuration(object):
self.compile_flags = []
self.link_flags = []
self.use_system_lib = False
self.use_clang_verify = False
if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'):
self.lit_config.fatal("unrecognized system")
@ -202,12 +209,24 @@ class Configuration(object):
val = default
return val
def get_lit_bool(self, name):
conf = self.get_lit_conf(name)
if conf is None:
return None
if conf.lower() in ('1', 'true'):
return True
if conf.lower() in ('', '0', 'false'):
return False
self.lit_config.fatal(
"parameter '{}' should be true or false".format(name))
def configure(self):
self.configure_cxx()
self.configure_triple()
self.configure_src_root()
self.configure_obj_root()
self.configure_use_system_lib()
self.configure_use_clang_verify()
self.configure_env()
self.configure_std_flag()
self.configure_compile_flags()
@ -218,6 +237,7 @@ class Configuration(object):
def get_test_format(self):
return LibcxxTestFormat(
self.cxx,
self.use_clang_verify,
cpp_flags=['-nostdinc++'] + self.compile_flags,
ld_flags=['-nodefaultlibs'] + self.link_flags,
exec_env=self.env)
@ -251,21 +271,22 @@ class Configuration(object):
# the locally built one; the former mode is useful for testing ABI
# compatibility between the current headers and a shipping dynamic
# library.
use_system_lib_str = self.get_lit_conf('use_system_lib')
if use_system_lib_str:
if use_system_lib_str.lower() in ('1', 'true'):
self.use_system_lib = True
elif use_system_lib_str.lower() in ('', '0', 'false'):
self.use_system_lib = False
else:
self.lit_config.fatal(
'user parameter use_system_lib should be 0 or 1')
else:
self.use_system_lib = self.get_lit_bool('use_system_lib')
if self.use_system_lib is None:
# Default to testing against the locally built libc++ library.
self.use_system_lib = False
self.lit_config.note(
"inferred use_system_lib as: %r" % self.use_system_lib)
def configure_use_clang_verify(self):
'''If set, run clang with -verify on failing tests.'''
self.use_clang_verify = self.get_lit_bool('use_clang_verify')
if self.use_clang_verify is None:
# TODO: Default this to True when using clang.
self.use_clang_verify = False
self.lit_config.note(
"inferred use_clang_verify as: %r" % self.use_clang_verify)
def configure_features(self):
# Figure out which of the required locales we support
locales = {

View File

@ -19,8 +19,9 @@
class Deleter
{
Deleter() {}
// expected-error@memory:* {{base class 'Deleter' has private default constructor}}
// expected-note@memory:* + {{in instantiation of member function}}
Deleter() {} // expected-note {{implicitly declared private here}}
public: