summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorjugglinmike <mike@mikepennisi.com>2017-06-12 17:59:14 -0400
committerLeo Balter <leonardo.balter@gmail.com>2017-06-12 18:59:14 -0300
commit66bd632bae7e8c1ae55d4f1239d08143224e4a17 (patch)
treeed786f0ecda03b0679254ebd32bea4118b23d2fd /tools
parentb2bb2f9e5ad19460ae41558abfed23b16d630542 (diff)
downloadqtdeclarative-testsuites-66bd632bae7e8c1ae55d4f1239d08143224e4a17.tar.gz
Lint test `features` tag (#1060)
A recent commit introduced a document that enumerated acceptable values for the test "features" metadata tag. However, this list was incomplete, and maintaining it placed extra burden on the project owners. Restructure the document into a machine-readable format. Add entries for all previously-omitted values. Add in-line documentation with recommendations for maintenance of the file. Extend the project's linting tool to validate tests according to the document's contents.
Diffstat (limited to 'tools')
-rw-r--r--tools/lint/lib/checks/features.py38
-rwxr-xr-xtools/lint/lint.py3
-rw-r--r--tools/lint/test/fixtures/features_empty.js11
-rw-r--r--tools/lint/test/fixtures/features_unrecognized.js11
-rw-r--r--tools/lint/test/fixtures/features_valid.js10
5 files changed, 72 insertions, 1 deletions
diff --git a/tools/lint/lib/checks/features.py b/tools/lint/lib/checks/features.py
new file mode 100644
index 000000000..f7cae4894
--- /dev/null
+++ b/tools/lint/lib/checks/features.py
@@ -0,0 +1,38 @@
+from ..check import Check
+
+_REQUIRED_FIELDS = set(['description'])
+_OPTIONAL_FIELDS = set([
+ 'author', 'es5id', 'es6id', 'esid', 'features', 'flags', 'includes',
+ 'info', 'negative', 'timeout'
+])
+_VALID_FIELDS = _REQUIRED_FIELDS | _OPTIONAL_FIELDS
+
+class CheckFeatures(Check):
+ '''Ensure tests specify only `features` from a list of valid values.'''
+ ID = 'FEATURES'
+
+ def __init__(self, filename):
+ with open(filename, 'r') as f:
+ self.valid_features = self._parse(f.read())
+
+ @staticmethod
+ def _parse(content):
+ features = []
+ for line in content.split():
+ if not line or line.startswith('#'):
+ continue
+ features.append(line)
+ return features
+
+ def run(self, name, meta, source):
+ if not meta or 'features' not in meta:
+ return
+
+ features = meta['features']
+
+ if len(features) == 0:
+ return 'If present, the `features` tag must have at least one member'
+
+ for feature in features:
+ if feature not in self.valid_features:
+ return 'Unrecognized feature: "%s"' % feature
diff --git a/tools/lint/lint.py b/tools/lint/lint.py
index b26569516..9cdbca474 100755
--- a/tools/lint/lint.py
+++ b/tools/lint/lint.py
@@ -6,6 +6,7 @@ import argparse
import sys
from lib.collect_files import collect_files
+from lib.checks.features import CheckFeatures
from lib.checks.frontmatter import CheckFrontmatter
from lib.checks.license import CheckLicense
from lib.eprint import eprint
@@ -20,7 +21,7 @@ parser.add_argument('path',
nargs='+',
help='file name or directory of files to lint')
-checks = [CheckFrontmatter(), CheckLicense()]
+checks = [CheckFrontmatter(), CheckFeatures('features.txt'), CheckLicense()]
def lint(file_names):
errors = dict()
diff --git a/tools/lint/test/fixtures/features_empty.js b/tools/lint/test/fixtures/features_empty.js
new file mode 100644
index 000000000..47322aa59
--- /dev/null
+++ b/tools/lint/test/fixtures/features_empty.js
@@ -0,0 +1,11 @@
+FEATURES
+^ expected errors | v input
+// Copyright (C) 2017 Mike Pennisi. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-assignment-operators-static-semantics-early-errors
+description: Minimal test
+features: []
+---*/
+
+// empty
diff --git a/tools/lint/test/fixtures/features_unrecognized.js b/tools/lint/test/fixtures/features_unrecognized.js
new file mode 100644
index 000000000..aec50a950
--- /dev/null
+++ b/tools/lint/test/fixtures/features_unrecognized.js
@@ -0,0 +1,11 @@
+FEATURES
+^ expected errors | v input
+// Copyright (C) 2017 Mike Pennisi. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-assignment-operators-static-semantics-early-errors
+description: Minimal test
+features: [not-a-valid-feature]
+---*/
+
+// empty
diff --git a/tools/lint/test/fixtures/features_valid.js b/tools/lint/test/fixtures/features_valid.js
new file mode 100644
index 000000000..1508f570a
--- /dev/null
+++ b/tools/lint/test/fixtures/features_valid.js
@@ -0,0 +1,10 @@
+^ expected errors | v input
+// Copyright (C) 2017 Mike Pennisi. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-assignment-operators-static-semantics-early-errors
+description: Minimal test
+features: [async-functions, object-spread]
+---*/
+
+async function f({ ...a }) {}