tools: enforce restriction on YAML negative key

The phase field must precede the type field for negative tests
to have a consistent style and be able to parse easier.
Related to the goal of https://github.com/tc39/test262/issues/1997

Added this check to the linting script and updated tests accordingly.
This commit is contained in:
Csaba Osztrogonác 2022-01-06 13:01:51 +01:00 committed by Rick Waldron
parent 9aedfd146d
commit 00f682e746
41 changed files with 66 additions and 40 deletions

View File

@ -159,10 +159,10 @@ single line comment syntax.
#### negative
`negative: [dictionary containing "phase" and "type" keys]`
This means the test is expected to throw an error of the given type. If no error is thrown, a test failure is reported.
This means the test is expected to throw an error of the given type. If no error is thrown, a test failure is reported. The **phase** field must precede the **type** field.
- **type** - If an error is thrown, it is implicitly converted to a string. In order for the test to pass, this value must match the name of the error constructor.
- **phase** - Negative tests whose **phase** value is "parse" must produce the specified error prior to executing code. The value "resolution" indicates that the error is expected to result while performing ES2015 module resolution. The value "runtime" dictates that the error is expected to be produced as a result of executing the test code.
- **type** - If an error is thrown, it is implicitly converted to a string. In order for the test to pass, this value must match the name of the error constructor.
For best practices on how to use the negative key please see [Handling Errors and Negative Test Cases](#handling-errors-and-negative-test-cases), below.

View File

@ -7,8 +7,8 @@ description: >
reserved word or a future reserved word is made inside a strict
mode FunctionBody of a PropertyAssignment
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [noStrict]
---*/

View File

@ -6,8 +6,8 @@ description: >
Strict Mode - SyntaxError is thrown when an assignment to a
reserved word or a future reserved word is contained in strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [onlyStrict]
---*/

View File

@ -7,8 +7,8 @@ description: >
reserved word is made in a strict FunctionBody of a
PropertyAssignment
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [noStrict]
---*/

View File

@ -6,8 +6,8 @@ description: >
Strict Mode - SyntaxError is thrown when an assignment to a
reserved word is contained in strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [onlyStrict]
---*/

View File

@ -7,8 +7,8 @@ description: >
the Identifier in a PropertySetParameterList of a
PropertyAssignment if its FunctionBody is strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [noStrict]
---*/

View File

@ -7,8 +7,8 @@ description: >
Identifier in a PropertySetParameterList of a PropertyAssignment
that is contained in strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [onlyStrict]
---*/

View File

@ -7,8 +7,8 @@ description: >
Identifier in a PropertySetParameterList of a PropertyAssignment
if its FunctionBody is strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [noStrict]
---*/

View File

@ -7,8 +7,8 @@ description: >
Identifier in a PropertySetParameterList of a PropertyAssignment
that is contained in strict code
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [onlyStrict]
---*/

View File

@ -10,8 +10,8 @@ info: |
SuperCall OptionalChain
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -13,8 +13,8 @@ info: |
It is a Syntax Error if any code matches this production.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -12,8 +12,8 @@ info: |
Return false.
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -12,8 +12,8 @@ info: |
--UnaryExpression
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -12,8 +12,8 @@ info: |
--UnaryExpression
features: [optional-chaining]
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -11,8 +11,8 @@ description: >
MemberExpression[?Yield, ?Await] . IdentifierName
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -7,8 +7,8 @@ description: Test VERTICAL TILDE (U+2E2F) is not recognized as ID_Continue chara
info: |
VERTICAL TILDE is in General Category 'Lm' and [:Pattern_Syntax:].
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -7,8 +7,8 @@ description: Test VERTICAL TILDE (U+2E2F) is not recognized as ID_Continue chara
info: |
VERTICAL TILDE is in General Category 'Lm' and [:Pattern_Syntax:].
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -7,8 +7,8 @@ description: Test VERTICAL TILDE (U+2E2F) is not recognized as ID_Start characte
info: |
VERTICAL TILDE is in General Category 'Lm' and [:Pattern_Syntax:].
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -7,8 +7,8 @@ description: Test VERTICAL TILDE (U+2E2F) is not recognized as ID_Start characte
info: |
VERTICAL TILDE is in General Category 'Lm' and [:Pattern_Syntax:].
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -1,4 +1,5 @@
import re
import yaml
from ..check import Check
_THROW_STMT = re.compile(
@ -39,3 +40,13 @@ class CheckNegative(Check):
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'
for event in meta.parsing_events:
if isinstance(event, yaml.ScalarEvent):
if event.value == 'type':
line_type = event.start_mark.line
elif event.value == 'phase':
line_phase = event.start_mark.line
if line_phase > line_type:
return '"phase" field must precede "type" field'

View File

@ -7,8 +7,8 @@ esid: sec-assignment-operators-static-semantics-early-errors
description: Extraneous field in "negative" frontmatter
negative:
flags: strict
type: ReferenceError
phase: runtime
type: ReferenceError
---*/
x;

View File

@ -6,8 +6,8 @@ NEGATIVE
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: early
type: SyntaxError
flags: [raw]
---*/

View File

@ -0,0 +1,15 @@
NEGATIVE
^ expected errors | v input
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
---*/
$DONOTEVALUATE();
!!!

View File

@ -5,8 +5,8 @@
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -6,8 +6,8 @@ NEGATIVE
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
throw "Test262: This statement should not be evaluated!";

View File

@ -6,8 +6,8 @@ NEGATIVE
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE(1);

View File

@ -6,8 +6,8 @@ NEGATIVE
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
!!!

View File

@ -5,8 +5,8 @@
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [raw]
---*/

View File

@ -6,8 +6,8 @@ NEGATIVE
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
flags: [raw]
---*/

View File

@ -7,8 +7,8 @@ esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [module]
negative:
type: SyntaxError
phase: resolution
type: SyntaxError
---*/
$DONOTEVALUATE(1);

View File

@ -7,8 +7,8 @@ esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [module]
negative:
type: SyntaxError
phase: resolution
type: SyntaxError
---*/
import 'non-existent-module.js';

View File

@ -5,8 +5,8 @@
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -6,8 +6,8 @@ esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [module]
negative:
type: SyntaxError
phase: resolution
type: SyntaxError
---*/
$DONOTEVALUATE();

View File

@ -5,8 +5,8 @@
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: ReferenceError
phase: runtime
type: ReferenceError
---*/
x;