mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
Expose deno.exit() and add test.
This commit is contained in:
parent
18d495c7d1
commit
790baae673
6 changed files with 40 additions and 11 deletions
|
@ -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";
|
||||
|
|
5
tests/exit_error42.ts
Normal file
5
tests/exit_error42.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import * as deno from "deno";
|
||||
|
||||
console.log("before");
|
||||
deno.exit(42);
|
||||
console.log("after");
|
1
tests/exit_error42.ts.out
Normal file
1
tests/exit_error42.ts.out
Normal file
|
@ -0,0 +1 @@
|
|||
before
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue