mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
parent
9a0bf201c2
commit
4e5e6da348
2 changed files with 28 additions and 66 deletions
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { exit } from "./ops/os.ts";
|
||||
import { core } from "./core.ts";
|
||||
import { version } from "./version.ts";
|
||||
import { stringifyArgs } from "./web/console.ts";
|
||||
import { startRepl, readline } from "./ops/repl.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
|
@ -13,26 +14,6 @@ function replError(...args: unknown[]): void {
|
|||
core.print(stringifyArgs(args) + "\n", true);
|
||||
}
|
||||
|
||||
const helpMsg = [
|
||||
"_ Get last evaluation result",
|
||||
"_error Get last thrown error",
|
||||
"exit Exit the REPL",
|
||||
"help Print this help message",
|
||||
].join("\n");
|
||||
|
||||
const replCommands = {
|
||||
exit: {
|
||||
get(): void {
|
||||
exit(0);
|
||||
},
|
||||
},
|
||||
help: {
|
||||
get(): string {
|
||||
return helpMsg;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Error messages that allow users to continue input
|
||||
// instead of throwing an error to REPL
|
||||
// ref: https://github.com/v8/v8/blob/master/src/message-template.h
|
||||
|
@ -83,7 +64,6 @@ function evaluate(code: string): boolean {
|
|||
// @internal
|
||||
export async function replLoop(): Promise<void> {
|
||||
const { console } = globalThis;
|
||||
Object.defineProperties(globalThis, replCommands);
|
||||
|
||||
const historyFile = "deno_history.txt";
|
||||
const rid = startRepl(historyFile);
|
||||
|
@ -126,6 +106,9 @@ export async function replLoop(): Promise<void> {
|
|||
},
|
||||
});
|
||||
|
||||
replLog(`Deno ${version.deno}`);
|
||||
replLog("exit using ctrl+d or close()");
|
||||
|
||||
while (true) {
|
||||
let code = "";
|
||||
// Top level read
|
||||
|
|
|
@ -581,7 +581,7 @@ fn repl_test_console_log() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "hello\nundefined\nworld\n");
|
||||
assert!(out.ends_with("hello\nundefined\nworld\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -594,38 +594,21 @@ fn repl_test_eof() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "3\n");
|
||||
assert!(out.ends_with("3\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
const REPL_MSG: &str = "exit using ctrl+d or close()\n";
|
||||
|
||||
#[test]
|
||||
fn repl_test_exit_command() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
fn repl_test_close_command() {
|
||||
let (_out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec!["exit", "'ignored'"]),
|
||||
Some(vec!["close()", "'ignored'"]),
|
||||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repl_test_help_command() {
|
||||
let (out, err) =
|
||||
util::run_and_collect_output(true, "repl", Some(vec!["help"]), None, false);
|
||||
assert_eq!(
|
||||
out,
|
||||
vec![
|
||||
"_ Get last evaluation result",
|
||||
"_error Get last thrown error",
|
||||
"exit Exit the REPL",
|
||||
"help Print this help message",
|
||||
"",
|
||||
]
|
||||
.join("\n")
|
||||
);
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -638,7 +621,7 @@ fn repl_test_function() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "[Function: writeFileSync]\n");
|
||||
assert!(out.ends_with("[Function: writeFileSync]\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -651,7 +634,7 @@ fn repl_test_multiline() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "3\n");
|
||||
assert!(out.ends_with("3\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -664,7 +647,7 @@ fn repl_test_eval_unterminated() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(out.ends_with(REPL_MSG));
|
||||
assert!(err.contains("Unexpected end of input"));
|
||||
}
|
||||
|
||||
|
@ -677,7 +660,7 @@ fn repl_test_reference_error() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(out.ends_with(REPL_MSG));
|
||||
assert!(err.contains("not_a_variable is not defined"));
|
||||
}
|
||||
|
||||
|
@ -690,7 +673,7 @@ fn repl_test_syntax_error() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(out.ends_with(REPL_MSG));
|
||||
assert!(err.contains("Unexpected identifier"));
|
||||
}
|
||||
|
||||
|
@ -703,7 +686,7 @@ fn repl_test_type_error() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.is_empty());
|
||||
assert!(out.ends_with(REPL_MSG));
|
||||
assert!(err.contains("console is not a function"));
|
||||
}
|
||||
|
||||
|
@ -716,7 +699,7 @@ fn repl_test_variable() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "undefined\n123\n");
|
||||
assert!(out.ends_with("undefined\n123\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -729,7 +712,7 @@ fn repl_test_lexical_scoped_variable() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "undefined\n123\n");
|
||||
assert!(out.ends_with("undefined\n123\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -748,7 +731,7 @@ fn repl_test_missing_deno_dir() {
|
|||
);
|
||||
assert!(read_dir(&test_deno_dir).is_ok());
|
||||
remove_dir_all(&test_deno_dir).unwrap();
|
||||
assert_eq!(out, "1\n");
|
||||
assert!(out.ends_with("1\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -761,7 +744,7 @@ fn repl_test_save_last_eval() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "1\n1\n");
|
||||
assert!(out.ends_with("1\n1\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
@ -774,7 +757,7 @@ fn repl_test_save_last_thrown() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(out, "1\n");
|
||||
assert!(out.ends_with("1\n"));
|
||||
assert_eq!(err, "Thrown: 1\n");
|
||||
}
|
||||
|
||||
|
@ -787,9 +770,8 @@ fn repl_test_assign_underscore() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(
|
||||
out,
|
||||
"Last evaluation result is no longer saved to _.\n1\n2\n1\n"
|
||||
assert!(
|
||||
out.ends_with("Last evaluation result is no longer saved to _.\n1\n2\n1\n")
|
||||
);
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
@ -803,9 +785,8 @@ fn repl_test_assign_underscore_error() {
|
|||
None,
|
||||
false,
|
||||
);
|
||||
assert_eq!(
|
||||
out,
|
||||
"Last thrown error is no longer saved to _error.\n1\n1\n"
|
||||
assert!(
|
||||
out.ends_with("Last thrown error is no longer saved to _error.\n1\n1\n")
|
||||
);
|
||||
assert_eq!(err, "Thrown: 2\n");
|
||||
}
|
||||
|
@ -2470,12 +2451,10 @@ mod util {
|
|||
envs: Option<Vec<(String, String)>>,
|
||||
need_http_server: bool,
|
||||
) -> (String, String) {
|
||||
let root = root_path();
|
||||
let tests_dir = root.join("cli").join("tests");
|
||||
let mut deno_process_builder = deno_cmd();
|
||||
deno_process_builder.args(args.split_whitespace());
|
||||
deno_process_builder
|
||||
.current_dir(&tests_dir)
|
||||
.args(args.split_whitespace())
|
||||
.current_dir(&deno::test_util::tests_path())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
|
|
Loading…
Add table
Reference in a new issue