diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-09-13 16:09:43 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-13 16:09:43 -0600 |
commit | a4b7d563c48d6f386d3383ce35a1319a6834eaf0 (patch) | |
tree | bce6995e1fafb0543667542286161f5f26cfd714 /tools/wpt.ts | |
parent | 81d50e1b6685a12a4f43693e695073a97f79264b (diff) |
chore(test_util): ensure that extra expectations are an error even without a filter (#20483)
Running `tools/wpt.ts` with a filter would cause an error if there were
extra, leftover expectations in expectations.json. These errors would
not appear if no filter was passed, often leaving the filtered version
of the test runner broken.
This also introduces a smarter bit of logic where filters can be
specified with a leading slash (`tools/wpt.ts run -- /url` is equivalent
to `tools/wpt.ts run -- url`)
Diffstat (limited to 'tools/wpt.ts')
-rwxr-xr-x | tools/wpt.ts | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/tools/wpt.ts b/tools/wpt.ts index 29d3e3517..8c9d0a447 100755 --- a/tools/wpt.ts +++ b/tools/wpt.ts @@ -37,6 +37,31 @@ import { blue, bold, green, red, yellow } from "../test_util/std/fmt/colors.ts"; import { writeAll, writeAllSync } from "../test_util/std/streams/write_all.ts"; import { saveExpectation } from "./wpt/utils.ts"; +class TestFilter { + filter?: string[]; + constructor(filter?: string[]) { + this.filter = filter; + } + + matches(path: string): boolean { + if (this.filter === undefined || this.filter.length == 0) { + return true; + } + for (const filter of this.filter) { + if (filter.startsWith("/")) { + if (path.startsWith(filter)) { + return true; + } + } else { + if (path.substring(1).startsWith(filter)) { + return true; + } + } + } + return false; + } +} + const command = Deno.args[0]; switch (command) { @@ -161,11 +186,12 @@ async function run() { const startTime = new Date().getTime(); assert(Array.isArray(rest), "filter must be array"); const expectation = getExpectation(); + const filter = new TestFilter(rest); const tests = discoverTestsToRun( - rest.length == 0 ? undefined : rest, + filter, expectation, ); - assertAllExpectationsHaveTests(expectation, tests, rest); + assertAllExpectationsHaveTests(expectation, tests, filter); const cores = navigator.hardwareConcurrency; console.log(`Going to run ${tests.length} test files on ${cores} cores.`); @@ -295,20 +321,14 @@ async function generateWptReport( function assertAllExpectationsHaveTests( expectation: Expectation, testsToRun: TestToRun[], - filter?: string[], + filter: TestFilter, ): void { const tests = new Set(testsToRun.map((t) => t.path)); const missingTests: string[] = []; - function walk(parentExpectation: Expectation, parent: string) { for (const [key, expectation] of Object.entries(parentExpectation)) { const path = `${parent}/${key}`; - if ( - filter && - !filter.find((filter) => path.substring(1).startsWith(filter)) - ) { - continue; - } + if (!filter.matches(path)) continue; if (typeof expectation == "boolean" || Array.isArray(expectation)) { if (!tests.has(path)) { missingTests.push(path); @@ -336,7 +356,8 @@ function assertAllExpectationsHaveTests( async function update() { assert(Array.isArray(rest), "filter must be array"); const startTime = new Date().getTime(); - const tests = discoverTestsToRun(rest.length == 0 ? undefined : rest, true); + const filter = new TestFilter(rest); + const tests = discoverTestsToRun(filter, true); console.log(`Going to run ${tests.length} test files.`); const results = await runWithTestUtil(false, async () => { @@ -668,7 +689,7 @@ function createReportTestCase(expectation: boolean | string[]) { } function discoverTestsToRun( - filter?: string[], + filter: TestFilter, expectation: Expectation | string[] | boolean = getExpectation(), ): TestToRun[] { const manifestFolder = getManifest().items.testharness; @@ -736,12 +757,8 @@ function discoverTestsToRun( ); } - if ( - filter && - !filter.find((filter) => finalPath.substring(1).startsWith(filter)) - ) { - continue; - } + if (!filter.matches(finalPath)) continue; + testsToRun.push({ path: finalPath, url, |