lint: add rule to verify use of harness files

Verify that every test file which references a harness file using the
"includes" directive also contains at least one reference to a value
defined in the harness file.

To support this check, extend each harness file with a list of values
which it defines.
This commit is contained in:
Mike Pennisi 2019-09-24 20:22:26 -04:00
parent bb5a6622d4
commit a9111d7144
40 changed files with 236 additions and 7 deletions

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Verify that a subArray is contained within an array. Verify that a subArray is contained within an array.
defines: [arrayContains]
---*/ ---*/
/** /**

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Collection of assertion functions used throughout test262 Collection of assertion functions used throughout test262
defines: [assert]
---*/ ---*/

View File

@ -5,6 +5,7 @@ description: |
Verify that the given date object's Number representation describes the Verify that the given date object's Number representation describes the
correct number of milliseconds since the Unix epoch relative to the local correct number of milliseconds since the Unix epoch relative to the local
time zone (as interpreted at the specified date). time zone (as interpreted at the specified date).
defines: [assertRelativeDateMs]
---*/ ---*/
/** /**

View File

@ -6,6 +6,7 @@ description: >
features: [Symbol, async-functions] features: [Symbol, async-functions]
flags: [non-deterministic] flags: [non-deterministic]
features: [FinalizationGroup] features: [FinalizationGroup]
defines: [asyncGC, asyncGCDeref, resolveAsyncGC]
---*/ ---*/
function asyncGC(...targets) { function asyncGC(...targets) {

View File

@ -3,6 +3,11 @@
/*--- /*---
description: > description: >
Collection of functions used to interact with Atomics.* operations across agent boundaries. Collection of functions used to interact with Atomics.* operations across agent boundaries.
defines:
- $262.agent.getReport
- $262.agent.safeBroadcast
- $262.agent.tryYield
- $262.trySleep
---*/ ---*/
/** /**

View File

@ -7,6 +7,7 @@ description: |
This helper is mostly used on tests for TypedArray and DataView, and each This helper is mostly used on tests for TypedArray and DataView, and each
array from the expected values must match the original values array on every array from the expected values must match the original values array on every
index containing its original value. index containing its original value.
defines: [byteConversionValues]
---*/ ---*/
var byteConversionValues = { var byteConversionValues = {
values: [ values: [

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Compare the contents of two arrays Compare the contents of two arrays
defines: [compareArray]
---*/ ---*/
// @ts-check // @ts-check

View File

@ -2,6 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: Compare the values of an iterator with an array of expected values description: Compare the values of an iterator with an array of expected values
defines: [assert.compareIterator]
---*/ ---*/
// Example: // Example:

View File

@ -3,6 +3,17 @@
/*--- /*---
description: | description: |
Collection of date-centric values Collection of date-centric values
defines:
- date_1899_end
- date_1900_start
- date_1969_end
- date_1970_start
- date_1999_end
- date_2000_start
- date_2099_end
- date_2100_start
- start_of_time
- end_of_time
---*/ ---*/
var date_1899_end = -2208988800001; var date_1899_end = -2208988800001;

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Collection of functions used to assert the correctness of various encoding operations. Collection of functions used to assert the correctness of various encoding operations.
defines: [decimalToHexString, decimalToPercentHexString]
---*/ ---*/
function decimalToHexString(n) { function decimalToHexString(n) {

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Compare two values structurally Compare two values structurally
defines: [assert.deepEqual]
---*/ ---*/
// @ts-check // @ts-check

View File

@ -5,7 +5,7 @@ description: |
A function used in the process of asserting correctness of TypedArray objects. A function used in the process of asserting correctness of TypedArray objects.
$262.detachArrayBuffer is defined by a host. $262.detachArrayBuffer is defined by a host.
defines: [$DETACHBUFFER]
---*/ ---*/
function $DETACHBUFFER(buffer) { function $DETACHBUFFER(buffer) {

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: | description: |
defines: [$DONE]
---*/ ---*/
function __consolePrintHandle__(msg) { function __consolePrintHandle__(msg) {

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Produce a reliable global object Produce a reliable global object
defines: [fnGlobalObject]
---*/ ---*/
var __globalObject = Function("return this;")(); var __globalObject = Function("return this;")();

View File

@ -4,6 +4,7 @@
/*--- /*---
description: | description: |
Test if a given function is a constructor function. Test if a given function is a constructor function.
defines: [isConstructor]
---*/ ---*/
function isConstructor(f) { function isConstructor(f) {

View File

@ -6,6 +6,7 @@ description: |
to create distinct bit representations on various platforms. These provide a to create distinct bit representations on various platforms. These provide a
weak basis for assertions regarding the consistent canonicalization of NaN weak basis for assertions regarding the consistent canonicalization of NaN
values in Array buffers. values in Array buffers.
defines: [NaNs]
---*/ ---*/
var NaNs = [ var NaNs = [

View File

@ -8,7 +8,10 @@ info: |
NativeFunction : NativeFunction :
function _IdentifierName_ opt ( _FormalParameters_ ) { [ native code ] } function _IdentifierName_ opt ( _FormalParameters_ ) { [ native code ] }
defines:
- NATIVE_FUNCTION_RE
- assertToStringOrNativeFunction
- assertNativeFunction
---*/ ---*/
const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/; const NATIVE_FUNCTION_RE = /\bfunction\b[\s\S]*\([\s\S]*\)[\s\S]*\{[\s\S]*\[[\s\S]*\bnative\b[\s\S]+\bcode\b[\s\S]*\][\s\S]*\}/;

View File

@ -6,6 +6,7 @@ description: |
and incrementing by 1 for each entry in the array. Used by and incrementing by 1 for each entry in the array. Used by
Promise tests to assert the order of execution in deep Promise Promise tests to assert the order of execution in deep Promise
resolution pipelines. resolution pipelines.
defines: [checkSequence, checkSettledPromises]
---*/ ---*/
function checkSequence(arr, message) { function checkSequence(arr, message) {

View File

@ -4,6 +4,15 @@
description: | description: |
Collection of functions used to safely verify the correctness of Collection of functions used to safely verify the correctness of
property descriptors. property descriptors.
defines:
- verifyProperty
- verifyEqualTo
- verifyWritable
- verifyNotWritable
- verifyEnumerable
- verifyNotEnumerable
- verifyConfigurable
- verifyNotConfigurable
---*/ ---*/
// @ts-check // @ts-check

View File

@ -4,6 +4,7 @@
description: | description: |
Used to assert the correctness of object behavior in the presence Used to assert the correctness of object behavior in the presence
and context of Proxy objects. and context of Proxy objects.
defines: [allowProxyTraps]
---*/ ---*/
function allowProxyTraps(overrides) { function allowProxyTraps(overrides) {

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Collection of functions used to assert the correctness of RegExp objects. Collection of functions used to assert the correctness of RegExp objects.
defines: [buildString, testPropertyEscapes, matchValidator]
---*/ ---*/
function buildString({ loneCodePoints, ranges }) { function buildString({ loneCodePoints, ranges }) {

View File

@ -6,6 +6,7 @@ description: |
- An error class to avoid false positives when testing for thrown exceptions - An error class to avoid false positives when testing for thrown exceptions
- A function to explicitly throw an exception using the Test262Error class - A function to explicitly throw an exception using the Test262Error class
defines: [Test262Error, $ERROR, $DONOTEVALUATE]
---*/ ---*/

View File

@ -5,6 +5,7 @@ description: |
This defines the number of consecutive recursive function calls that must be This defines the number of consecutive recursive function calls that must be
made in order to prove that stack frames are properly destroyed according to made in order to prove that stack frames are properly destroyed according to
ES2015 tail call optimization semantics. ES2015 tail call optimization semantics.
defines: [$MAX_ITERATIONS]
---*/ ---*/

View File

@ -3,6 +3,10 @@
/*--- /*---
description: | description: |
Collection of functions used to assert the correctness of SharedArrayBuffer objects. Collection of functions used to assert the correctness of SharedArrayBuffer objects.
defines:
- testWithAtomicsOutOfBoundsIndices
- testWithAtomicsInBoundsIndices
- testWithAtomicsNonViewValues
---*/ ---*/

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Collection of functions used to assert the correctness of BigInt TypedArray objects. Collection of functions used to assert the correctness of BigInt TypedArray objects.
defines: [TypedArray, testWithBigIntTypedArrayConstructors]
---*/ ---*/
/** /**

View File

@ -6,8 +6,24 @@ description: |
This file contains shared functions for the tests in the conformance test This file contains shared functions for the tests in the conformance test
suite for the ECMAScript Internationalization API. suite for the ECMAScript Internationalization API.
author: Norbert Lindenberg author: Norbert Lindenberg
defines:
- testWithIntlConstructors
- taintDataProperty
- taintMethod
- taintProperties
- taintArray
- getLocaleSupportInfo
- getInvalidLanguageTags
- isCanonicalizedStructurallyValidLanguageTag
- getInvalidLocaleArguments
- testOption
- testForUnwantedRegExpChanges
- isValidNumberingSystem
- testNumberFormat
- getDateTimeComponents
- getDateTimeComponentValues
- isCanonicalizedStructurallyValidTimeZoneName
---*/ ---*/
/** /**
*/ */

View File

@ -3,6 +3,13 @@
/*--- /*---
description: | description: |
Collection of functions used to assert the correctness of TypedArray objects. Collection of functions used to assert the correctness of TypedArray objects.
defines:
- typedArrayConstructors
- floatArrayConstructors
- intArrayConstructors
- TypedArray
- testWithTypedArrayConstructors
- testTypedArrayConversions
---*/ ---*/
/** /**

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
Used in website/scripts/sth.js Used in website/scripts/sth.js
defines: [setTimeout]
---*/ ---*/
//setTimeout is not available, hence this script was loaded //setTimeout is not available, hence this script was loaded
if (Promise === undefined && this.setTimeout === undefined) { if (Promise === undefined && this.setTimeout === undefined) {

View File

@ -4,6 +4,30 @@
description: | description: |
Functions to help generate test cases for testing type coercion abstract Functions to help generate test cases for testing type coercion abstract
operations like ToNumber. operations like ToNumber.
defines:
- testCoercibleToIndexZero
- testCoercibleToIndexOne
- testCoercibleToIndexFromIndex
- testCoercibleToIntegerZero
- testCoercibleToIntegerOne
- testCoercibleToNumberZero
- testCoercibleToNumberNan
- testCoercibleToNumberOne
- testCoercibleToIntegerFromInteger
- testPrimitiveWrappers
- testCoercibleToPrimitiveWithMethod
- testNotCoercibleToIndex
- testNotCoercibleToInteger
- testNotCoercibleToNumber
- testNotCoercibleToPrimitive
- testCoercibleToString
- testNotCoercibleToString
- testCoercibleToBooleanTrue
- testCoercibleToBooleanFalse
- testCoercibleToBigIntZero
- testCoercibleToBigIntOne
- testCoercibleToBigIntFromBigInt
- testNotCoercibleToBigInt
---*/ ---*/
function testCoercibleToIndexZero(test) { function testCoercibleToIndexZero(test) {

View File

@ -3,6 +3,7 @@
/*--- /*---
description: | description: |
An Array of all representable Well-Known Intrinsic Objects An Array of all representable Well-Known Intrinsic Objects
defines: [WellKnownIntrinsicObjects]
---*/ ---*/
const WellKnownIntrinsicObjects = [ const WellKnownIntrinsicObjects = [

View File

@ -0,0 +1,65 @@
import os
import re
from ..check import Check
from ..frontmatter import parse
class CheckIncludes(Check):
'''Ensure tests make use of the harness files that they require via the
`includes` directive.'''
ID = 'INCLUDES'
_cache = dict()
@staticmethod
def _remove_frontmatter(source):
return re.sub(
r'/\*---.*---\*/', '', source, flags=re.DOTALL
)
@staticmethod
def _load(include_name):
if include_name not in CheckIncludes._cache:
with open(os.path.join('harness', include_name), 'r') as f:
source = f.read()
CheckIncludes._cache[include_name] = {
'name': include_name,
'source': CheckIncludes._remove_frontmatter(source),
'defines': parse(source)['defines']
}
return CheckIncludes._cache.get(include_name)
@staticmethod
def _has_reference(source, names):
for name in names:
if name in source:
return True
return False
def run(self, name, meta, source):
if not meta or 'includes' not in meta:
return
harness_files = [self._load(name) for name in meta['includes']]
if len(harness_files) == 0:
return 'If present, the `includes` tag must have at least one member'
without_frontmatter = self._remove_frontmatter(source)
for harness_file in harness_files:
if self._has_reference(without_frontmatter, harness_file['defines']):
continue
# If the test file does not reference a value defined by a given
# include file, inspect each of the other include files for such a
# reference.
for other_harness_file in harness_files:
if other_harness_file == harness_file:
continue
if self._has_reference(other_harness_file['source'], harness_file['defines']):
break
else:
return 'Unused include: "%s"' % harness_file['name']

View File

@ -37,6 +37,7 @@ from lib.checks.features import CheckFeatures
from lib.checks.frontmatter import CheckFrontmatter from lib.checks.frontmatter import CheckFrontmatter
from lib.checks.harnessfeatures import CheckHarnessFeatures from lib.checks.harnessfeatures import CheckHarnessFeatures
from lib.checks.harness import CheckHarness from lib.checks.harness import CheckHarness
from lib.checks.includes import CheckIncludes
from lib.checks.license import CheckLicense from lib.checks.license import CheckLicense
from lib.checks.negative import CheckNegative from lib.checks.negative import CheckNegative
from lib.checks.filename import CheckFileName from lib.checks.filename import CheckFileName
@ -61,6 +62,7 @@ checks = [
CheckFeatures('features.txt'), CheckFeatures('features.txt'),
CheckHarnessFeatures(), CheckHarnessFeatures(),
CheckHarness(), CheckHarness(),
CheckIncludes(),
CheckLicense(), CheckLicense(),
CheckNegative(), CheckNegative(),
CheckNoPadding(), CheckNoPadding(),

View File

@ -0,0 +1,13 @@
// Copyright (C) 2019 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
A function used in the process of asserting correctness of TypedArray objects.
$262.detachArrayBuffer is defined by a host.
defines: [modifiedDetachArrayBuffer]
---*/
function modifiedDetachArrayBuffer(buffer) {
return $DETACHBUFFER(buffer);
}

View File

@ -8,4 +8,4 @@ features: [TypedArray]
includes: [testTypedArray.js] includes: [testTypedArray.js]
---*/ ---*/
// empty intArrayConstructors;

View File

@ -5,7 +5,7 @@ HARNESS - verifyConfigurable & verifyProperty may not be used in the same file
/*--- /*---
esid: sec-whatever esid: sec-whatever
description: Minimal test description: Minimal test
includes: [verifyProperty.js] includes: [propertyHelper.js]
---*/ ---*/
verifyConfigurable(Object, ''); verifyConfigurable(Object, '');

View File

@ -4,7 +4,7 @@
/*--- /*---
esid: sec-whatever esid: sec-whatever
description: Minimal test description: Minimal test
includes: [verifyProperty.js] includes: [propertyHelper.js]
---*/ ---*/
verifyConfigurable(Object, ''); verifyConfigurable(Object, '');

View File

@ -0,0 +1,11 @@
INCLUDES
^ expected errors | v input
// Copyright (C) 2019 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
includes: []
---*/
void 0;

View File

@ -0,0 +1,16 @@
INCLUDES
^ expected errors | v input
// Copyright (C) 2019 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
includes: [detachArrayBuffer.js]
---*/
// This file doesn't reference any names defined by the "include" file. It
// contains some references that don't match exactly in order to verify that
// the linter is not susceptible to false positives.
DETACHBUFFER();
$DETACHBUFFE();
$DETACH_BUFFER();

View File

@ -0,0 +1,10 @@
^ expected errors | v input
// Copyright (C) 2019 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
includes: [detachArrayBuffer.js]
---*/
$DETACHBUFFER();

View File

@ -0,0 +1,13 @@
^ expected errors | v input
// Copyright (C) 2019 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
includes: [detachArrayBuffer.js, usesDetachArrayBuffer.js]
---*/
// This file doesn't reference any names defined by the first "include" file,
// but the second "include" file does.
modifiedDetachArrayBuffer();