summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/deno.ts4
-rw-r--r--tests/exit_error42.ts5
-rw-r--r--tests/exit_error42.ts.out1
-rwxr-xr-xtools/check_output_test.py16
-rw-r--r--tools/util.py11
-rw-r--r--tools/util_test.py14
6 files changed, 40 insertions, 11 deletions
diff --git a/js/deno.ts b/js/deno.ts
index f281ebefa..060b2d526 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -1,6 +1,4 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Public deno module.
-// TODO get rid of deno.d.ts
-// export { pub, sub } from "./dispatch";
-export { readFileSync } from "./os";
+export { exit, readFileSync } from "./os";
export { libdeno } from "./globals";
diff --git a/tests/exit_error42.ts b/tests/exit_error42.ts
new file mode 100644
index 000000000..c55cf0ece
--- /dev/null
+++ b/tests/exit_error42.ts
@@ -0,0 +1,5 @@
+import * as deno from "deno";
+
+console.log("before");
+deno.exit(42);
+console.log("after");
diff --git a/tests/exit_error42.ts.out b/tests/exit_error42.ts.out
new file mode 100644
index 000000000..90be1f305
--- /dev/null
+++ b/tests/exit_error42.ts.out
@@ -0,0 +1 @@
+before
diff --git a/tools/check_output_test.py b/tools/check_output_test.py
index cba3b0c56..54aff4e0c 100755
--- a/tools/check_output_test.py
+++ b/tools/check_output_test.py
@@ -7,7 +7,7 @@
import os
import sys
import subprocess
-from util import pattern_match
+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")
@@ -27,21 +27,23 @@ 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
+ expected_code = parse_exit_code(script)
print " ".join(cmd)
- err = False
+ actual_code = 0
try:
actual_out = subprocess.check_output(cmd, universal_newlines=True)
except subprocess.CalledProcessError as e:
- err = True
+ actual_code = e.returncode
actual_out = e.output
- if should_succeed == True:
+ if expected_code == 0:
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:"
+ 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)
diff --git a/tools/util.py b/tools/util.py
index 9e29cf742..b50b754c2 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -1,5 +1,6 @@
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import os
+import re
import shutil
import stat
import sys
@@ -162,3 +163,13 @@ def pattern_match(pattern, string, wildcard="[WILDCARD]"):
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:
+ assert False, "doesn't support multiple error codes."
+ elif len(codes) == 1:
+ return codes[0]
+ else:
+ return 0
diff --git a/tools/util_test.py b/tools/util_test.py
index 3315a4eaf..308951bc2 100644
--- a/tools/util_test.py
+++ b/tools/util_test.py
@@ -1,5 +1,5 @@
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
-from util import pattern_match
+from util import pattern_match, parse_exit_code
def pattern_match_test():
@@ -27,5 +27,17 @@ def pattern_match_test():
"[BAR]") == False, "expected wildcard to be set"
+def parse_exit_code_test():
+ print "Testing util.parse_exit_code()..."
+ assert 54 == parse_exit_code('hello_error54_world')
+ assert 1 == parse_exit_code('hello_error_world')
+ assert 0 == parse_exit_code('hello_world')
+
+
def util_test():
pattern_match_test()
+ parse_exit_code_test()
+
+
+if __name__ == '__main__':
+ util_test()