summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/check_output_test.py17
-rwxr-xr-xtools/test.py4
-rw-r--r--tools/util.py33
-rw-r--r--tools/util_test.py31
4 files changed, 80 insertions, 5 deletions
diff --git a/tools/check_output_test.py b/tools/check_output_test.py
index 7227bb0a6..cba3b0c56 100755
--- a/tools/check_output_test.py
+++ b/tools/check_output_test.py
@@ -7,6 +7,7 @@
import os
import sys
import subprocess
+from util import pattern_match
root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
tests_path = os.path.join(root_path, "tests")
@@ -26,15 +27,25 @@ def check_output_test(deno_exe_filename):
with open(out_abs, 'r') as f:
expected_out = f.read()
cmd = [deno_exe_filename, script_abs]
+ should_succeed = "error" not in script
print " ".join(cmd)
+ err = False
try:
actual_out = subprocess.check_output(cmd, universal_newlines=True)
except subprocess.CalledProcessError as e:
- print "Got non-zero exit code. Output:"
- print e.output
+ err = True
+ actual_out = e.output
+ if should_succeed == True:
+ print "Expected success but got error. Output:"
+ print actual_out
+ sys.exit(1)
+
+ if should_succeed == False and err == False:
+ print "Expected an error but succeeded. Output:"
+ print actual_out
sys.exit(1)
- if expected_out != actual_out:
+ if pattern_match(expected_out, actual_out) != True:
print "Expected output does not match actual."
print "Expected: " + expected_out
print "Actual: " + actual_out
diff --git a/tools/test.py b/tools/test.py
index 91557e0fd..5344e7b62 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -5,6 +5,7 @@ import os
import sys
from check_output_test import check_output_test
from util import executable_suffix, run, build_path
+from util_test import util_test
def check_exists(filename):
@@ -23,6 +24,9 @@ def main(argv):
print "Usage: tools/test.py [build_dir]"
sys.exit(1)
+ # Internal tools testing
+ util_test()
+
test_cc = os.path.join(build_dir, "test_cc" + executable_suffix)
check_exists(test_cc)
run([test_cc])
diff --git a/tools/util.py b/tools/util.py
index 0a6f6a071..9e29cf742 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -1,5 +1,4 @@
-# Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
-# All rights reserved. MIT License.
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import os
import shutil
import stat
@@ -133,3 +132,33 @@ def build_path():
return os.environ["DENO_BUILD_PATH"]
else:
return os.path.join(root_path, "out", 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 len(pattern) == 0:
+ return string == 0
+ 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
diff --git a/tools/util_test.py b/tools/util_test.py
new file mode 100644
index 000000000..3315a4eaf
--- /dev/null
+++ b/tools/util_test.py
@@ -0,0 +1,31 @@
+# Copyright 2018 the Deno authors. All rights reserved. MIT license.
+from util import pattern_match
+
+
+def pattern_match_test():
+ print "Testing util.pattern_match()..."
+ # 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 util_test():
+ pattern_match_test()