| 1 |
import re |
| 2 |
from ..check import Check |
| 3 |
|
| 4 |
_THROW_STMT = re.compile( |
| 5 |
r'^throw "Test262: This statement should not be evaluated\.";$', |
| 6 |
re.MULTILINE) |
| 7 |
|
| 8 |
class CheckNegative(Check): |
| 9 |
'''Ensure tests have the expected YAML-formatted metadata.''' |
| 10 |
ID = 'NEGATIVE' |
| 11 |
|
| 12 |
def run(self, name, meta, source): |
| 13 |
if meta is None or meta.get('negative') is None: |
| 14 |
return |
| 15 |
|
| 16 |
negative = meta['negative'] |
| 17 |
if not isinstance(negative, dict): |
| 18 |
return '"negative" must be a dictionary with fields "type" and "phase"' |
| 19 |
|
| 20 |
if not 'type' in negative: |
| 21 |
return '"negative" must specify a "type" field' |
| 22 |
|
| 23 |
if not 'phase' in negative: |
| 24 |
return '"negative" must specify a "phase" field' |
| 25 |
|
| 26 |
if negative["phase"] in ["parse", "resolution"] and not _THROW_STMT.search(source): |
| 27 |
return 'Negative tests of type "early" must include a `throw` statement' |