Skip to content

Commit 5b54058

Browse files
committed
Enable configuration of templates for generated tests. Fixes tc39gh-1049
1 parent 99ceda4 commit 5b54058

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+708
-14
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ Test cases and test templates specify meta-data using the same YAML frontmatter
385385
### test cases (`*.case`)
386386
Field | Description
387387
------|-------------
388-
`template` | name of the sub-directory to locate templates for this test
388+
`template` | a template file, directory or glob expression.
389+
`templates` | a list of template file, directory or glob expressions.
389390
`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.
390391
`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.
391392
`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.

tools/generation/lib/case.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ def _parse(self, source):
2222
region_name = None
2323
region_start = 0
2424
lines = source.split('\n')
25-
matches = re.finditer(metaPattern, source, re.MULTILINE)
25+
search = re.search(metaPattern, source, re.DOTALL|re.MULTILINE)
2626

27-
for matchNum, match in enumerate(matches, start=1):
28-
meta = "{match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())
27+
if search:
28+
meta = search.group()
2929
meta = parse_yaml(meta[2:-2])
3030
if meta and not case['meta']:
3131
case['meta'] = meta
32-
break
3332

3433
for comment in find_comments(source):
3534
match = regionStartPattern.match(comment['source'])

tools/generation/lib/expander.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ def expand(self, encoding, case_file = None):
6060

6161
def expand_case(self, file_name, encoding):
6262
case = Case(file_name, encoding)
63+
localtemplates = [];
6364

64-
template_class = case.attribs['meta']['template']
65-
templates = self.templates.get(template_class)
65+
if 'template' in case.attribs['meta']:
66+
localtemplates.append(case.attribs['meta']['template'])
6667

67-
for template in self._get_templates(template_class, encoding):
68-
yield template.expand(file_name, os.path.basename(file_name[:-5]), case.attribs, encoding)
68+
if 'templates' in case.attribs['meta']:
69+
localtemplates.extend(case.attribs['meta']['templates'])
70+
71+
for t in localtemplates:
72+
template_class = t
73+
templates = self.templates.get(template_class)
74+
75+
for template in self._get_templates(template_class, encoding):
76+
yield template.expand(file_name, os.path.basename(file_name[:-5]), case.attribs, encoding)

tools/generation/test/expected/glob/normal/a-nested/path2-glob-expr.js tools/generation/test/expected/glob-expr/normal/a-nested/path2-glob-expr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file was procedurally generated from the following sources:
22
// - tools/generation/test/fixtures/glob-expr.case
3-
// - tools/generation/test/fixtures/glob/a/normal2.template
3+
// - tools/generation/test/fixtures/glob-expr/a/normal2.template
44
/*---
55
description: foobar (Second template name)
66
esid: sec-a-generic-id

tools/generation/test/expected/glob/normal/a-path1-glob-expr.js tools/generation/test/expected/glob-expr/normal/a-path1-glob-expr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file was procedurally generated from the following sources:
22
// - tools/generation/test/fixtures/glob-expr.case
3-
// - tools/generation/test/fixtures/glob/a/normal.template
3+
// - tools/generation/test/fixtures/glob-expr/a/normal.template
44
/*---
55
description: foobar (First template name)
66
es6id: 1.2.3

tools/generation/test/expected/glob/normal/b-nested/path2-glob-expr.js tools/generation/test/expected/glob-expr/normal/b-nested/path2-glob-expr.js

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

tools/generation/test/expected/glob/normal/b-path1-glob-expr.js tools/generation/test/expected/glob-expr/normal/b-path1-glob-expr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file was procedurally generated from the following sources:
22
// - tools/generation/test/fixtures/glob-expr.case
3-
// - tools/generation/test/fixtures/glob/b/normal.template
3+
// - tools/generation/test/fixtures/glob-expr/b/normal.template
44
/*---
55
description: foobar (First template name)
66
es6id: 1.2.3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/glob/normal.template
4+
/*---
5+
description: foobar (First template name)
6+
es6id: 1.2.3
7+
flags: [generated, a, b, c, d]
8+
includes: [foo.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after
16+
17+
before*Second value*between*First value*after
18+
19+
before/* " */Third value (Special characters like `≠` should be tolerated.)after
20+
21+
// Special characters like `≠` should be tolerated.
22+
23+
The following should not be expanded:
24+
25+
/* */*{ first }*/
26+
/*
27+
*/*{ first }*/
28+
//*{ first }*/
29+
// /*{ first }*/
30+
Quote characters: " ' `
31+
"Quote characters: ' ' `"
32+
'Quote characters: " " `'
33+
`
34+
Quote characters: " ' '`
35+
36+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/glob/normal2.template
4+
/*---
5+
description: foobar (Second template name)
6+
esid: sec-a-generic-id
7+
flags: [generated, a, b]
8+
includes: [foo.js, bar.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-Third value (Special characters like `≠` should be tolerated.)Second value-after
16+
17+
/* Improperly-terminated comments should not break the tokenizer *
18+
19+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/a/normal2.template
4+
/*---
5+
description: foobar (Second template name)
6+
esid: sec-a-generic-id
7+
flags: [generated, a, b]
8+
includes: [foo.js, bar.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-Third value (Special characters like `≠` should be tolerated.)Second value-after
16+
17+
/* Improperly-terminated comments should not break the tokenizer *
18+
19+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/a/no-info.template
4+
/*---
5+
description: foobar (First template name)
6+
es6id: 1.2.3
7+
flags: [generated, a, b]
8+
includes: [foo.js]
9+
info: |
10+
case info
11+
---*/
12+
13+
First value
14+
15+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/a/normal.template
4+
/*---
5+
description: foobar (First template name)
6+
es6id: 1.2.3
7+
flags: [generated, a, b, c, d]
8+
includes: [foo.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after
16+
17+
before*Second value*between*First value*after
18+
19+
before/* " */Third value (Special characters like `≠` should be tolerated.)after
20+
21+
// Special characters like `≠` should be tolerated.
22+
23+
The following should not be expanded:
24+
25+
/* */*{ first }*/
26+
/*
27+
*/*{ first }*/
28+
//*{ first }*/
29+
// /*{ first }*/
30+
Quote characters: " ' `
31+
"Quote characters: ' ' `"
32+
'Quote characters: " " `'
33+
`
34+
Quote characters: " ' '`
35+
36+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/b/features.template
4+
/*---
5+
description: foobar (First template name)
6+
es6id: 1.2.3
7+
features: [f1]
8+
flags: [generated, a, b]
9+
includes: [foo.js]
10+
info: |
11+
case info
12+
---*/
13+
14+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/b/normal2.template
4+
/*---
5+
description: foobar (Second template name)
6+
esid: sec-a-generic-id
7+
flags: [generated, a, b]
8+
includes: [foo.js, bar.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-Third value (Special characters like `≠` should be tolerated.)Second value-after
16+
17+
/* Improperly-terminated comments should not break the tokenizer *
18+
19+
'This is "teardown" code.';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file was procedurally generated from the following sources:
2+
// - tools/generation/test/fixtures/multiple-templates.case
3+
// - tools/generation/test/fixtures/multiple/b/normal.template
4+
/*---
5+
description: foobar (First template name)
6+
es6id: 1.2.3
7+
flags: [generated, a, b, c, d]
8+
includes: [foo.js]
9+
info: |
10+
template info
11+
12+
case info
13+
---*/
14+
15+
before-First value-between-Third value (Special characters like `≠` should be tolerated.)-after
16+
17+
before*Second value*between*First value*after
18+
19+
before/* " */Third value (Special characters like `≠` should be tolerated.)after
20+
21+
// Special characters like `≠` should be tolerated.
22+
23+
The following should not be expanded:
24+
25+
/* */*{ first }*/
26+
/*
27+
*/*{ first }*/
28+
//*{ first }*/
29+
// /*{ first }*/
30+
Quote characters: " ' `
31+
"Quote characters: ' ' `"
32+
'Quote characters: " " `'
33+
`
34+
Quote characters: " ' '`
35+
36+
'This is "teardown" code.';

tools/generation/test/fixtures/glob-expr.case

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2016 the V8 project authors. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33
/*---
4-
template: glob/**/normal*.template
4+
template: glob-expr/**/normal*.template
55
desc: foobar
66
info: case info
77
flags: [a, b]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: First template name
5+
path: glob-expr/normal/a-features-
6+
es6id: 1.2.3
7+
features: [f1]
8+
---*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: First template name
5+
path: glob-expr/normal/a-info-multiline-folding-
6+
es6id: 1.2.3
7+
info: |
8+
This is an "info" field with an
9+
10+
empty line
11+
Trailing white space in the template:
12+
should be preserved:
13+
14+
15+
16+
17+
18+
19+
20+
---*/
21+
22+
// Trailing white space in the test body:
23+
// should be preserved:
24+
25+
26+
27+
28+
29+
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: First template name
5+
path: glob-expr/normal/a-no-info-
6+
es6id: 1.2.3
7+
---*/
8+
9+
/*{ first }*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: First template name
5+
path: glob-expr/normal/a-path1-
6+
es6id: 1.2.3
7+
info: template info
8+
flags: [c, d]
9+
---*/
10+
11+
before-/*{ first }*/-between-/*{ third }*/-after
12+
13+
before*/*{ second }*/*between*/*{ first }*/*after
14+
15+
before/* " *//*{ third }*/after
16+
17+
// Special characters like `≠` should be tolerated.
18+
19+
The following should not be expanded:
20+
21+
/* */*{ first }*/
22+
/*
23+
*/*{ first }*/
24+
//*{ first }*/
25+
// /*{ first }*/
26+
/*{ fourth }*/
27+
"/*{ fourth }*/"
28+
'/*{ fourth }*/'
29+
`
30+
/*{ fourth }*/`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: Second template name
5+
path: glob-expr/normal/a-nested/path2-
6+
esid: sec-a-generic-id
7+
includes: [bar.js]
8+
info: template info
9+
---*/
10+
11+
before-/*{ third }*//*{ second }*/-after
12+
13+
/* Improperly-terminated comments should not break the tokenizer *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (C) 2016 the V8 project authors. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
name: First template name
5+
path: glob-expr/normal/b-features-
6+
es6id: 1.2.3
7+
features: [f1]
8+
---*/

0 commit comments

Comments
 (0)