test262/tools/lint/lib/checks/frontmatter.py
Mike Pennisi 53842533b7 Enforce use of throw stmt in early error tests
Previously, test consumers were encouraged to insert a `throw` statement
as the first statement of tests for early errors. This recommendation
made tests harder to consume, and as an optional transformation,
consumers may have ignored it or simply been unaware it was made. By
explicitly including such a `throw` statement, the tests become more
literal, making them easier to consume and more transparent in their
expectations.

Document expectation for all tests for early errors to include an
explicit `throw` statement. Extend linting script to verify that
contributors are automatically notified of violations and to ensure that
future contributions satisfy this expectation.
2017-06-28 11:24:36 -04:00

32 lines
999 B
Python

from ..check import Check
_REQUIRED_FIELDS = set(['description'])
_OPTIONAL_FIELDS = set([
'author', 'es5id', 'es6id', 'esid', 'features', 'flags', 'includes',
'info', 'negative', 'timeout'
])
_VALID_FIELDS = _REQUIRED_FIELDS | _OPTIONAL_FIELDS
class CheckFrontmatter(Check):
'''Ensure tests have the expected YAML-formatted metadata.'''
ID = 'FRONTMATTER'
def run(self, name, meta, source):
if name.endswith('_FIXTURE.js'):
if meta is not None:
return '"Fixture" files cannot specify metadata'
return
if meta is None:
return 'No valid YAML-formatted frontmatter'
fields = set(meta.keys())
missing = _REQUIRED_FIELDS - fields
if len(missing) > 0:
return 'Required fields missing: %s' % ', '.join(list(missing))
unrecognized = fields - _VALID_FIELDS
if len(unrecognized) > 0:
return 'Unrecognized fields: %s' % ', '.join(list(unrecognized))