Fixed test262.py to handle strict options correctly.

Fixed convert.py to convert a "use strict" into an @strict_only
This commit is contained in:
Mark Miller 2011-09-13 22:06:04 -07:00
parent bba34a262e
commit 9f7d9f6ab5
2 changed files with 51 additions and 36 deletions

View File

@ -39,11 +39,13 @@
var captureCommentPattern = /\/\*\*?((?:\s|\S)*?)\*\/\s*\n/; var captureCommentPattern = /\/\*\*?((?:\s|\S)*?)\*\/\s*\n/;
var anyPattern = /(?:\s|\S)*/; var anyPattern = /(?:\s|\S)*/;
var blanksPattern = /(?:\s|\n)*/; var blanksPattern = /(?:\s|\n)*/;
var captureStrictPattern = /\s*('use strict'|"use strict");/;
// Should match anything // Should match anything
var testEnvelopePattern = var testEnvelopePattern =
regExp('^(', headerPattern, regExp('^(', headerPattern,
')(?:', captureCommentPattern, ')(?:', captureCommentPattern,
')?(?:', captureStrictPattern,
')?(', anyPattern, ')?(', anyPattern,
')$'); ')$');
@ -102,7 +104,6 @@
throw new Error('unrecognized: ' + name); throw new Error('unrecognized: ' + name);
} }
envelope.header = trim(envelopeMatch[1]); envelope.header = trim(envelopeMatch[1]);
if (envelopeMatch[2]) { if (envelopeMatch[2]) {
var propTexts = envelopeMatch[2].split(/\s*\n\s*\*\s*@/); var propTexts = envelopeMatch[2].split(/\s*\n\s*\*\s*@/);
envelope.comment = stripStars(propTexts.shift()), // notice side effect envelope.comment = stripStars(propTexts.shift()), // notice side effect
@ -120,7 +121,10 @@
envelope.testRecord[propName] = propVal; envelope.testRecord[propName] = propVal;
}); });
} }
envelope.rest = envelopeMatch[3]; // Do not trim if (envelopeMatch[3]) {
envelope.testRecord.strict_only = '';
}
envelope.rest = envelopeMatch[4]; // Do not trim
var registerMatch = registerPattern.exec(envelope.rest); var registerMatch = registerPattern.exec(envelope.rest);
if (registerMatch) { if (registerMatch) {
@ -247,7 +251,7 @@
if (!('strict_only' in testRecord)) { if (!('strict_only' in testRecord)) {
testRecord.strict_only = ''; testRecord.strict_only = '';
} }
if (!'negative' in testRecord) { if (!('negative' in testRecord)) {
testRecord.negative = testRecord.strict_mode_negative; testRecord.negative = testRecord.strict_mode_negative;
delete testRecord.strict_mode_negative; delete testRecord.strict_mode_negative;
} }

View File

@ -36,8 +36,10 @@ def BuildOptions():
help="Print summary after running tests") help="Print summary after running tests")
result.add_option("--full-summary", default=False, action="store_true", result.add_option("--full-summary", default=False, action="store_true",
help="Print summary and test output after running tests") help="Print summary and test output after running tests")
result.add_option("--enable-strict-mode", default=False, action="store_true", result.add_option("--strict_only", default=False, action="store_true",
help="Run the mode also in ES5 strict mode") help="Test only strict mode")
result.add_option("--non_strict_only", default=False, action="store_true",
help="Test only non-strict mode")
return result return result
@ -122,16 +124,15 @@ class TestResult(object):
def ReportOutcome(self, long_format): def ReportOutcome(self, long_format):
name = self.case.GetName() name = self.case.GetName()
mode = self.case.GetMode()
if self.HasUnexpectedOutcome(): if self.HasUnexpectedOutcome():
if self.case.IsNegative(): if self.case.IsNegative():
print "%s was expected to fail but didn't" % name print "%s was expected to fail in %s, but didn't" % (name, mode)
elif (self.case.strict_mode and self.case.IsStrictModeNegative()):
print "%s was expected to fail in strict mode, but didn't" % name
else: else:
if long_format: if long_format:
print "=== %s failed ===" % name print "=== %s failed in %s ===" % (name, mode)
else: else:
print "%s: " % name print "%s in %s: " % (name, mode)
out = self.stdout.strip() out = self.stdout.strip()
if len(out) > 0: if len(out) > 0:
print "--- output ---" print "--- output ---"
@ -143,14 +144,9 @@ class TestResult(object):
if long_format: if long_format:
print "===" print "==="
elif self.case.IsNegative(): elif self.case.IsNegative():
print "%s failed as expected" % name print "%s failed in %s as expected" % (name, mode)
elif self.case.strict_mode:
if self.case.IsStrictModeNegative():
print "%s failed in strict mode as expected" % name
else:
print "%s passed in strict mode" % name
else: else:
print "%s passed" % name print "%s passed in %s" % (name, mode)
def HasFailed(self): def HasFailed(self):
return self.exit_code != 0 return self.exit_code != 0
@ -158,26 +154,31 @@ class TestResult(object):
def HasUnexpectedOutcome(self): def HasUnexpectedOutcome(self):
if self.case.IsNegative(): if self.case.IsNegative():
return not self.HasFailed() return not self.HasFailed()
if self.case.IsStrictModeNegative():
return not self.HasFailed()
else: else:
return self.HasFailed() return self.HasFailed()
class TestCase(object): class TestCase(object):
def __init__(self, suite, name, full_path, strict_mode=False): def __init__(self, suite, name, full_path, strict_mode):
self.suite = suite self.suite = suite
self.name = name self.name = name
self.full_path = full_path self.full_path = full_path
self.contents = None self.contents = None
self.is_negative = None self.is_negative = None
self.strict_mode = strict_mode self.strict_mode = strict_mode
self.is_strict_mode_negative = None self.is_strict_only = None
self.is_non_strict_only = None
def GetName(self): def GetName(self):
return path.join(*self.name) return path.join(*self.name)
def GetMode(self):
if self.strict_mode:
return "strict mode"
else:
return "non-strict mode"
def GetPath(self): def GetPath(self):
return self.name return self.name
@ -193,11 +194,15 @@ class TestCase(object):
self.is_negative = ("@negative" in self.GetRawContents()) self.is_negative = ("@negative" in self.GetRawContents())
return self.is_negative return self.is_negative
def IsStrictModeNegative(self): def IsStrictOnly(self):
if self.strict_mode and self.is_strict_mode_negative is None: if self.is_strict_only is None:
self.is_strict_mode_negative = \ self.is_strict_only = ("@strict_only" in self.GetRawContents())
("@strict_mode_negative" in self.GetRawContents()) return self.is_strict_only
return self.is_strict_mode_negative
def IsNonStrictOnly(self):
if self.is_non_strict_only is None:
self.is_non_strict_only = ("@non_strict_only" in self.GetRawContents())
return self.is_non_strict_only
def GetSource(self): def GetSource(self):
source = self.suite.GetInclude("framework.js", False) + \ source = self.suite.GetInclude("framework.js", False) + \
@ -293,12 +298,11 @@ def MakePlural(n):
class TestSuite(object): class TestSuite(object):
def __init__(self, root, stric_mode): def __init__(self, root, strict_only, non_strict_only):
# self.test_root = path.join(root, 'test', 'suite', 'Sputnik', 'Conformance')
# self.test_root = path.join(root, 'test', 'suite', 'other')
self.test_root = path.join(root, 'test', 'suite', 'converted') self.test_root = path.join(root, 'test', 'suite', 'converted')
self.lib_root = path.join(root, 'test', 'harness') self.lib_root = path.join(root, 'test', 'harness')
self.strict_mode = stric_mode self.strict_only = strict_only
self.non_strict_only = non_strict_only
self.include_cache = { } self.include_cache = { }
def Validate(self): def Validate(self):
@ -375,9 +379,14 @@ class TestSuite(object):
if self.ShouldRun(rel_path, tests): if self.ShouldRun(rel_path, tests):
basename = path.basename(full_path)[:-3] basename = path.basename(full_path)[:-3]
name = rel_path.split(path.sep)[:-1] + [basename] name = rel_path.split(path.sep)[:-1] + [basename]
cases.append(TestCase(self, name, full_path, False)) if not self.non_strict_only:
if self.strict_mode: strict_case = TestCase(self, name, full_path, True)
cases.append(TestCase(self, name, full_path, True)) if not strict_case.IsNonStrictOnly():
cases.append(strict_case)
if not self.strict_only:
non_strict_case = TestCase(self, name, full_path, False)
if not non_strict_case.IsStrictOnly():
cases.append(non_strict_case)
logging.info("Done listing tests") logging.info("Done listing tests")
return cases return cases
@ -401,12 +410,12 @@ class TestSuite(object):
print print
print "Failed tests" print "Failed tests"
for result in positive: for result in positive:
print " %s" % result.case.GetName() print " %s in %s" % (result.case.GetName(), result.case.GetMode())
if len(negative) > 0: if len(negative) > 0:
print print
print "Expected to fail but passed ---" print "Expected to fail but passed ---"
for result in negative: for result in negative:
print " %s" % result.case.GetName() print " %s in %s" % (result.case.GetName(), result.case.GetMode())
def PrintFailureOutput(self, progress): def PrintFailureOutput(self, progress):
for result in progress.failed_tests: for result in progress.failed_tests:
@ -512,7 +521,9 @@ def Main():
parser = BuildOptions() parser = BuildOptions()
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
ValidateOptions(options) ValidateOptions(options)
test_suite = TestSuite(options.tests, options.enable_strict_mode) test_suite = TestSuite(options.tests,
options.strict_only,
options.non_strict_only)
test_suite.Validate() test_suite.Validate()
if options.cat: if options.cat:
test_suite.Print(args) test_suite.Print(args)