summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check_output_test.py63
-rwxr-xr-xtools/integration_tests.py78
-rwxr-xr-xtools/test.py4
-rw-r--r--tools/util.py12
4 files changed, 92 insertions, 65 deletions
diff --git a/tools/check_output_test.py b/tools/check_output_test.py
deleted file mode 100755
index b2169c12b..000000000
--- a/tools/check_output_test.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2018 the Deno authors. All rights reserved. MIT license.
-# 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
-from util import pattern_match, parse_exit_code
-
-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)
- outs = sorted([
- filename for filename in os.listdir(tests_path)
- if filename.endswith(".out")
- ])
- 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()
- cmd = [deno_exe_filename, script_abs, "--reload"]
- expected_code = parse_exit_code(script)
- print " ".join(cmd)
- actual_code = 0
- try:
- actual_out = subprocess.check_output(cmd, universal_newlines=True)
- except subprocess.CalledProcessError as e:
- actual_code = e.returncode
- actual_out = e.output
- if expected_code == 0:
- print "Expected success but got error. Output:"
- print actual_out
- sys.exit(1)
-
- if expected_code != actual_code:
- print "Expected exit code %d but got %d" % (expected_code,
- actual_code)
- print "Output:"
- print actual_out
- sys.exit(1)
-
- if pattern_match(expected_out, actual_out) != True:
- print "Expected output does not match actual."
- print "Expected: " + expected_out
- print "Actual: " + actual_out
- sys.exit(1)
-
-
-def main(argv):
- check_output_test(argv[1])
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv))
diff --git a/tools/integration_tests.py b/tools/integration_tests.py
new file mode 100755
index 000000000..95c670f61
--- /dev/null
+++ b/tools/integration_tests.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
+# 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
+from util import pattern_match, green_ok, red_failed
+
+root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+tests_path = os.path.join(root_path, "tests")
+
+
+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:
+ key, value = re.split(r":\s+", line)
+ test_dict[key] = value
+ return test_dict
+
+
+def integration_tests(deno_executable):
+ assert os.path.isfile(deno_executable)
+ tests = sorted([
+ filename for filename in os.listdir(tests_path)
+ if filename.endswith(".test")
+ ])
+ assert len(tests) > 0
+ for test_filename in tests:
+ test_abs = os.path.join(tests_path, test_filename)
+ test = read_test(test_abs)
+ exit_code = int(test.get("exit_code", 0))
+ args = test.get("args", "").split(" ")
+ output_abs = os.path.join(root_path, test.get("output", ""))
+ with open(output_abs, 'r') as f:
+ expected_out = f.read()
+ cmd = [deno_executable] + args
+ print "test %s" % (test_filename)
+ print " ".join(cmd)
+ actual_code = 0
+ try:
+ actual_out = subprocess.check_output(cmd, universal_newlines=True)
+ 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):
+ integration_tests(argv[1])
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))
diff --git a/tools/test.py b/tools/test.py
index e2d077245..18fc23e5c 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -4,7 +4,7 @@
# Usage: ./tools/test.py out/Debug
import os
import sys
-from check_output_test import check_output_test
+from integration_tests import integration_tests
from deno_dir_test import deno_dir_test
from setup_test import setup_test
from util import build_path, enable_ansi_colors, executable_suffix, run, rmtree
@@ -58,7 +58,7 @@ def main(argv):
unit_tests(deno_exe)
- check_output_test(deno_exe)
+ integration_tests(deno_exe)
# TODO We currently skip testing the prompt in Windows completely.
# Windows does not support the pty module used for testing the permission
diff --git a/tools/util.py b/tools/util.py
index 306f2109f..dd80ab4bd 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -6,6 +6,10 @@ import stat
import sys
import subprocess
+RESET = "\x1b[0m"
+FG_RED = "\x1b[31m"
+FG_GREEN = "\x1b[32m"
+
executable_suffix = ".exe" if os.name == "nt" else ""
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
@@ -73,6 +77,14 @@ def shell_quote(arg):
return quote(arg)
+def red_failed():
+ return "%sFAILED%s" % (FG_RED, RESET)
+
+
+def green_ok():
+ return "%sok%s" % (FG_GREEN, RESET)
+
+
def remove_and_symlink(target, name, target_is_dir=False):
try:
# On Windows, directory symlink can only be removed with rmdir().