未验证 提交 9a960b9f 编写于 作者: R Ryan Dahl 提交者: GitHub

Use stderr for exceptions (#1303)

上级 1548792f
......@@ -141,7 +141,7 @@ impl DenoDir {
let mt = Path::new(&media_type_filename);
let src = if self.reload || !p.exists() {
println!("Downloading {}", module_name);
eprintln!("Downloading {}", module_name);
let (source, content_type) = http_util::fetch_sync_string(module_name)?;
match p.parent() {
Some(ref parent) => fs::create_dir_all(parent),
......
......@@ -72,9 +72,7 @@ impl log::Log for Logger {
}
fn print_err_and_exit(err: js_errors::JSError) {
// TODO Currently tests depend on exception going to stdout. It should go
// to stderr. https://github.com/denoland/deno/issues/964
println!("{}", err.to_string());
eprintln!("{}", err.to_string());
std::process::exit(1);
}
......
Downloading http://localhost:4545/tests/subdir/mod2.ts
Downloading http://localhost:4545/tests/subdir/print_hello.ts
Hello
success
Downloading http://localhost:4545/tests/subdir/mod2
Downloading http://localhost:4545/tests/subdir/mod2.ts
Downloading http://localhost:4545/tests/subdir/print_hello.ts
true
[Function: printHello]
[Function: printHello]
......
Downloading http://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts
Hello
Downloading http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts
Downloading http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts
Downloading http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts
Downloading http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts
Downloading http://localhost:4545/tests/subdir/mt_text_javascript.j1.js
Downloading http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js
Downloading http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js
Downloading http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js
success true true true true true true true true
exit_code: 1
args: tests/async_error.ts --reload
check_stderr: true
output: tests/async_error.ts.out
hello
[WILDCARD]hello
before error
world
Error: error
......
args: tests/error_001.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_001.ts.out
Error: bad
[WILDCARD]Error: bad
at foo (file://[WILDCARD]tests/error_001.ts:2:9)
at bar (file://[WILDCARD]tests/error_001.ts:6:3)
at eval (file://[WILDCARD]tests/error_001.ts:9:1)
......
args: tests/error_002.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_002.ts.out
Error: exception from mod1
[WILDCARD]Error: exception from mod1
at throwsError (file://[WILDCARD]/tests/subdir/mod1.ts:16:9)
at foo (file://[WILDCARD]/tests/error_002.ts:4:3)
at eval (file://[WILDCARD]/tests/error_002.ts:7:1)
......
args: tests/error_004_missing_module.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_004_missing_module.ts.out
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
[WILDCARD]NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
......
args: tests/error_005_missing_dynamic_import.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_005_missing_dynamic_import.ts.out
NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_005_missing_dynamic_import.ts"
[WILDCARD]NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_005_missing_dynamic_import.ts"
at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
......
args: tests/error_006_import_ext_failure.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_006_import_ext_failure.ts.out
NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]/tests/error_006_import_ext_failure.ts"
[WILDCARD]NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]/tests/error_006_import_ext_failure.ts"
at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
......
args: tests/error_007_any.ts --reload
check_stderr: true
exit_code: 1
output: tests/error_007_any.ts.out
[object Object]
[WILDCARD][object Object]
Downloading https://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts
Hello
......@@ -28,6 +28,15 @@ def read_test(file_name):
return test_dict
def str2bool(v):
if v == "true":
return True
elif v == "false":
return False
else:
raise ValueError("Bad boolean value")
def integration_tests(deno_executable):
assert os.path.isfile(deno_executable)
tests = sorted([
......@@ -40,6 +49,10 @@ def integration_tests(deno_executable):
test = read_test(test_abs)
exit_code = int(test.get("exit_code", 0))
args = test.get("args", "").split(" ")
check_stderr = str2bool(test.get("check_stderr", "false"))
stderr = subprocess.STDOUT if check_stderr else None
output_abs = os.path.join(root_path, test.get("output", ""))
with open(output_abs, 'r') as f:
expected_out = f.read()
......@@ -48,7 +61,8 @@ def integration_tests(deno_executable):
print " ".join(cmd)
actual_code = 0
try:
actual_out = subprocess.check_output(cmd, universal_newlines=True)
actual_out = subprocess.check_output(
cmd, universal_newlines=True, stderr=stderr)
except subprocess.CalledProcessError as e:
actual_code = e.returncode
actual_out = e.output
......
......@@ -79,10 +79,9 @@ class Prompt(object):
assert stderr == b''
def test_write_no(self):
code, stdout, stderr = self.run('needsWrite', b'N\n')
code, _stdout, stderr = self.run('needsWrite', b'N\n')
assert code == 1
# FIXME this error message should be in stderr
assert b'PermissionDenied: permission denied' in stdout
assert b'PermissionDenied: permission denied' in stderr
assert b'Deno requests write access' in stderr
def test_env_yes(self):
......@@ -98,10 +97,9 @@ class Prompt(object):
assert stderr == b''
def test_env_no(self):
code, stdout, stderr = self.run('needsEnv', b'N\n')
code, _stdout, stderr = self.run('needsEnv', b'N\n')
assert code == 1
# FIXME this error message should be in stderr
assert b'PermissionDenied: permission denied' in stdout
assert b'PermissionDenied: permission denied' in stderr
assert b'Deno requests access to environment' in stderr
def test_net_yes(self):
......@@ -117,10 +115,9 @@ class Prompt(object):
assert stderr == b''
def test_net_no(self):
code, stdout, stderr = self.run('needsNet', b'N\n')
code, _stdout, stderr = self.run('needsNet', b'N\n')
assert code == 1
# FIXME this error message should be in stderr
assert b'PermissionDenied: permission denied' in stdout
assert b'PermissionDenied: permission denied' in stderr
assert b'Deno requests network access' in stderr
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册