Skip to content

Commit 3ba6adc

Browse files
ossy-szegedrerobika
authored andcommitted
Make run-tests --unittests work on Windows too (#3026)
Changes: * Bash based unittest runner replaced with a python runner * Typo fixed in doctest cmake build system (python executable) * run-tests.py prints error message if build fails JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
1 parent 2f1908f commit 3ba6adc

File tree

5 files changed

+120
-125
lines changed

5 files changed

+120
-125
lines changed

tests/unit-doc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ endif()
2828
# file names that will be generated. This allows the definition of proper
2929
# dependencies between the MarkDown files and the generated sources.
3030
execute_process(
31-
COMMAND ${Python_EXECUTABLE} ${GEN_DOCTEST} --dry -d ${CMAKE_CURRENT_BINARY_DIR} ${DOC_FILES}
31+
COMMAND ${PYTHON_EXECUTABLE} ${GEN_DOCTEST} --dry -d ${CMAKE_CURRENT_BINARY_DIR} ${DOC_FILES}
3232
OUTPUT_VARIABLE DOCTEST_OUTPUT
3333
RESULT_VARIABLE GEN_DOCTEST_RESULT
3434
)

tools/run-tests.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def get_arguments():
222222
TERM_NORMAL = '\033[0m'
223223
TERM_YELLOW = '\033[1;33m'
224224
TERM_BLUE = '\033[1;34m'
225+
TERM_RED = '\033[1;31m'
225226

226227
def report_command(cmd_type, cmd, env=None):
227228
sys.stderr.write('%s%s%s\n' % (TERM_BLUE, cmd_type, TERM_NORMAL))
@@ -236,14 +237,21 @@ def report_skip(job):
236237
sys.stderr.write(' (%s)' % job.skip)
237238
sys.stderr.write('%s\n' % TERM_NORMAL)
238239

240+
def get_platform_cmd_prefix():
241+
if sys.platform == 'win32':
242+
return ['cmd', '/S', '/C']
243+
return []
244+
239245
def create_binary(job, options):
240246
build_args = job.build_args[:]
241247
if options.buildoptions:
242248
for option in options.buildoptions.split(','):
243249
if option not in build_args:
244250
build_args.append(option)
245251

246-
build_cmd = [settings.BUILD_SCRIPT] + build_args
252+
build_cmd = get_platform_cmd_prefix()
253+
build_cmd.append(settings.BUILD_SCRIPT)
254+
build_cmd.extend(build_args)
247255

248256
build_dir_path = os.path.join(options.outdir, job.name)
249257
build_cmd.append('--builddir=%s' % build_dir_path)
@@ -329,6 +337,7 @@ def run_jerry_debugger_tests(options):
329337
for job in DEBUGGER_TEST_OPTIONS:
330338
ret_build, build_dir_path = create_binary(job, options)
331339
if ret_build:
340+
print("\n%sBuild failed%s\n" % (TERM_RED, TERM_NORMAL))
332341
break
333342

334343
for channel in ["websocket", "rawpacket"]:
@@ -413,6 +422,7 @@ def run_test262_test_suite(options):
413422
for job in TEST262_TEST_SUITE_OPTIONS:
414423
ret_build, build_dir_path = create_binary(job, options)
415424
if ret_build:
425+
print("\n%sBuild failed%s\n" % (TERM_RED, TERM_NORMAL))
416426
break
417427

418428
test_cmd = [
@@ -433,11 +443,22 @@ def run_unittests(options):
433443
for job in JERRY_UNITTESTS_OPTIONS:
434444
ret_build, build_dir_path = create_binary(job, options)
435445
if ret_build:
446+
print("\n%sBuild failed%s\n" % (TERM_RED, TERM_NORMAL))
436447
break
437448

449+
if sys.platform == 'win32':
450+
if "--debug" in job.build_args:
451+
build_config = "Debug"
452+
else:
453+
build_config = "MinSizeRel"
454+
else:
455+
build_config = ""
456+
457+
438458
ret_test |= run_check(
459+
get_platform_cmd_prefix() +
439460
[settings.UNITTEST_RUNNER_SCRIPT] +
440-
[os.path.join(build_dir_path, 'tests')] +
461+
[os.path.join(build_dir_path, 'tests', build_config)] +
441462
(["-q"] if options.quiet else [])
442463
)
443464

@@ -451,6 +472,7 @@ def run_buildoption_test(options):
451472

452473
ret, _ = create_binary(job, options)
453474
if ret:
475+
print("\n%sBuild failed%s\n" % (TERM_RED, TERM_NORMAL))
454476
break
455477

456478
return ret

tools/runners/run-unittests.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright JS Foundation and other contributors, http://js.foundation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import print_function
18+
import argparse
19+
import glob
20+
import os
21+
import subprocess
22+
import sys
23+
24+
TERM_NORMAL = '\033[0m'
25+
TERM_RED = '\033[1;31m'
26+
TERM_GREEN = '\033[1;32m'
27+
28+
def get_arguments():
29+
parser = argparse.ArgumentParser()
30+
parser.add_argument('-q', '--quiet', action='store_true',
31+
help='Only print out failing tests')
32+
parser.add_argument('path',
33+
help='Path of test binaries')
34+
35+
script_args = parser.parse_args()
36+
return script_args
37+
38+
39+
def get_unittests(path):
40+
unittests = []
41+
files = glob.glob(os.path.join(path, 'unit-*'))
42+
for testfile in files:
43+
if os.path.isfile(testfile) and os.access(testfile, os.X_OK):
44+
if sys.platform != 'win32' or testfile.endswith(".exe"):
45+
unittests.append(testfile)
46+
unittests.sort()
47+
return unittests
48+
49+
50+
def main(args):
51+
unittests = get_unittests(args.path)
52+
total = len(unittests)
53+
if total == 0:
54+
print("%s: no unit-* test to execute", args.path)
55+
return 1
56+
57+
tested = 0
58+
passed = 0
59+
failed = 0
60+
61+
runtime = os.environ.get('RUNTIME')
62+
test_cmd = [runtime] if runtime else []
63+
64+
for test in unittests:
65+
tested += 1
66+
testpath = os.path.relpath(test)
67+
try:
68+
subprocess.check_output(test_cmd + [test], stderr=subprocess.STDOUT, universal_newlines=True)
69+
passed += 1
70+
if not args.quiet:
71+
print("[%4d/%4d] %sPASS: %s%s" % (tested, total, TERM_GREEN, testpath, TERM_NORMAL))
72+
except subprocess.CalledProcessError as err:
73+
failed += 1
74+
print("[%4d/%4d] %sFAIL (%d): %s%s" % (tested, total, TERM_RED, err.returncode, testpath, TERM_NORMAL))
75+
print("================================================")
76+
print(err.output)
77+
print("================================================")
78+
79+
print("\n[summary] %s\n" % os.path.join(os.path.relpath(args.path), "unit-*"))
80+
print("TOTAL: %d" % total)
81+
print("%sPASS: %d%s" % (TERM_GREEN, passed, TERM_NORMAL))
82+
print("%sFAIL: %d%s\n" % (TERM_RED, failed, TERM_NORMAL))
83+
84+
success_color = TERM_GREEN if passed == total else TERM_RED
85+
print("%sSuccess: %d%%%s" % (success_color, passed*100/total, TERM_NORMAL))
86+
87+
if failed > 0:
88+
return 1
89+
90+
return 0
91+
92+
93+
if __name__ == "__main__":
94+
sys.exit(main(get_arguments()))

tools/runners/run-unittests.sh

Lines changed: 0 additions & 121 deletions
This file was deleted.

tools/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
TEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-test-suite.sh')
3838
TEST262_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-test-suite-test262.sh')
3939
VERA_SCRIPT = path.join(TOOLS_DIR, 'check-vera.sh')
40-
UNITTEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-unittests.sh')
40+
UNITTEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-unittests.py')

0 commit comments

Comments
 (0)