mirror of
https://github.com/tc39/test262.git
synced 2025-04-08 19:35:28 +02:00
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.
28 lines
905 B
Python
28 lines
905 B
Python
import re
|
|
from ..check import Check
|
|
|
|
_THROW_STMT = re.compile(
|
|
r'^throw "Test262: This statement should not be evaluated\.";$',
|
|
re.MULTILINE)
|
|
|
|
class CheckNegative(Check):
|
|
'''Ensure tests have the expected YAML-formatted metadata.'''
|
|
ID = 'NEGATIVE'
|
|
|
|
def run(self, name, meta, source):
|
|
if meta is None or meta.get('negative') is None:
|
|
return
|
|
|
|
negative = meta['negative']
|
|
if not isinstance(negative, dict):
|
|
return '"negative" must be a dictionary with fields "type" and "phase"'
|
|
|
|
if not 'type' in negative:
|
|
return '"negative" must specify a "type" field'
|
|
|
|
if not 'phase' in negative:
|
|
return '"negative" must specify a "phase" field'
|
|
|
|
if negative["phase"] == "early" and not _THROW_STMT.search(source):
|
|
return 'Negative tests of type "early" must include a `throw` statement'
|