2017-04-29 21:33:06 +02:00
|
|
|
import re
|
|
|
|
from ..check import Check
|
|
|
|
|
|
|
|
_THROW_STMT = re.compile(
|
2018-10-11 16:59:24 +02:00
|
|
|
r'^\$DONOTEVALUATE\(\);$',
|
2017-04-29 21:33:06 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
|
2019-08-09 15:52:40 +02:00
|
|
|
_THROW_STMT_RAW = re.compile(
|
2019-02-05 21:32:34 +01:00
|
|
|
r'^throw "Test262: This statement should not be evaluated\.";$',
|
|
|
|
re.MULTILINE)
|
|
|
|
|
2017-04-29 21:33:06 +02:00
|
|
|
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'
|
|
|
|
|
2021-06-24 19:37:55 +02:00
|
|
|
if len(negative.keys()) > 2:
|
|
|
|
return '"negative" must specify only "type" and "phase" fields'
|
|
|
|
|
2019-03-06 18:24:44 +01:00
|
|
|
if negative["phase"] not in ["parse", "resolution", "runtime"]:
|
|
|
|
return '"phase" must be one of ["parse", "resolution", "runtime"]'
|
|
|
|
|
2019-02-05 21:32:34 +01:00
|
|
|
if negative["phase"] in ["parse", "resolution"]:
|
|
|
|
if meta.get('flags') and 'raw' in meta['flags']:
|
2019-08-09 15:52:40 +02:00
|
|
|
if not _THROW_STMT_RAW.search(source):
|
2019-02-05 21:32:34 +01:00
|
|
|
return 'Negative tests of type "early" must include a `throw` statement'
|
|
|
|
elif not _THROW_STMT.search(source):
|
|
|
|
return 'Negative tests of type "early" must include a $DONOTEVALUATE() call'
|