mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
Fix repl crash when deno dir doesn't exist (#2727)
This commit is contained in:
parent
e438ac2c74
commit
520bdb6c31
2 changed files with 30 additions and 1 deletions
16
cli/repl.rs
16
cli/repl.rs
|
@ -76,6 +76,14 @@ impl Repl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_history(&mut self) -> Result<(), ErrBox> {
|
fn save_history(&mut self) -> Result<(), ErrBox> {
|
||||||
|
if !self.history_dir_exists() {
|
||||||
|
eprintln!(
|
||||||
|
"Unable to save REPL history: {:?} directory does not exist",
|
||||||
|
self.history_file
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
.editor
|
.editor
|
||||||
.save_history(&self.history_file.to_str().unwrap())
|
.save_history(&self.history_file.to_str().unwrap())
|
||||||
|
@ -86,6 +94,14 @@ impl Repl {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn history_dir_exists(&self) -> bool {
|
||||||
|
self
|
||||||
|
.history_file
|
||||||
|
.parent()
|
||||||
|
.map(|ref p| p.exists())
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn readline(&mut self, prompt: &str) -> Result<String, ErrBox> {
|
pub fn readline(&mut self, prompt: &str) -> Result<String, ErrBox> {
|
||||||
self
|
self
|
||||||
.editor
|
.editor
|
||||||
|
|
|
@ -11,7 +11,12 @@ class TestRepl(DenoTestCase):
|
||||||
def input(self, *lines, **kwargs):
|
def input(self, *lines, **kwargs):
|
||||||
exit_ = kwargs.pop("exit", True)
|
exit_ = kwargs.pop("exit", True)
|
||||||
sleep_ = kwargs.pop("sleep", 0)
|
sleep_ = kwargs.pop("sleep", 0)
|
||||||
p = Popen([self.deno_exe], stdout=PIPE, stderr=PIPE, stdin=PIPE)
|
env_ = kwargs.pop("env", None)
|
||||||
|
p = Popen([self.deno_exe],
|
||||||
|
stdout=PIPE,
|
||||||
|
stderr=PIPE,
|
||||||
|
stdin=PIPE,
|
||||||
|
env=env_)
|
||||||
try:
|
try:
|
||||||
# Note: The repl takes a >100ms until it's ready.
|
# Note: The repl takes a >100ms until it's ready.
|
||||||
time.sleep(sleep_)
|
time.sleep(sleep_)
|
||||||
|
@ -137,6 +142,14 @@ class TestRepl(DenoTestCase):
|
||||||
self.assertEqual(err, '')
|
self.assertEqual(err, '')
|
||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 0)
|
||||||
|
|
||||||
|
def test_missing_deno_dir(self):
|
||||||
|
new_env = os.environ.copy()
|
||||||
|
new_env["DENO_DIR"] = os.path.abspath("doesnt_exist")
|
||||||
|
out, err, code = self.input("'noop'", exit=False, env=new_env)
|
||||||
|
self.assertEqual(out, "noop\n")
|
||||||
|
self.assertTrue(err.startswith("Unable to save REPL history:"))
|
||||||
|
self.assertEqual(code, 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run_tests()
|
run_tests()
|
||||||
|
|
Loading…
Reference in a new issue