2018-07-21 19:08:24 -04:00
|
|
|
#!/usr/bin/env python
|
2018-10-19 15:25:29 -04:00
|
|
|
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-07-21 19:08:24 -04:00
|
|
|
# Given a deno executable, this script execute several integration tests
|
|
|
|
# with it. The tests are stored in //tests/ and each script has a corresponding
|
|
|
|
# .out file which specifies what the stdout should be.
|
|
|
|
#
|
|
|
|
# Usage: check_output_test.py [path to deno executable]
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2018-08-19 03:00:34 -04:00
|
|
|
from util import pattern_match, parse_exit_code
|
2018-07-21 19:08:24 -04:00
|
|
|
|
|
|
|
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
tests_path = os.path.join(root_path, "tests")
|
|
|
|
|
|
|
|
|
|
|
|
def check_output_test(deno_exe_filename):
|
|
|
|
assert os.path.isfile(deno_exe_filename)
|
2018-08-01 16:30:19 -04:00
|
|
|
outs = sorted([
|
2018-07-21 19:08:24 -04:00
|
|
|
filename for filename in os.listdir(tests_path)
|
|
|
|
if filename.endswith(".out")
|
2018-08-01 16:30:19 -04:00
|
|
|
])
|
2018-07-21 19:08:24 -04:00
|
|
|
assert len(outs) > 1
|
|
|
|
tests = [(os.path.splitext(filename)[0], filename) for filename in outs]
|
|
|
|
for (script, out_filename) in tests:
|
|
|
|
script_abs = os.path.join(tests_path, script)
|
|
|
|
out_abs = os.path.join(tests_path, out_filename)
|
|
|
|
with open(out_abs, 'r') as f:
|
|
|
|
expected_out = f.read()
|
2018-08-14 16:50:53 -04:00
|
|
|
cmd = [deno_exe_filename, script_abs, "--reload"]
|
2018-08-19 03:00:34 -04:00
|
|
|
expected_code = parse_exit_code(script)
|
2018-07-21 19:08:24 -04:00
|
|
|
print " ".join(cmd)
|
2018-08-19 03:00:34 -04:00
|
|
|
actual_code = 0
|
2018-08-08 16:41:25 -04:00
|
|
|
try:
|
|
|
|
actual_out = subprocess.check_output(cmd, universal_newlines=True)
|
|
|
|
except subprocess.CalledProcessError as e:
|
2018-08-19 03:00:34 -04:00
|
|
|
actual_code = e.returncode
|
2018-08-10 13:38:32 -04:00
|
|
|
actual_out = e.output
|
2018-08-19 03:00:34 -04:00
|
|
|
if expected_code == 0:
|
2018-08-10 13:38:32 -04:00
|
|
|
print "Expected success but got error. Output:"
|
|
|
|
print actual_out
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-19 03:00:34 -04:00
|
|
|
if expected_code != actual_code:
|
|
|
|
print "Expected exit code %d but got %d" % (expected_code,
|
|
|
|
actual_code)
|
|
|
|
print "Output:"
|
2018-08-10 13:38:32 -04:00
|
|
|
print actual_out
|
2018-08-08 16:41:25 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-08-10 13:38:32 -04:00
|
|
|
if pattern_match(expected_out, actual_out) != True:
|
2018-07-21 19:08:24 -04:00
|
|
|
print "Expected output does not match actual."
|
2018-07-21 21:01:40 -04:00
|
|
|
print "Expected: " + expected_out
|
|
|
|
print "Actual: " + actual_out
|
2018-07-21 19:08:24 -04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
check_output_test(argv[1])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|