2018-08-23 19:47:43 -04:00
|
|
|
#!/usr/bin/env python
|
2019-01-21 14:03:30 -05:00
|
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-11 16:56:50 -04:00
|
|
|
import util
|
2018-08-23 19:47:43 -04:00
|
|
|
import sys
|
2018-10-11 16:56:50 -04:00
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
|
2018-10-15 16:46:42 -04:00
|
|
|
|
2018-10-11 17:23:22 -04:00
|
|
|
def run_unit_test2(cmd):
|
2018-10-11 16:56:50 -04:00
|
|
|
process = subprocess.Popen(
|
|
|
|
cmd,
|
|
|
|
bufsize=1,
|
|
|
|
universal_newlines=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT)
|
|
|
|
(actual, expected) = util.parse_unit_test_output(process.stdout, True)
|
|
|
|
process.wait()
|
|
|
|
errcode = process.returncode
|
|
|
|
if errcode != 0:
|
|
|
|
sys.exit(errcode)
|
2019-04-07 13:58:26 -04:00
|
|
|
# To avoid the case where we silently filter out all tests.
|
|
|
|
assert expected > 0
|
2018-10-11 16:56:50 -04:00
|
|
|
if actual == None and expected == None:
|
|
|
|
raise AssertionError("Bad js/unit_test.ts output")
|
|
|
|
if expected != actual:
|
|
|
|
print "expected", expected, "actual", actual
|
|
|
|
raise AssertionError("expected tests did not equal actual")
|
|
|
|
process.wait()
|
|
|
|
errcode = process.returncode
|
|
|
|
if errcode != 0:
|
|
|
|
sys.exit(errcode)
|
2018-08-23 19:47:43 -04:00
|
|
|
|
2018-10-15 16:46:42 -04:00
|
|
|
|
2018-11-30 03:27:41 -05:00
|
|
|
def run_unit_test(deno_exe, permStr, flags=None):
|
|
|
|
if flags is None:
|
|
|
|
flags = []
|
2019-04-07 13:58:26 -04:00
|
|
|
cmd = [deno_exe] + flags + ["js/unit_tests.ts", permStr]
|
2018-10-11 17:23:22 -04:00
|
|
|
run_unit_test2(cmd)
|
|
|
|
|
2018-08-23 19:47:43 -04:00
|
|
|
|
|
|
|
# We want to test many ops in deno which have different behavior depending on
|
|
|
|
# the permissions set. These tests can specify which permissions they expect,
|
|
|
|
# which appends a special string like "permW1N0" to the end of the test name.
|
|
|
|
# Here we run several copies of deno with different permissions, filtering the
|
2019-04-20 15:12:00 -04:00
|
|
|
# tests by the special string. permW1N0 means allow-write but not allow-net.
|
2018-08-23 19:47:43 -04:00
|
|
|
# See js/test_util.ts for more details.
|
|
|
|
def unit_tests(deno_exe):
|
2019-04-08 16:22:40 -04:00
|
|
|
run_unit_test(deno_exe, "permR0W0N0E0U0H0", ["--reload"])
|
|
|
|
run_unit_test(deno_exe, "permR1W0N0E0U0H0", ["--allow-read"])
|
|
|
|
run_unit_test(deno_exe, "permR0W1N0E0U0H0", ["--allow-write"])
|
2019-05-02 17:08:02 -04:00
|
|
|
run_unit_test(deno_exe, "permR0W0N1E0U0H0", ["--allow-net"])
|
2019-04-08 16:22:40 -04:00
|
|
|
run_unit_test(deno_exe, "permR1W1N0E0U0H0",
|
2019-02-11 12:57:26 -05:00
|
|
|
["--allow-read", "--allow-write"])
|
2019-04-08 16:22:40 -04:00
|
|
|
run_unit_test(deno_exe, "permR0W0N0E1U0H0", ["--allow-env"])
|
|
|
|
run_unit_test(deno_exe, "permR0W0N0E0U0H1", ["--allow-high-precision"])
|
|
|
|
run_unit_test(deno_exe, "permR0W0N0E0U1H0", ["--allow-run"])
|
|
|
|
run_unit_test(deno_exe, "permR0W1N0E0U1H0",
|
|
|
|
["--allow-run", "--allow-write"])
|
2018-10-11 16:56:50 -04:00
|
|
|
# TODO We might accidentally miss some. We should be smarter about which we
|
|
|
|
# run. Maybe we can use the "filtered out" number to check this.
|
2018-08-23 19:47:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) < 2:
|
2018-11-08 13:38:20 -05:00
|
|
|
print "Usage ./tools/unit_tests.py target/debug/deno"
|
2018-08-23 19:47:43 -04:00
|
|
|
sys.exit(1)
|
|
|
|
unit_tests(sys.argv[1])
|