Fix tests, move rpassword usage to utils.rs to implement something different for wasm.
This commit is contained in:
+1
-1
@@ -19,7 +19,6 @@ thiserror = "1.0.37"
|
|||||||
anyerror = "0.1.7"
|
anyerror = "0.1.7"
|
||||||
sha1 = "0.10.5"
|
sha1 = "0.10.5"
|
||||||
base64 = "0.20.0"
|
base64 = "0.20.0"
|
||||||
rpassword = "7.2.0"
|
|
||||||
shlex = "1.1.0"
|
shlex = "1.1.0"
|
||||||
shellexpand = "3.0.0"
|
shellexpand = "3.0.0"
|
||||||
scopeguard = "1.1.0"
|
scopeguard = "1.1.0"
|
||||||
@@ -29,3 +28,4 @@ chrono = "0.4.23"
|
|||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
home = "0.5.4"
|
home = "0.5.4"
|
||||||
rustyline = "10.0.0"
|
rustyline = "10.0.0"
|
||||||
|
rpassword = "7.2.0"
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,4 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rpassword::prompt_password;
|
|
||||||
use sha1::{Digest, Sha1};
|
use sha1::{Digest, Sha1};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
@@ -13,6 +12,7 @@ use crate::password::{Name, Password, PasswordRef};
|
|||||||
use crate::repl::LKEval;
|
use crate::repl::LKEval;
|
||||||
use crate::structs::{LKOut, Radix, CORRECT_FILE, DUMP_FILE};
|
use crate::structs::{LKOut, Radix, CORRECT_FILE, DUMP_FILE};
|
||||||
use crate::utils::{call_cmd_with_input, get_cmd_args_from_command, get_copy_command_from_env, rnd};
|
use crate::utils::{call_cmd_with_input, get_cmd_args_from_command, get_copy_command_from_env, rnd};
|
||||||
|
use crate::utils::editor::password;
|
||||||
|
|
||||||
impl<'a> LKEval<'a> {
|
impl<'a> LKEval<'a> {
|
||||||
pub fn get_password(&self, name: &String) -> Option<PasswordRef> {
|
pub fn get_password(&self, name: &String) -> Option<PasswordRef> {
|
||||||
@@ -251,7 +251,7 @@ impl<'a> LKEval<'a> {
|
|||||||
match command_parser::script(&script) {
|
match command_parser::script(&script) {
|
||||||
Ok(cmd_list) => {
|
Ok(cmd_list) => {
|
||||||
for cmd in cmd_list {
|
for cmd in cmd_list {
|
||||||
let print = LKEval::new(cmd, self.state.clone(), prompt_password).eval();
|
let print = LKEval::new(cmd, self.state.clone(), password).eval();
|
||||||
print.out.copy(&out);
|
print.out.copy(&out);
|
||||||
if print.quit { return true; }
|
if print.quit { return true; }
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-9
@@ -1,10 +1,9 @@
|
|||||||
use rpassword::prompt_password;
|
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use crate::lk::LK;
|
use crate::lk::LK;
|
||||||
use crate::parser::command_parser;
|
use crate::parser::command_parser;
|
||||||
use crate::structs::{Command, LKErr, LKOut, HISTORY_FILE};
|
use crate::structs::{Command, LKErr, LKOut, HISTORY_FILE};
|
||||||
use crate::utils::editor::Editor;
|
use crate::utils::editor::{ Editor, password };
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LKRead {
|
pub struct LKRead {
|
||||||
@@ -36,7 +35,7 @@ impl LKRead {
|
|||||||
prompt,
|
prompt,
|
||||||
state,
|
state,
|
||||||
cmd: "".to_string(),
|
cmd: "".to_string(),
|
||||||
read_password: prompt_password,
|
read_password: password,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +152,8 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::password::Password;
|
use crate::password::Password;
|
||||||
use crate::structs::Mode;
|
use crate::structs::Mode;
|
||||||
use chrono::naive::NaiveDate;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use crate::utils::date::Date;
|
||||||
|
|
||||||
impl<'a> LKEval<'a> {
|
impl<'a> LKEval<'a> {
|
||||||
pub fn news(cmd: Command<'a>, state: Rc<RefCell<LK>>) -> Self {
|
pub fn news(cmd: Command<'a>, state: Rc<RefCell<LK>>) -> Self {
|
||||||
@@ -181,7 +180,7 @@ mod tests {
|
|||||||
length: None,
|
length: None,
|
||||||
mode: Mode::Regular,
|
mode: Mode::Regular,
|
||||||
seq: 99,
|
seq: 99,
|
||||||
date: NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(),
|
date: Date::new(2022, 12, 30),
|
||||||
comment: Some("comment".to_string()),
|
comment: Some("comment".to_string()),
|
||||||
parent: None,
|
parent: None,
|
||||||
}));
|
}));
|
||||||
@@ -208,7 +207,7 @@ mod tests {
|
|||||||
length: None,
|
length: None,
|
||||||
mode: Mode::Regular,
|
mode: Mode::Regular,
|
||||||
seq: 99,
|
seq: 99,
|
||||||
date: NaiveDate::from_ymd_opt(2022, 12, 31).unwrap(),
|
date: Date::new(2022, 12, 31),
|
||||||
comment: Some("bli blup".to_string()),
|
comment: Some("bli blup".to_string()),
|
||||||
parent: None,
|
parent: None,
|
||||||
}));
|
}));
|
||||||
@@ -252,7 +251,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(),
|
Date::new(2022, 12, 30),
|
||||||
None,
|
None,
|
||||||
)));
|
)));
|
||||||
let t2 = Rc::new(RefCell::new(Password::new(
|
let t2 = Rc::new(RefCell::new(Password::new(
|
||||||
@@ -261,7 +260,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(),
|
Date::new(2022, 12, 30),
|
||||||
None,
|
None,
|
||||||
)));
|
)));
|
||||||
let t3 = Rc::new(RefCell::new(Password::new(
|
let t3 = Rc::new(RefCell::new(Password::new(
|
||||||
@@ -270,7 +269,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 12, 30).unwrap(),
|
Date::new(2022, 12, 30),
|
||||||
None,
|
None,
|
||||||
)));
|
)));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
+9
-10
@@ -1,5 +1,4 @@
|
|||||||
use crate::password::{Comment, Name, PasswordRef};
|
use crate::password::{Comment, Name, PasswordRef};
|
||||||
use rpassword::prompt_password;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
@@ -8,7 +7,7 @@ use crate::lk::LK;
|
|||||||
use crate::parser::command_parser;
|
use crate::parser::command_parser;
|
||||||
use crate::repl::{LKEval, LKRead};
|
use crate::repl::{LKEval, LKRead};
|
||||||
use crate::utils::home;
|
use crate::utils::home;
|
||||||
use crate::utils::editor::Editor;
|
use crate::utils::editor::{ Editor, password };
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref HISTORY_FILE: Box<Path> = {
|
pub static ref HISTORY_FILE: Box<Path> = {
|
||||||
@@ -270,11 +269,11 @@ pub fn init() -> Option<LKRead> {
|
|||||||
Ok(script) => match command_parser::script(&script) {
|
Ok(script) => match command_parser::script(&script) {
|
||||||
Ok(cmd_list) => {
|
Ok(cmd_list) => {
|
||||||
for cmd in cmd_list {
|
for cmd in cmd_list {
|
||||||
if !LKEval::new(cmd, lk.clone(), prompt_password).eval().print() { return None; }
|
if !LKEval::new(cmd, lk.clone(), password).eval().print() { return None; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
LKEval::new(Command::Error(LKErr::ParseError(err)), lk.clone(), prompt_password).eval().print();
|
LKEval::new(Command::Error(LKErr::ParseError(err)), lk.clone(), password).eval().print();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) if err.kind() == std::io::ErrorKind::NotFound => (),
|
Err(err) if err.kind() == std::io::ErrorKind::NotFound => (),
|
||||||
@@ -284,7 +283,7 @@ pub fn init() -> Option<LKRead> {
|
|||||||
format!("Failed to read init file {:?}: {}", INIT_FILE.to_str(), err).as_str(),
|
format!("Failed to read init file {:?}: {}", INIT_FILE.to_str(), err).as_str(),
|
||||||
)),
|
)),
|
||||||
lk.clone(),
|
lk.clone(),
|
||||||
prompt_password,
|
password,
|
||||||
)
|
)
|
||||||
.eval()
|
.eval()
|
||||||
.print();
|
.print();
|
||||||
@@ -297,7 +296,7 @@ pub fn init() -> Option<LKRead> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::password::Password;
|
use crate::password::Password;
|
||||||
use chrono::naive::NaiveDate;
|
use crate::utils::date::Date;
|
||||||
use std::io::{BufWriter, Write};
|
use std::io::{BufWriter, Write};
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
@@ -358,7 +357,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(),
|
Date::new(2022, 10, 10),
|
||||||
None,
|
None,
|
||||||
)));
|
)));
|
||||||
let t2 = Rc::new(RefCell::new(Password::new(
|
let t2 = Rc::new(RefCell::new(Password::new(
|
||||||
@@ -367,7 +366,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(),
|
Date::new(2022, 10, 10),
|
||||||
Some("test".to_string()),
|
Some("test".to_string()),
|
||||||
)));
|
)));
|
||||||
t2.borrow_mut().parent = Some(t1.clone());
|
t2.borrow_mut().parent = Some(t1.clone());
|
||||||
@@ -377,7 +376,7 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
Mode::Regular,
|
Mode::Regular,
|
||||||
99,
|
99,
|
||||||
NaiveDate::from_ymd_opt(2022, 10, 10).unwrap(),
|
Date::new(2022, 10, 10),
|
||||||
Some("aoeu".to_string()),
|
Some("aoeu".to_string()),
|
||||||
)));
|
)));
|
||||||
t3.borrow_mut().parent = Some(t2.clone());
|
t3.borrow_mut().parent = Some(t2.clone());
|
||||||
@@ -385,7 +384,7 @@ mod tests {
|
|||||||
assert_eq!(*lkread.state.borrow().db.get("t2").unwrap().borrow(), *t2.borrow());
|
assert_eq!(*lkread.state.borrow().db.get("t2").unwrap().borrow(), *t2.borrow());
|
||||||
assert_eq!(*lkread.state.borrow().db.get("t3").unwrap().borrow(), *t3.borrow());
|
assert_eq!(*lkread.state.borrow().db.get("t3").unwrap().borrow(), *t3.borrow());
|
||||||
|
|
||||||
LKEval::new(command_parser::cmd("dump").unwrap(), lkread.state.clone(), prompt_password)
|
LKEval::new(command_parser::cmd("dump").unwrap(), lkread.state.clone(), password)
|
||||||
.eval()
|
.eval()
|
||||||
.print();
|
.print();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
+5
-1
@@ -10,7 +10,7 @@ pub mod date {
|
|||||||
use chrono::naive::NaiveDate;
|
use chrono::naive::NaiveDate;
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||||
pub struct Date {
|
pub struct Date {
|
||||||
date: NaiveDate
|
date: NaiveDate
|
||||||
}
|
}
|
||||||
@@ -107,6 +107,10 @@ pub mod editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn password(prompt: impl ToString) -> std::io::Result<String> {
|
||||||
|
rpassword::prompt_password(prompt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_cmd_with_input(cmd: &str, args: &Vec<String>, input: &str) -> io::Result<String> {
|
pub fn call_cmd_with_input(cmd: &str, args: &Vec<String>, input: &str) -> io::Result<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user