From 95d51c4a152d7c77d09572ed0353a9806a00bbab Mon Sep 17 00:00:00 2001 From: Rick Waldron <waldron.rick@gmail.com> Date: Thu, 3 Sep 2020 10:57:17 -0400 Subject: [PATCH] Generation: don't make negative parse SyntaxError tests that have flags: [async]. Fixes gh-1229 --- tools/generation/lib/template.py | 20 ++++++++++--------- ...tion-declaration-async-negative-invalid.js | 17 ++++++++++++++++ .../test/fixtures/async-negative-invalid.case | 15 ++++++++++++++ .../test/fixtures/async/async.template | 13 ++++++++++++ tools/generation/test/run.py | 5 +++++ 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 tools/generation/test/expected/async/async-function-declaration-async-negative-invalid.js create mode 100644 tools/generation/test/fixtures/async-negative-invalid.case create mode 100644 tools/generation/test/fixtures/async/async.template diff --git a/tools/generation/lib/template.py b/tools/generation/lib/template.py index 16eb2ccd92..b50b19d778 100644 --- a/tools/generation/lib/template.py +++ b/tools/generation/lib/template.py @@ -156,10 +156,20 @@ class Template: if len(features): lines += ['features: ' + re.sub('\n\s*', ' ', yaml.dump(features, default_flow_style=True).strip())] + # Reconcile "negative" meta data before "flags" + if case_values['meta'].get('negative'): + if self.attribs['meta'].get('negative'): + raise Exception('Cannot specify negative in case and template file') + negative = case_values['meta'].get('negative') + else: + negative = self.attribs['meta'].get('negative') + flags = ['generated'] flags += case_values['meta'].get('flags', []) flags += self.attribs['meta'].get('flags', []) flags = list(OrderedDict.fromkeys(flags)) + if 'async' in flags and negative and negative.get('phase') == 'parse' and negative.get('type') == 'SyntaxError': + flags.remove('async') lines += ['flags: ' + re.sub('\n\s*', ' ', yaml.dump(flags, default_flow_style=True).strip())] includes = [] @@ -169,17 +179,9 @@ class Template: if len(includes): lines += ['includes: ' + re.sub('\n\s*', ' ', yaml.dump(includes, default_flow_style=True).strip())] - if case_values['meta'].get('negative'): - if self.attribs['meta'].get('negative'): - raise Exception('Cannot specify negative in case and template file') - negative = case_values['meta'].get('negative') - else: - negative = self.attribs['meta'].get('negative') - if negative: lines += ['negative:'] - as_yaml = yaml.dump(negative, - default_flow_style=False) + as_yaml = yaml.dump(negative, default_flow_style=False) lines += indent(as_yaml.strip(), ' ').split('\n') info = [] diff --git a/tools/generation/test/expected/async/async-function-declaration-async-negative-invalid.js b/tools/generation/test/expected/async/async-function-declaration-async-negative-invalid.js new file mode 100644 index 0000000000..e0b47db345 --- /dev/null +++ b/tools/generation/test/expected/async/async-function-declaration-async-negative-invalid.js @@ -0,0 +1,17 @@ +// This file was procedurally generated from the following sources: +// - tools/generation/test/fixtures/async-negative-invalid.case +// - tools/generation/test/fixtures/async/async.template +/*--- +description: Early SyntaxError tests should not include "async" in flags[] (async function declaration) +esid: prod-AsyncFunctionDeclaration +flags: [generated] +negative: + phase: parse + type: SyntaxError +---*/ +$DONOTEVALUATE(); + +async function fn() { + await 1; + 1=1; +} diff --git a/tools/generation/test/fixtures/async-negative-invalid.case b/tools/generation/test/fixtures/async-negative-invalid.case new file mode 100644 index 0000000000..708c881a51 --- /dev/null +++ b/tools/generation/test/fixtures/async-negative-invalid.case @@ -0,0 +1,15 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +desc: Early SyntaxError tests should not include "async" in flags[] +template: async +negative: + phase: parse + type: SyntaxError +---*/ + +//- setup +$DONOTEVALUATE(); +//- body +1=1; diff --git a/tools/generation/test/fixtures/async/async.template b/tools/generation/test/fixtures/async/async.template new file mode 100644 index 0000000000..73fabbf651 --- /dev/null +++ b/tools/generation/test/fixtures/async/async.template @@ -0,0 +1,13 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +path: async/async-function-declaration- +name: async function declaration +esid: prod-AsyncFunctionDeclaration +flags: [async] +---*/ + +async function fn() { + await 1; + /*{ body }*/ +} diff --git a/tools/generation/test/run.py b/tools/generation/test/run.py index 833cd251d6..baf2d3127e 100755 --- a/tools/generation/test/run.py +++ b/tools/generation/test/run.py @@ -59,6 +59,11 @@ class TestGeneration(unittest.TestCase): self.assertEqual(result['returncode'], 0) self.compareTrees('normal') + def test_async(self): + result = self.fixture('async-negative-invalid.case') + self.assertEqual(result['returncode'], 0) + self.compareTrees('async') + def test_negative(self): result = self.fixture('negative.case') self.assertEqual(result['returncode'], 0)