Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: add rule to verify use of harness files #2367

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions harness/arrayContains.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Verify that a subArray is contained within an array.
defines: [arrayContains]
---*/

/**
Expand Down
1 change: 1 addition & 0 deletions harness/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Collection of assertion functions used throughout test262
defines: [assert]
---*/


Expand Down
1 change: 1 addition & 0 deletions harness/assertRelativeDateMs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: |
Verify that the given date object's Number representation describes the
correct number of milliseconds since the Unix epoch relative to the local
time zone (as interpreted at the specified date).
defines: [assertRelativeDateMs]
---*/

/**
Expand Down
1 change: 1 addition & 0 deletions harness/async-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: >
features: [Symbol, async-functions]
flags: [non-deterministic]
features: [FinalizationGroup]
defines: [asyncGC, asyncGCDeref, resolveAsyncGC]
---*/

function asyncGC(...targets) {
Expand Down
5 changes: 5 additions & 0 deletions harness/atomicsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
/*---
description: >
Collection of functions used to interact with Atomics.* operations across agent boundaries.
defines:
- $262.agent.getReport
- $262.agent.safeBroadcast
- $262.agent.tryYield
- $262.trySleep
---*/

/**
Expand Down
1 change: 1 addition & 0 deletions harness/byteConversionValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description: |
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
index containing its original value.
defines: [byteConversionValues]
---*/
var byteConversionValues = {
values: [
Expand Down
1 change: 1 addition & 0 deletions harness/compareArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Compare the contents of two arrays
defines: [compareArray]
---*/

// @ts-check
Expand Down
1 change: 1 addition & 0 deletions harness/compareIterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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
defines: [assert.compareIterator]
---*/

// Example:
Expand Down
11 changes: 11 additions & 0 deletions harness/dateConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
/*---
description: |
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;
Expand Down
1 change: 1 addition & 0 deletions harness/decimalToHexString.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Collection of functions used to assert the correctness of various encoding operations.
defines: [decimalToHexString, decimalToPercentHexString]
---*/

function decimalToHexString(n) {
Expand Down
1 change: 1 addition & 0 deletions harness/deepEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Compare two values structurally
defines: [assert.deepEqual]
---*/

// @ts-check
Expand Down
2 changes: 1 addition & 1 deletion harness/detachArrayBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: |
A function used in the process of asserting correctness of TypedArray objects.

$262.detachArrayBuffer is defined by a host.

defines: [$DETACHBUFFER]
---*/

function $DETACHBUFFER(buffer) {
Expand Down
2 changes: 1 addition & 1 deletion harness/doneprintHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |

defines: [$DONE]
---*/

function __consolePrintHandle__(msg) {
Expand Down
1 change: 1 addition & 0 deletions harness/fnGlobalObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Produce a reliable global object
defines: [fnGlobalObject]
---*/

var __globalObject = Function("return this;")();
Expand Down
1 change: 1 addition & 0 deletions harness/isConstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/*---
description: |
Test if a given function is a constructor function.
defines: [isConstructor]
---*/

function isConstructor(f) {
Expand Down
1 change: 1 addition & 0 deletions harness/nans.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: |
to create distinct bit representations on various platforms. These provide a
weak basis for assertions regarding the consistent canonicalization of NaN
values in Array buffers.
defines: [NaNs]
---*/

var NaNs = [
Expand Down
5 changes: 4 additions & 1 deletion harness/nativeFunctionMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ info: |

NativeFunction :
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]*\}/;

Expand Down
1 change: 1 addition & 0 deletions harness/promiseHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: |
and incrementing by 1 for each entry in the array. Used by
Promise tests to assert the order of execution in deep Promise
resolution pipelines.
defines: [checkSequence, checkSettledPromises]
---*/

function checkSequence(arr, message) {
Expand Down
9 changes: 9 additions & 0 deletions harness/propertyHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
description: |
Collection of functions used to safely verify the correctness of
property descriptors.
defines:
- verifyProperty
- verifyEqualTo
- verifyWritable
- verifyNotWritable
- verifyEnumerable
- verifyNotEnumerable
- verifyConfigurable
- verifyNotConfigurable
---*/

// @ts-check
Expand Down
1 change: 1 addition & 0 deletions harness/proxyTrapsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
description: |
Used to assert the correctness of object behavior in the presence
and context of Proxy objects.
defines: [allowProxyTraps]
---*/

function allowProxyTraps(overrides) {
Expand Down
1 change: 1 addition & 0 deletions harness/regExpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Collection of functions used to assert the correctness of RegExp objects.
defines: [buildString, testPropertyEscapes, matchValidator]
---*/

function buildString({ loneCodePoints, ranges }) {
Expand Down
1 change: 1 addition & 0 deletions harness/sta.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: |

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


Expand Down
1 change: 1 addition & 0 deletions harness/tcoHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: |
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
ES2015 tail call optimization semantics.
defines: [$MAX_ITERATIONS]
---*/


Expand Down
4 changes: 4 additions & 0 deletions harness/testAtomics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
/*---
description: |
Collection of functions used to assert the correctness of SharedArrayBuffer objects.
defines:
- testWithAtomicsOutOfBoundsIndices
- testWithAtomicsInBoundsIndices
- testWithAtomicsNonViewValues
---*/


Expand Down
1 change: 1 addition & 0 deletions harness/testBigIntTypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Collection of functions used to assert the correctness of BigInt TypedArray objects.
defines: [TypedArray, testWithBigIntTypedArrayConstructors]
---*/

/**
Expand Down
18 changes: 17 additions & 1 deletion harness/testIntl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@ description: |
This file contains shared functions for the tests in the conformance test
suite for the ECMAScript Internationalization API.
author: Norbert Lindenberg
defines:
- testWithIntlConstructors
- taintDataProperty
- taintMethod
- taintProperties
- taintArray
- getLocaleSupportInfo
- getInvalidLanguageTags
- isCanonicalizedStructurallyValidLanguageTag
- getInvalidLocaleArguments
- testOption
- testForUnwantedRegExpChanges
- isValidNumberingSystem
- testNumberFormat
- getDateTimeComponents
- getDateTimeComponentValues
- isCanonicalizedStructurallyValidTimeZoneName
---*/

/**
*/

Expand Down
7 changes: 7 additions & 0 deletions harness/testTypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
/*---
description: |
Collection of functions used to assert the correctness of TypedArray objects.
defines:
- typedArrayConstructors
- floatArrayConstructors
- intArrayConstructors
- TypedArray
- testWithTypedArrayConstructors
- testTypedArrayConversions
---*/

/**
Expand Down
1 change: 1 addition & 0 deletions harness/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
Used in website/scripts/sth.js
defines: [setTimeout]
---*/
//setTimeout is not available, hence this script was loaded
if (Promise === undefined && this.setTimeout === undefined) {
Expand Down
24 changes: 24 additions & 0 deletions harness/typeCoercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@
description: |
Functions to help generate test cases for testing type coercion abstract
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) {
Expand Down
1 change: 1 addition & 0 deletions harness/wellKnownIntrinsicObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*---
description: |
An Array of all representable Well-Known Intrinsic Objects
defines: [WellKnownIntrinsicObjects]
---*/

const WellKnownIntrinsicObjects = [
Expand Down
65 changes: 65 additions & 0 deletions tools/lint/lib/checks/includes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this check. Thanks!

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']
2 changes: 2 additions & 0 deletions tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from lib.checks.frontmatter import CheckFrontmatter
from lib.checks.harnessfeatures import CheckHarnessFeatures
from lib.checks.harness import CheckHarness
from lib.checks.includes import CheckIncludes
from lib.checks.license import CheckLicense
from lib.checks.negative import CheckNegative
from lib.checks.filename import CheckFileName
Expand All @@ -61,6 +62,7 @@
CheckFeatures('features.txt'),
CheckHarnessFeatures(),
CheckHarness(),
CheckIncludes(),
CheckLicense(),
CheckNegative(),
CheckNoPadding(),
Expand Down
Loading