2018-11-04 14:52:31 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2019-01-21 14:03:30 -05:00
|
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-11-04 14:52:31 -05:00
|
|
|
# Given a deno executable, this script executes several integration tests with
|
|
|
|
# it. The tests are stored in /tests/ and each is specified in a .yaml file
|
|
|
|
# where a description, command line, and output are specified. Optionally an
|
|
|
|
# exit code can be specified.
|
|
|
|
#
|
|
|
|
# Usage: integration_tests.py [path to deno executable]
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import subprocess
|
2019-01-15 12:19:58 -05:00
|
|
|
from util import root_path, tests_path, pattern_match, green_ok, red_failed
|
2018-11-04 14:52:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
def read_test(file_name):
|
|
|
|
with open(file_name, "r") as f:
|
|
|
|
test_file = f.read()
|
|
|
|
lines = test_file.splitlines()
|
|
|
|
test_dict = {}
|
|
|
|
for line in lines:
|
2019-02-02 01:28:31 -05:00
|
|
|
if line.strip().startswith("#"):
|
|
|
|
# skip comments
|
|
|
|
continue
|
2018-11-04 14:52:31 -05:00
|
|
|
key, value = re.split(r":\s+", line)
|
|
|
|
test_dict[key] = value
|
|
|
|
return test_dict
|
|
|
|
|
|
|
|
|
2018-12-10 17:50:41 -05:00
|
|
|
def str2bool(v):
|
|
|
|
if v == "true":
|
|
|
|
return True
|
|
|
|
elif v == "false":
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
raise ValueError("Bad boolean value")
|
|
|
|
|
|
|
|
|
2019-02-02 01:58:27 -05:00
|
|
|
def integration_tests(deno_exe, test_filter = None):
|
|
|
|
assert os.path.isfile(deno_exe)
|
2018-11-04 14:52:31 -05:00
|
|
|
tests = sorted([
|
|
|
|
filename for filename in os.listdir(tests_path)
|
|
|
|
if filename.endswith(".test")
|
|
|
|
])
|
|
|
|
assert len(tests) > 0
|
|
|
|
for test_filename in tests:
|
2019-02-02 01:58:27 -05:00
|
|
|
if test_filter and test_filter not in test_filename:
|
|
|
|
continue
|
|
|
|
|
2018-11-04 14:52:31 -05:00
|
|
|
test_abs = os.path.join(tests_path, test_filename)
|
2019-02-02 01:58:27 -05:00
|
|
|
print "read_test", test_abs
|
2018-11-04 14:52:31 -05:00
|
|
|
test = read_test(test_abs)
|
|
|
|
exit_code = int(test.get("exit_code", 0))
|
|
|
|
args = test.get("args", "").split(" ")
|
2018-12-10 17:50:41 -05:00
|
|
|
|
|
|
|
check_stderr = str2bool(test.get("check_stderr", "false"))
|
|
|
|
stderr = subprocess.STDOUT if check_stderr else None
|
|
|
|
|
2018-11-04 14:52:31 -05:00
|
|
|
output_abs = os.path.join(root_path, test.get("output", ""))
|
|
|
|
with open(output_abs, 'r') as f:
|
|
|
|
expected_out = f.read()
|
2019-02-02 01:58:27 -05:00
|
|
|
cmd = [deno_exe] + args
|
2018-11-04 14:52:31 -05:00
|
|
|
print "test %s" % (test_filename)
|
|
|
|
print " ".join(cmd)
|
|
|
|
actual_code = 0
|
|
|
|
try:
|
2018-12-10 17:50:41 -05:00
|
|
|
actual_out = subprocess.check_output(
|
|
|
|
cmd, universal_newlines=True, stderr=stderr)
|
2018-11-04 14:52:31 -05:00
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
actual_code = e.returncode
|
|
|
|
actual_out = e.output
|
|
|
|
|
|
|
|
if exit_code != actual_code:
|
|
|
|
print "... " + red_failed()
|
|
|
|
print "Expected exit code %d but got %d" % (exit_code, actual_code)
|
|
|
|
print "Output:"
|
|
|
|
print actual_out
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if pattern_match(expected_out, actual_out) != True:
|
|
|
|
print "... " + red_failed()
|
|
|
|
print "Expected output does not match actual."
|
|
|
|
print "Expected output: \n" + expected_out
|
|
|
|
print "Actual output: \n" + actual_out
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print "... " + green_ok()
|
|
|
|
|
|
|
|
def main(argv):
|
2019-02-02 01:58:27 -05:00
|
|
|
deno_exe = argv[1]
|
|
|
|
test_filter = None
|
|
|
|
if len(argv) > 2:
|
|
|
|
test_filter = argv[2]
|
|
|
|
integration_tests(deno_exe, test_filter)
|
2018-11-04 14:52:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main(sys.argv))
|