completely rewrote test suite for top level src files and all builtin files
This commit is contained in:
42
src/state.rs
42
src/state.rs
@@ -32,12 +32,20 @@ use crate::{
|
||||
shopt::ShOpts,
|
||||
};
|
||||
|
||||
thread_local! {
|
||||
pub static SHED: Shed = Shed::new();
|
||||
}
|
||||
|
||||
#[derive(Clone,Debug)]
|
||||
pub struct Shed {
|
||||
pub jobs: RefCell<JobTab>,
|
||||
pub var_scopes: RefCell<ScopeStack>,
|
||||
pub meta: RefCell<MetaTab>,
|
||||
pub logic: RefCell<LogTab>,
|
||||
pub shopts: RefCell<ShOpts>,
|
||||
|
||||
#[cfg(test)]
|
||||
saved: RefCell<Option<Box<Self>>>,
|
||||
}
|
||||
|
||||
impl Shed {
|
||||
@@ -48,6 +56,9 @@ impl Shed {
|
||||
meta: RefCell::new(MetaTab::new()),
|
||||
logic: RefCell::new(LogTab::new()),
|
||||
shopts: RefCell::new(ShOpts::default()),
|
||||
|
||||
#[cfg(test)]
|
||||
saved: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,6 +69,31 @@ impl Default for Shed {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl Shed {
|
||||
pub fn save(&self) {
|
||||
let saved = Self {
|
||||
jobs: RefCell::new(self.jobs.borrow().clone()),
|
||||
var_scopes: RefCell::new(self.var_scopes.borrow().clone()),
|
||||
meta: RefCell::new(self.meta.borrow().clone()),
|
||||
logic: RefCell::new(self.logic.borrow().clone()),
|
||||
shopts: RefCell::new(self.shopts.borrow().clone()),
|
||||
saved: RefCell::new(None),
|
||||
};
|
||||
*self.saved.borrow_mut() = Some(Box::new(saved));
|
||||
}
|
||||
|
||||
pub fn restore(&self) {
|
||||
if let Some(saved) = self.saved.take() {
|
||||
*self.jobs.borrow_mut() = saved.jobs.into_inner();
|
||||
*self.var_scopes.borrow_mut() = saved.var_scopes.into_inner();
|
||||
*self.meta.borrow_mut() = saved.meta.into_inner();
|
||||
*self.logic.borrow_mut() = saved.logic.into_inner();
|
||||
*self.shopts.borrow_mut() = saved.shopts.into_inner();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Debug, Clone, Copy)]
|
||||
pub enum ShellParam {
|
||||
// Global
|
||||
@@ -485,10 +521,6 @@ impl ScopeStack {
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
pub static SHED: Shed = Shed::new();
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShAlias {
|
||||
pub body: String,
|
||||
@@ -1258,7 +1290,7 @@ impl VarTab {
|
||||
}
|
||||
|
||||
/// A table of metadata for the shell
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub struct MetaTab {
|
||||
// command running duration
|
||||
runtime_start: Option<Instant>,
|
||||
|
||||
Reference in New Issue
Block a user