summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2019-09-10 17:09:54 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-09-10 11:09:54 -0400
commitacee1944b9419e101f515a501b11653af8229258 (patch)
tree25d31a76d25f465a8c97c637f3edce30c166ebb8 /tools
parent0b757f37371474da63db341b831d83539df28df6 (diff)
feat: Make integration tests rust unit tests (#2884)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/integration_tests.py115
-rwxr-xr-xtools/test.py2
-rw-r--r--tools/util.py28
-rwxr-xr-xtools/util_test.py28
4 files changed, 2 insertions, 171 deletions
diff --git a/tools/integration_tests.py b/tools/integration_tests.py
deleted file mode 100755
index dd65feaf9..000000000
--- a/tools/integration_tests.py
+++ /dev/null
@@ -1,115 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright 2018-2019 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 subprocess
-
-import http_server
-from test_util import DenoTestCase, run_tests
-from util import root_path, tests_path, pattern_match, rmtree
-
-
-def strip_ansi_codes(s):
- ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
- return ansi_escape.sub('', s)
-
-
-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:
- if line.strip().startswith("#"):
- # skip comments
- continue
- key, value = re.split(r":\s+", line)
- test_dict[key] = value
- return test_dict
-
-
-def str2bool(v):
- if v == "true":
- return True
- elif v == "false":
- return False
- else:
- raise ValueError("Bad boolean value")
-
-
-class TestIntegrations(DenoTestCase):
- @classmethod
- def _test(cls, test_filename):
- # Return thunk to test for js file,
- # This is to 'trick' unittest so as to generate these dynamically.
- return lambda self: self.generate(test_filename)
-
- def generate(self, test_filename):
- 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", None)
-
- if not args:
- return
-
- # TODO(kevinkassimo): better args parsing with quotation marks.
- args = args.split(" ")
- check_stderr = str2bool(test.get("check_stderr", "false"))
- stderr = subprocess.STDOUT if check_stderr else open(os.devnull, 'w')
- stdin_input = (test.get("input",
- "").strip().decode("string_escape").replace(
- "\r\n", "\n"))
- has_stdin_input = len(stdin_input) > 0
-
- output_abs = os.path.join(root_path, test.get("output", ""))
- with open(output_abs, 'r') as f:
- expected_out = f.read()
- cmd = [self.deno_exe] + args
- actual_code = 0
- try:
- if has_stdin_input:
- # Provided stdin
- proc = subprocess.Popen(
- cmd,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=stderr)
- actual_out, _ = proc.communicate(stdin_input)
- actual_out = actual_out.replace("\r\n", "\n")
- else:
- # No stdin sent
- actual_out = subprocess.check_output(
- cmd, universal_newlines=True, stderr=stderr)
-
- except subprocess.CalledProcessError as e:
- actual_code = e.returncode
- actual_out = e.output
-
- actual_out = strip_ansi_codes(actual_out)
- if not pattern_match(expected_out, actual_out):
- # This will always throw since pattern_match failed.
- self.assertEqual(expected_out, actual_out)
-
- self.assertEqual(exit_code, actual_code)
-
-
-# Add a methods for each test file in tests_path.
-for fn in sorted(
- filename for filename in os.listdir(tests_path)
- if filename.endswith(".test")):
-
- t = TestIntegrations._test(fn)
- tn = t.__name__ = "test_" + fn.split(".")[0]
- setattr(TestIntegrations, tn, t)
-
-if __name__ == "__main__":
- with http_server.spawn():
- run_tests()
diff --git a/tools/test.py b/tools/test.py
index 3f8e74ecd..9cd2f7a46 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -8,7 +8,6 @@ from benchmark_test import TestBenchmark
from deno_dir_test import TestDenoDir
from fetch_test import TestFetch
from fmt_test import TestFmt
-from integration_tests import TestIntegrations
from repl_test import TestRepl
from setup_test import TestSetup
from target_test import TestTarget
@@ -41,7 +40,6 @@ def main():
TestTarget,
JsUnitTests,
TestFetch,
- TestIntegrations,
TestRepl,
TestDenoDir,
TestBenchmark,
diff --git a/tools/util.py b/tools/util.py
index 39eaf6863..89b288a11 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -214,34 +214,6 @@ def build_path():
return os.path.join(root_path, "target", build_mode())
-# Returns True if the expected matches the actual output, allowing variation
-# from actual where expected has the wildcard (e.g. matches /.*/)
-def pattern_match(pattern, string, wildcard="[WILDCARD]"):
- if pattern == wildcard:
- return True
-
- parts = str.split(pattern, wildcard)
-
- if len(parts) == 1:
- return pattern == string
-
- if string.startswith(parts[0]):
- string = string[len(parts[0]):]
- else:
- return False
-
- for i in range(1, len(parts)):
- if i == (len(parts) - 1):
- if parts[i] == "" or parts[i] == "\n":
- return True
- found = string.find(parts[i])
- if found < 0:
- return False
- string = string[(found + len(parts[i])):]
-
- return len(string) == 0
-
-
def parse_exit_code(s):
codes = [int(d or 1) for d in re.findall(r'error(\d*)', s)]
if len(codes) > 1:
diff --git a/tools/util_test.py b/tools/util_test.py
index 0a718f1d9..4a545ff1c 100755
--- a/tools/util_test.py
+++ b/tools/util_test.py
@@ -2,35 +2,11 @@
import os
from test_util import DenoTestCase, run_tests
-from util import (pattern_match, parse_exit_code, shell_quote_win,
- parse_wrk_output, root_path)
+from util import (parse_exit_code, shell_quote_win, parse_wrk_output,
+ root_path)
class TestUtil(DenoTestCase):
- def test_pattern_match(self):
- # yapf: disable
- fixtures = [("foobarbaz", "foobarbaz", True),
- ("[WILDCARD]", "foobarbaz", True),
- ("foobar", "foobarbaz", False),
- ("foo[WILDCARD]baz", "foobarbaz", True),
- ("foo[WILDCARD]baz", "foobazbar", False),
- ("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", True),
- ("foo[WILDCARD]", "foobar", True),
- ("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", True)]
- # yapf: enable
-
- # Iterate through the fixture lists, testing each one
- for (pattern, string, expected) in fixtures:
- actual = pattern_match(pattern, string)
- assert expected == actual, \
- "expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % (
- expected, pattern, string)
-
- assert pattern_match("foo[BAR]baz", "foobarbaz",
- "[BAR]") == True, "expected wildcard to be set"
- assert pattern_match("foo[BAR]baz", "foobazbar",
- "[BAR]") == False, "expected wildcard to be set"
-
def test_parse_exit_code(self):
assert 54 == parse_exit_code('hello_error54_world')
assert 1 == parse_exit_code('hello_error_world')