Skip to content

Commit a0219af

Browse files
committed
Add support for .mjs in test harness
1 parent e2d8fd0 commit a0219af

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

test/testpy/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import test
2929
import os
30-
from os.path import join, dirname, exists
30+
from os.path import join, dirname, exists, splitext
3131
import re
3232
import ast
3333

@@ -109,18 +109,17 @@ def __init__(self, context, root, section, additional=None):
109109
self.additional_flags = []
110110

111111
def Ls(self, path):
112-
def SelectTest(name):
113-
return name.startswith('test-') and name.endswith('.js')
114-
return [f[:-3] for f in os.listdir(path) if SelectTest(f)]
112+
return [f for f in os.listdir(path) if re.match('^test-.*\.m?js$', f)]
115113

116114
def ListTests(self, current_path, path, arch, mode):
117115
all_tests = [current_path + [t] for t in self.Ls(join(self.root))]
118116
result = []
119117
for test in all_tests:
120118
if self.Contains(path, test):
121-
file_path = join(self.root, reduce(join, test[1:], "") + ".js")
122-
result.append(SimpleTestCase(test, file_path, arch, mode, self.context,
123-
self, self.additional_flags))
119+
file_path = join(self.root, reduce(join, test[1:], ""))
120+
test_name = test[:-1] + [splitext(test[-1])[0]]
121+
result.append(SimpleTestCase(test_name, file_path, arch, mode,
122+
self.context, self, self.additional_flags))
124123
return result
125124

126125
def GetBuildRequirements(self):

tools/test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ def HasRun(self, output):
279279
# hard to decipher what test is running when only the filename is printed.
280280
prefix = abspath(join(dirname(__file__), '../test')) + os.sep
281281
command = output.command[-1]
282-
if command.endswith('.js'): command = command[:-3]
283-
if command.startswith(prefix): command = command[len(prefix):]
284-
command = command.replace('\\', '/')
282+
command = NormalizePath(command, prefix)
285283

286284
if output.UnexpectedOutput():
287285
status_line = 'not ok %i %s' % (self._done, command)
@@ -352,9 +350,7 @@ def HasRun(self, output):
352350
# hard to decipher what test is running when only the filename is printed.
353351
prefix = abspath(join(dirname(__file__), '../test')) + os.sep
354352
command = output.command[-1]
355-
if command.endswith('.js'): command = command[:-3]
356-
if command.startswith(prefix): command = command[len(prefix):]
357-
command = command.replace('\\', '/')
353+
command = NormalizePath(command, prefix)
358354

359355
stdout = output.output.stdout.strip()
360356
printed_file = False
@@ -1497,12 +1493,16 @@ def SplitPath(s):
14971493
stripped = [ c.strip() for c in s.split('/') ]
14981494
return [ Pattern(s) for s in stripped if len(s) > 0 ]
14991495

1500-
def NormalizePath(path):
1496+
def NormalizePath(path, prefix='test/'):
15011497
# strip the extra path information of the specified test
1502-
if path.startswith('test/'):
1503-
path = path[5:]
1498+
prefix = prefix.replace('\\', '/')
1499+
path = path.replace('\\', '/')
1500+
if path.startswith(prefix):
1501+
path = path[len(prefix):]
15041502
if path.endswith('.js'):
15051503
path = path[:-3]
1504+
elif path.endswith('.mjs'):
1505+
path = path[:-4]
15061506
return path
15071507

15081508
def GetSpecialCommandProcessor(value):

0 commit comments

Comments
 (0)