-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(manifest): Add initial tooling for Test262 test types [pt 1/5] #56840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jcscottiii
wants to merge
5
commits into
master
Choose a base branch
from
feat/test262-manifest-tooling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
72ff9c7
feat(manifest): Add initial tooling for Test262 test types
jcscottiii 0cf0d25
address @jgraham feedback
jcscottiii 21ff821
be explicit with each property during test
jcscottiii 75b097c
don't use Any
jcscottiii 28a3a4b
fix type hints for earlier python versions
jcscottiii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from __future__ import print_function | ||
|
|
||
| from dataclasses import dataclass | ||
| from logging import Logger | ||
| from typing import Dict, List, Optional, Text, Tuple | ||
|
|
||
| import re | ||
|
|
||
| # Matches trailing whitespace and any following blank lines. | ||
| _BLANK_LINES = r"([ \t]*[\r\n]{1,2})*" | ||
|
|
||
| # Matches the YAML frontmatter block. | ||
| _YAML_PATTERN = re.compile(r"/\*---(.*)---\*/" + _BLANK_LINES, re.DOTALL) | ||
|
|
||
| _STRIP_CONTROL_CHARS = re.compile(r'[\x7f-\x9f]') | ||
|
|
||
|
|
||
|
|
||
| @dataclass | ||
| class TestRecord: | ||
| test: str | ||
| includes: Optional[List[Text]] = None | ||
| negative: Optional[Dict[Text, Text]] = None | ||
| is_only_strict: bool = False | ||
| is_module: bool = False | ||
|
|
||
| def _yaml_attr_parser(logger: Logger, test_record: TestRecord, attrs: Text, name: Text) -> None: | ||
| import yaml | ||
| parsed = yaml.safe_load(re.sub(_STRIP_CONTROL_CHARS, ' ', attrs)) | ||
| if parsed is None: | ||
| logger.error("Failed to parse yaml in name %s" % name) | ||
| return | ||
|
|
||
| for key, value in parsed.items(): | ||
| if key == "negative": | ||
| test_record.negative = value | ||
| elif key == "flags": | ||
| if isinstance(value, list): | ||
| for flag in value: | ||
| if flag == "onlyStrict": | ||
| test_record.is_only_strict = True | ||
| elif flag == "module": | ||
| test_record.is_module = True | ||
| elif key == "includes": | ||
| test_record.includes = value | ||
|
|
||
|
|
||
| def _find_attrs(src: Text) -> Tuple[Optional[Text], Optional[Text]]: | ||
| match = _YAML_PATTERN.search(src) | ||
| if not match: | ||
| return (None, None) | ||
|
|
||
| return (match.group(0), match.group(1).strip()) | ||
|
|
||
|
|
||
| def parse(logger: Logger, src: Text, name: Text) -> Optional[TestRecord]: | ||
| if name.endswith('_FIXTURE.js'): | ||
| return None | ||
|
|
||
| # Find the YAML frontmatter. | ||
| (frontmatter, attrs) = _find_attrs(src) | ||
|
|
||
| # YAML frontmatter is required for all tests. | ||
| if frontmatter is None: | ||
| logger.error("Missing frontmatter: %s" % name) | ||
| return None | ||
|
|
||
| test_record = TestRecord(test = src) | ||
|
|
||
| if attrs: | ||
| _yaml_attr_parser(logger, test_record, attrs, name) | ||
|
|
||
| return test_record | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # mypy: allow-untyped-defs | ||
|
|
||
| import pytest | ||
|
|
||
| from tools.manifest.log import get_logger | ||
| from tools.manifest.test262 import parse, TestRecord | ||
|
|
||
| TestRecord.__test__ = False # type: ignore[attr-defined] | ||
|
|
||
| @pytest.mark.parametrize("name, src, expected_record", [ | ||
| ( | ||
| "test.js", | ||
| """/*--- | ||
| description: A simple test | ||
| features: [Test262] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, | ||
| TestRecord("""/*--- | ||
| description: A simple test | ||
| features: [Test262] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, includes=None, negative=None, is_module=False, is_only_strict=False) | ||
| ), | ||
| ( | ||
| "no_frontmatter.js", | ||
| """assert.sameValue(1, 1);""", | ||
| None | ||
| ), | ||
| ( | ||
| "test_FIXTURE.js", | ||
| """/*--- | ||
| description: A fixture file | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, | ||
| None | ||
| ), | ||
| ( | ||
| "flags-module.js", | ||
| """/*--- | ||
| description: Test with module flag | ||
| flags: [raw, module] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, | ||
| TestRecord("""/*--- | ||
| description: Test with module flag | ||
| flags: [raw, module] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, includes=None, negative=None, is_module=True, is_only_strict=False) | ||
| ), | ||
| ( | ||
| "flags-onlyStrict.js", | ||
| """/*--- | ||
| description: Test with onlyStrict flag | ||
| flags: [raw, onlyStrict] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, | ||
| TestRecord("""/*--- | ||
| description: Test with onlyStrict flag | ||
| flags: [raw, onlyStrict] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, includes=None, negative=None, is_module=False, is_only_strict=True) | ||
| ), | ||
| ( | ||
| "negative.js", | ||
| """/*--- | ||
| description: Negative test | ||
| negative: | ||
| phase: runtime | ||
| type: TypeError | ||
| ---*/ | ||
| throw new TypeError(); | ||
| """, | ||
| TestRecord("""/*--- | ||
| description: Negative test | ||
| negative: | ||
| phase: runtime | ||
| type: TypeError | ||
| ---*/ | ||
| throw new TypeError(); | ||
| """, includes=None, negative={"phase": "runtime", "type": "TypeError"}, is_module=False, is_only_strict=False) | ||
| ), | ||
| ( | ||
| "includes.js", | ||
| """/*--- | ||
| description: Test with includes | ||
| includes: [assert.js, sta.js] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, | ||
| TestRecord("""/*--- | ||
| description: Test with includes | ||
| includes: [assert.js, sta.js] | ||
| ---*/ | ||
| assert.sameValue(1, 1); | ||
| """, includes=["assert.js", "sta.js"], negative=None, is_module=False, is_only_strict=False) | ||
| ), | ||
| ]) | ||
| def test_test262_parser(name, src, expected_record): | ||
| record = parse(get_logger(), src, name) | ||
|
|
||
| assert expected_record == record |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| requests==2.32.3 | ||
| types-requests==2.32.0.20241016 | ||
| pyyaml==6.0.1 | ||
| types-pyyaml==6.0.12.20241230 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.