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

This commit is contained in:
Rick Waldron 2020-09-24 16:51:49 -04:00
parent 99ceda42a4
commit 5b54058ad7
43 changed files with 708 additions and 14 deletions

View File

@ -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.

View File

@ -22,14 +22,13 @@ class Case:
region_name = None
region_start = 0
lines = source.split('\n')
matches = re.finditer(metaPattern, source, re.MULTILINE)
search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
meta = "{match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())
if search:
meta = search.group()
meta = parse_yaml(meta[2:-2])
if meta and not case['meta']:
case['meta'] = meta
break
for comment in find_comments(source):
match = regionStartPattern.match(comment['source'])

View File

@ -60,9 +60,17 @@ class Expander:
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)

View File

@ -1,6 +1,6 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob/a/normal2.template
// - tools/generation/test/fixtures/glob-expr/a/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id

View File

@ -1,6 +1,6 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob/a/normal.template
// - tools/generation/test/fixtures/glob-expr/a/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3

View File

@ -1,6 +1,6 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob/b/normal2.template
// - tools/generation/test/fixtures/glob-expr/b/normal2.template
/*---
description: foobar (Second template name)
esid: sec-a-generic-id

View File

@ -1,6 +1,6 @@
// This file was procedurally generated from the following sources:
// - tools/generation/test/fixtures/glob-expr.case
// - tools/generation/test/fixtures/glob/b/normal.template
// - tools/generation/test/fixtures/glob-expr/b/normal.template
/*---
description: foobar (First template name)
es6id: 1.2.3

View File

@ -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.';

View File

@ -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.';

View File

@ -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.';

View File

@ -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.';

View File

@ -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.';

View File

@ -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.';

View File

@ -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.';

View File

@ -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/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.';

View File

@ -1,7 +1,7 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
template: glob/**/normal*.template
template: glob-expr/**/normal*.template
desc: foobar
info: case info
flags: [a, b]

View File

@ -0,0 +1,8 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/a-features-
es6id: 1.2.3
features: [f1]
---*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/a-info-multiline-folding-
es6id: 1.2.3
info: |
This is an "info" field with an
empty line
Trailing white space in the template:
should be preserved:
---*/
// Trailing white space in the test body:
// should be preserved:

View File

@ -0,0 +1,9 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/a-no-info-
es6id: 1.2.3
---*/
/*{ first }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/a-path1-
es6id: 1.2.3
info: template info
flags: [c, d]
---*/
before-/*{ first }*/-between-/*{ third }*/-after
before*/*{ second }*/*between*/*{ first }*/*after
before/* " *//*{ third }*/after
// Special characters like `≠` should be tolerated.
The following should not be expanded:
/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
/*{ fourth }*/
"/*{ fourth }*/"
'/*{ fourth }*/'
`
/*{ fourth }*/`

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: Second template name
path: glob-expr/normal/a-nested/path2-
esid: sec-a-generic-id
includes: [bar.js]
info: template info
---*/
before-/*{ third }*//*{ second }*/-after
/* Improperly-terminated comments should not break the tokenizer *

View File

@ -0,0 +1,8 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/b-features-
es6id: 1.2.3
features: [f1]
---*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/b-info-multiline-folding-
es6id: 1.2.3
info: |
This is an "info" field with an
empty line
Trailing white space in the template:
should be preserved:
---*/
// Trailing white space in the test body:
// should be preserved:

View File

@ -0,0 +1,9 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/b-no-info-
es6id: 1.2.3
---*/
/*{ first }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: glob-expr/normal/b-path1-
es6id: 1.2.3
info: template info
flags: [c, d]
---*/
before-/*{ first }*/-between-/*{ third }*/-after
before*/*{ second }*/*between*/*{ first }*/*after
before/* " *//*{ third }*/after
// Special characters like `≠` should be tolerated.
The following should not be expanded:
/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
/*{ fourth }*/
"/*{ fourth }*/"
'/*{ fourth }*/'
`
/*{ fourth }*/`

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: Second template name
path: glob-expr/normal/b-nested/path2-
esid: sec-a-generic-id
includes: [bar.js]
info: template info
---*/
before-/*{ third }*//*{ second }*/-after
/* Improperly-terminated comments should not break the tokenizer *

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
templates:
- multiple/**/normal*.template
- multiple/b/features.template
- multiple/a/no-info.template
desc: foobar
info: case info
flags: [a, b]
includes: [foo.js]
---*/
Because this test appears before any "region" delimiters, it should not appear
in the generated files.
// - first
this is not a valid region delimiter
/* *//- first
this is also not a valid region delimiter
//- first
First value
//- second
Second value
//- third
Third value (Special characters like `≠` should be tolerated.)
//- fourth
Quote characters: " ' `
//- teardown
'This is "teardown" code.';

View File

@ -0,0 +1,8 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/a-features-
es6id: 1.2.3
features: [f1]
---*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/a-info-multiline-folding-
es6id: 1.2.3
info: |
This is an "info" field with an
empty line
Trailing white space in the template:
should be preserved:
---*/
// Trailing white space in the test body:
// should be preserved:

View File

@ -0,0 +1,9 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/a-no-info-
es6id: 1.2.3
---*/
/*{ first }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/a-path1-
es6id: 1.2.3
info: template info
flags: [c, d]
---*/
before-/*{ first }*/-between-/*{ third }*/-after
before*/*{ second }*/*between*/*{ first }*/*after
before/* " *//*{ third }*/after
// Special characters like `≠` should be tolerated.
The following should not be expanded:
/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
/*{ fourth }*/
"/*{ fourth }*/"
'/*{ fourth }*/'
`
/*{ fourth }*/`

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: Second template name
path: multiple/normal/a-nested/path2-
esid: sec-a-generic-id
includes: [bar.js]
info: template info
---*/
before-/*{ third }*//*{ second }*/-after
/* Improperly-terminated comments should not break the tokenizer *

View File

@ -0,0 +1,8 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/b-features-
es6id: 1.2.3
features: [f1]
---*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/b-info-multiline-folding-
es6id: 1.2.3
info: |
This is an "info" field with an
empty line
Trailing white space in the template:
should be preserved:
---*/
// Trailing white space in the test body:
// should be preserved:

View File

@ -0,0 +1,9 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/b-no-info-
es6id: 1.2.3
---*/
/*{ first }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/normal/b-path1-
es6id: 1.2.3
info: template info
flags: [c, d]
---*/
before-/*{ first }*/-between-/*{ third }*/-after
before*/*{ second }*/*between*/*{ first }*/*after
before/* " *//*{ third }*/after
// Special characters like `≠` should be tolerated.
The following should not be expanded:
/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
/*{ fourth }*/
"/*{ fourth }*/"
'/*{ fourth }*/'
`
/*{ fourth }*/`

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: Second template name
path: multiple/normal/b-nested/path2-
esid: sec-a-generic-id
includes: [bar.js]
info: template info
---*/
before-/*{ third }*//*{ second }*/-after
/* Improperly-terminated comments should not break the tokenizer *

View File

@ -0,0 +1,8 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/glob/features-
es6id: 1.2.3
features: [f1]
---*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/glob/normal/info-multiline-folding-
es6id: 1.2.3
info: |
This is an "info" field with an
empty line
Trailing white space in the template:
should be preserved:
---*/
// Trailing white space in the test body:
// should be preserved:

View File

@ -0,0 +1,9 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/glob/normal/no-info-
es6id: 1.2.3
---*/
/*{ first }*/

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: First template name
path: multiple/glob/normal-
es6id: 1.2.3
info: template info
flags: [c, d]
---*/
before-/*{ first }*/-between-/*{ third }*/-after
before*/*{ second }*/*between*/*{ first }*/*after
before/* " *//*{ third }*/after
// Special characters like `≠` should be tolerated.
The following should not be expanded:
/* */*{ first }*/
/*
*/*{ first }*/
//*{ first }*/
// /*{ first }*/
/*{ fourth }*/
"/*{ fourth }*/"
'/*{ fourth }*/'
`
/*{ fourth }*/`

View File

@ -0,0 +1,13 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
name: Second template name
path: multiple/glob/normal2-
esid: sec-a-generic-id
includes: [bar.js]
info: template info
---*/
before-/*{ third }*//*{ second }*/-after
/* Improperly-terminated comments should not break the tokenizer *

View File

@ -54,6 +54,16 @@ class TestGeneration(unittest.TestCase):
self.assertEqual(result['returncode'], 0)
self.compareTrees('glob')
def test_glob_expr(self):
result = self.fixture('glob-expr.case')
self.assertEqual(result['returncode'], 0)
self.compareTrees('glob-expr')
def test_multiple_templates(self):
result = self.fixture('multiple-templates.case')
self.assertEqual(result['returncode'], 0)
self.compareTrees('multiple-templates')
def test_normal(self):
result = self.fixture('normal.case')
self.assertEqual(result['returncode'], 0)