Skip to content
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

Enable configuration of templates for generated tests. Fixes gh-1049 #2822

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -385,7 +385,8 @@ Test cases and test templates specify meta-data using the same YAML frontmatter
### test cases (`*.case`)
Field | Description
------|-------------
`template` | name of the sub-directory to locate templates for this test
`template` | a template file, directory or glob expression.
`templates` | a list of template file, directory or glob expressions.
`desc` | see the frontmatter definition of the "desc" field. The generated test will have a have final "desc" value which is this text appended with the test template's "name" field in parentheses.
`info` | see the frontmatter definition of the "info" field. The generated test will have a have final "info" value which is this text concatenated at the end of the test templates's "info" text.
`features` | see the frontmatter definition of the "features" field. The generated test will have a final feature list in combination with the template's feature field.
Expand Down
11 changes: 7 additions & 4 deletions tools/generation/lib/case.py
Expand Up @@ -8,6 +8,7 @@
from .util.parse_yaml import parse_yaml

regionStartPattern = re.compile(r'-\s+(\S+)')
metaPattern = r'\/\*---\n([\s]*)((?:\s|\S)*)[\n\s*]---\*\/'

class Case:
def __init__(self, file_name, encoding):
Expand All @@ -21,13 +22,15 @@ def _parse(self, source):
region_name = None
region_start = 0
lines = source.split('\n')
search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE)

for comment in find_comments(source):
meta = parse_yaml(comment['source'])
if meta:
if search:
meta = search.group()
meta = parse_yaml(meta[2:-2])
if meta and not case['meta']:
case['meta'] = meta
continue

for comment in find_comments(source):
match = regionStartPattern.match(comment['source'])
if match:
if region_name:
Expand Down
31 changes: 21 additions & 10 deletions tools/generation/lib/expander.py
Expand Up @@ -19,12 +19,15 @@ def _load_templates(self, template_class, encoding):
file_names = []

for expanded_directory in glob.glob(directory):
file_names.extend(
map(
lambda x: os.path.join(expanded_directory, x),
filter(self.is_template_file, os.listdir(expanded_directory))
try:
file_names.extend(
map(
lambda x: os.path.join(expanded_directory, x),
filter(self.is_template_file, os.listdir(expanded_directory))
)
)
)
except:
file_names.append(expanded_directory)

self.templates[template_class] = [
Template(x, encoding) for x in file_names
Expand All @@ -37,7 +40,7 @@ def _get_templates(self, template_class, encoding):
return self.templates[template_class]

def is_template_file(self, filename):
return re.match(templateFilenamePattern, filename)
return re.match(templateFilenamePattern, filename)

def list_cases(self):
for name in os.listdir(self.case_dir):
Expand All @@ -57,9 +60,17 @@ def expand(self, encoding, case_file = None):

def expand_case(self, file_name, encoding):
case = Case(file_name, encoding)
localtemplates = [];

template_class = case.attribs['meta']['template']
templates = self.templates.get(template_class)
if 'template' in case.attribs['meta']:
localtemplates.append(case.attribs['meta']['template'])

for template in self._get_templates(template_class, encoding):
yield template.expand(file_name, os.path.basename(file_name[:-5]), case.attribs, encoding)
if 'templates' in case.attribs['meta']:
localtemplates.extend(case.attribs['meta']['templates'])

for t in localtemplates:
template_class = t
templates = self.templates.get(template_class)

for template in self._get_templates(template_class, encoding):
yield template.expand(file_name, os.path.basename(file_name[:-5]), case.attribs, encoding)
@@ -0,0 +1,19 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob-expr/a/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id
flags: [generated, a, b]
includes: [foo.js, bar.js]
info: |
template info

case info
---*/

before-Third value (Special characters like `≠` should be tolerated.)Second value-after

/* Improperly-terminated comments should not break the tokenizer *

'This is "teardown" code.';
@@ -0,0 +1,36 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob-expr/a/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3
flags: [generated, a, b, c, d]
includes: [foo.js]
info: |
template info

case info
---*/

before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after

before*Second value*between*First value*after

before/* " */Third value (Special characters like `≠` should be tolerated.)after

// Special characters like `≠` should be tolerated.

The following should not be expanded:

/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
Quote characters: " ' `
"Quote characters: ' ' `"
'Quote characters: " " `'
`
Quote characters: " ' '`

'This is "teardown" code.';
@@ -0,0 +1,19 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob-expr/b/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id
flags: [generated, a, b]
includes: [foo.js, bar.js]
info: |
template info

case info
---*/

before-Third value (Special characters like `≠` should be tolerated.)Second value-after

/* Improperly-terminated comments should not break the tokenizer *

'This is "teardown" code.';
@@ -0,0 +1,36 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob-expr/b/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3
flags: [generated, a, b, c, d]
includes: [foo.js]
info: |
template info

case info
---*/

before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after

before*Second value*between*First value*after

before/* " */Third value (Special characters like `≠` should be tolerated.)after

// Special characters like `≠` should be tolerated.

The following should not be expanded:

/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
Quote characters: " ' `
"Quote characters: ' ' `"
'Quote characters: " " `'
`
Quote characters: " ' '`

'This is "teardown" code.';
@@ -0,0 +1,36 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/glob/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3
flags: [generated, a, b, c, d]
includes: [foo.js]
info: |
template info

case info
---*/

before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after

before*Second value*between*First value*after

before/* " */Third value (Special characters like `≠` should be tolerated.)after

// Special characters like `≠` should be tolerated.

The following should not be expanded:

/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
Quote characters: " ' `
"Quote characters: ' ' `"
'Quote characters: " " `'
`
Quote characters: " ' '`

'This is "teardown" code.';
@@ -0,0 +1,19 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/glob/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id
flags: [generated, a, b]
includes: [foo.js, bar.js]
info: |
template info

case info
---*/

before-Third value (Special characters like `≠` should be tolerated.)Second value-after

/* Improperly-terminated comments should not break the tokenizer *

'This is "teardown" code.';
@@ -0,0 +1,19 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/a/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id
flags: [generated, a, b]
includes: [foo.js, bar.js]
info: |
template info

case info
---*/

before-Third value (Special characters like `≠` should be tolerated.)Second value-after

/* Improperly-terminated comments should not break the tokenizer *

'This is "teardown" code.';
@@ -0,0 +1,15 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/a/no-info.template
/*---
description: foobar (First template name)
es6id: 1.2.3
flags: [generated, a, b]
includes: [foo.js]
info: |
case info
---*/

First value

'This is "teardown" code.';
@@ -0,0 +1,36 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/a/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3
flags: [generated, a, b, c, d]
includes: [foo.js]
info: |
template info

case info
---*/

before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after

before*Second value*between*First value*after

before/* " */Third value (Special characters like `≠` should be tolerated.)after

// Special characters like `≠` should be tolerated.

The following should not be expanded:

/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
Quote characters: " ' `
"Quote characters: ' ' `"
'Quote characters: " " `'
`
Quote characters: " ' '`

'This is "teardown" code.';
@@ -0,0 +1,14 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/b/features.template
/*---
description: foobar (First template name)
es6id: 1.2.3
features: [f1]
flags: [generated, a, b]
includes: [foo.js]
info: |
case info
---*/

'This is "teardown" code.';
@@ -0,0 +1,19 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/multiple-templates.case
// - tools/generation/test/fixtures/multiple/b/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id
flags: [generated, a, b]
includes: [foo.js, bar.js]
info: |
template info

case info
---*/

before-Third value (Special characters like `≠` should be tolerated.)Second value-after

/* Improperly-terminated comments should not break the tokenizer *

'This is "teardown" code.';