Skip to content

Commit c94eed7

Browse files
committed
Lint for invalid use of test_driver_internal
This isn't supposed to be called directly in tests; they must use the test_driver API
1 parent f440533 commit c94eed7

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lint.ignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,6 @@ SET TIMEOUT: wasm/core/js/harness/testharness.js
830830
ASSERT_THROWS: wasm/core/js/harness/testharness.js
831831
GENERATE_TESTS: wasm/core/js/harness/testharness.js
832832
PROMISE_REJECTS: wasm/core/js/harness/testharness.js
833+
834+
# Legitimate use of test_driver_internal
835+
TEST DRIVER INTERNAL: resources/testdriver.js

tools/lint/lint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ def filter_ignorelist_errors(data: Ignorelist, errors: Sequence[rules.Error]) ->
356356
rules.AssertThrowsRegexp,
357357
rules.PromiseRejectsRegexp,
358358
rules.AssertPreconditionRegexp,
359-
rules.HTMLInvalidSyntaxRegexp]]
359+
rules.HTMLInvalidSyntaxRegexp,
360+
rules.TestDriverInternalRegexp]]
360361

361362

362363
def check_regexp_line(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error]:

tools/lint/rules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,11 @@ class HTMLInvalidSyntaxRegexp(Regexp):
565565
file_extensions = EXTENSIONS["html"]
566566
description = "Test-file line has a non-void HTML tag with /> syntax"
567567
to_fix = """Replace with start tag and end tag"""
568+
569+
570+
class TestDriverInternalRegexp(Regexp):
571+
pattern = br"test_driver_internal"
572+
name = "TEST DRIVER INTERNAL"
573+
file_extensions = EXTENSIONS["js_all"]
574+
description = "Test-file uses test_driver_internal API"
575+
to_fix = """Only use test_driver public API"""

tools/lint/tests/test_file_lints.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ def test_html_invalid_syntax():
243243
assert errors == [("HTML INVALID SYNTAX", "Test-file line has a non-void HTML tag with /> syntax", filename, 1)]
244244

245245

246+
def test_testdriver_internal():
247+
error_map = check_with_files(b" test_driver_internal.foo()")
248+
249+
for (filename, (errors, kind)) in error_map.items():
250+
check_errors(errors)
251+
252+
if kind not in {"web-strict", "python"}:
253+
assert errors == [("TEST DRIVER INTERNAL", "Test-file uses test_driver_internal API", filename, 1)]
254+
255+
246256
def test_meta_timeout():
247257
code = b"""
248258
<html xmlns="http://www.w3.org/1999/xhtml">

0 commit comments

Comments
 (0)