mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Ensure DENO_DIR when saving the REPL history (#3106)
This commit is contained in:
parent
ab63e59817
commit
04ed8d0531
2 changed files with 10 additions and 20 deletions
18
cli/repl.rs
18
cli/repl.rs
|
@ -2,6 +2,7 @@
|
||||||
use crate::deno_dir::DenoDir;
|
use crate::deno_dir::DenoDir;
|
||||||
use deno::ErrBox;
|
use deno::ErrBox;
|
||||||
use rustyline;
|
use rustyline;
|
||||||
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -76,14 +77,7 @@ impl Repl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_history(&mut self) -> Result<(), ErrBox> {
|
fn save_history(&mut self) -> Result<(), ErrBox> {
|
||||||
if !self.history_dir_exists() {
|
fs::create_dir_all(self.history_file.parent().unwrap())?;
|
||||||
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())
|
||||||
|
@ -94,14 +88,6 @@ 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
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from subprocess import CalledProcessError, PIPE, Popen
|
from subprocess import CalledProcessError, PIPE, Popen
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -145,11 +146,14 @@ class TestRepl(DenoTestCase):
|
||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 0)
|
||||||
|
|
||||||
def test_missing_deno_dir(self):
|
def test_missing_deno_dir(self):
|
||||||
|
deno_dir = "nonexistent"
|
||||||
new_env = os.environ.copy()
|
new_env = os.environ.copy()
|
||||||
new_env["DENO_DIR"] = os.path.abspath("doesnt_exist")
|
new_env["DENO_DIR"] = deno_dir
|
||||||
out, err, code = self.input("'noop'", exit=False, env=new_env)
|
out, err, code = self.input("1", exit=False, env=new_env)
|
||||||
self.assertEqual(out, "noop\n")
|
self.assertTrue(os.path.isdir(deno_dir))
|
||||||
self.assertTrue(err.startswith("Unable to save REPL history:"))
|
shutil.rmtree(deno_dir)
|
||||||
|
self.assertEqual(out, "1\n")
|
||||||
|
self.assertEqual(err, "")
|
||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 0)
|
||||||
|
|
||||||
def test_save_last_eval(self):
|
def test_save_last_eval(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue