Implemented flags and extra safety for zoltraak
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use libsh::error::{ShErr, ShErrKind};
|
||||
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cmd_not_found() {
|
||||
@@ -95,3 +93,30 @@ fn case_no_in() {
|
||||
let err_fmt = format!("{e}");
|
||||
insta::assert_snapshot!(err_fmt)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_with_notes() {
|
||||
let err = ShErr::simple(ShErrKind::ExecFail, "Execution failed")
|
||||
.with_note(Note::new("Execution failed for this reason"))
|
||||
.with_note(Note::new("Here is how to fix it: blah blah blah"));
|
||||
|
||||
let err_fmt = format!("{err}");
|
||||
insta::assert_snapshot!(err_fmt)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_with_notes_and_sub_notes() {
|
||||
let err = ShErr::simple(ShErrKind::ExecFail, "Execution failed")
|
||||
.with_note(Note::new("Execution failed for this reason"))
|
||||
.with_note(
|
||||
Note::new("Here is how to fix it:")
|
||||
.with_sub_notes(vec![
|
||||
"blah",
|
||||
"blah",
|
||||
"blah"
|
||||
])
|
||||
);
|
||||
|
||||
let err_fmt = format!("{err}");
|
||||
insta::assert_snapshot!(err_fmt)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use expand::{expand_aliases, unescape_str};
|
||||
use parse::lex::{Tk, TkFlags, TkRule};
|
||||
use state::{write_logic, write_vars};
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn simple_expansion() {
|
||||
@@ -32,61 +29,97 @@ fn unescape_string() {
|
||||
|
||||
#[test]
|
||||
fn expand_alias_simple() {
|
||||
write_logic(|l| l.insert_alias("foo", "echo foo"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
let input = String::from("foo");
|
||||
|
||||
let input = String::from("foo");
|
||||
|
||||
let result = expand_aliases(input, HashSet::new());
|
||||
assert_eq!(result.as_str(),"echo foo")
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result.as_str(),"echo foo");
|
||||
l.clear_aliases();
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_alias_in_if() {
|
||||
write_logic(|l| l.insert_alias("foo", "echo foo"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
let input = String::from("if foo; then echo bar; fi");
|
||||
|
||||
let input = String::from("if foo; then echo bar; fi");
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result.as_str(),"if echo foo; then echo bar; fi");
|
||||
l.clear_aliases();
|
||||
});
|
||||
}
|
||||
|
||||
let result = expand_aliases(input, HashSet::new());
|
||||
assert_eq!(result.as_str(),"if echo foo; then echo bar; fi")
|
||||
#[test]
|
||||
fn expand_alias_multiline() {
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
l.insert_alias("bar", "echo bar");
|
||||
let input = String::from("
|
||||
foo
|
||||
if true; then
|
||||
bar
|
||||
fi
|
||||
");
|
||||
let expected = String::from("
|
||||
echo foo
|
||||
if true; then
|
||||
echo bar
|
||||
fi
|
||||
");
|
||||
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result,expected)
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_multiple_aliases() {
|
||||
write_logic(|l| l.insert_alias("foo", "echo foo"));
|
||||
write_logic(|l| l.insert_alias("bar", "echo bar"));
|
||||
write_logic(|l| l.insert_alias("biz", "echo biz"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
l.insert_alias("bar", "echo bar");
|
||||
l.insert_alias("biz", "echo biz");
|
||||
let input = String::from("foo; bar; biz");
|
||||
|
||||
let input = String::from("foo; bar; biz");
|
||||
|
||||
let result = expand_aliases(input, HashSet::new());
|
||||
assert_eq!(result.as_str(),"echo foo; echo bar; echo biz")
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result.as_str(),"echo foo; echo bar; echo biz");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_in_arg_position() {
|
||||
write_logic(|l| l.insert_alias("foo", "echo foo"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
let input = String::from("echo foo");
|
||||
|
||||
let input = String::from("echo foo");
|
||||
|
||||
let result = expand_aliases(input.clone(), HashSet::new());
|
||||
assert_eq!(input,result)
|
||||
let result = expand_aliases(input.clone(), HashSet::new(), &l);
|
||||
assert_eq!(input,result);
|
||||
l.clear_aliases();
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_recursive_alias() {
|
||||
write_logic(|l| l.insert_alias("foo", "echo foo"));
|
||||
write_logic(|l| l.insert_alias("bar", "foo bar"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "echo foo");
|
||||
l.insert_alias("bar", "foo bar");
|
||||
|
||||
let input = String::from("bar");
|
||||
let result = expand_aliases(input, HashSet::new());
|
||||
assert_eq!(result.as_str(),"echo foo bar")
|
||||
let input = String::from("bar");
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result.as_str(),"echo foo bar");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_infinite_recursive_alias() {
|
||||
write_logic(|l| l.insert_alias("foo", "foo bar"));
|
||||
write_logic(|l| {
|
||||
l.insert_alias("foo", "foo bar");
|
||||
|
||||
let input = String::from("foo");
|
||||
let result = expand_aliases(input, HashSet::new(), &l);
|
||||
assert_eq!(result.as_str(),"foo bar");
|
||||
l.clear_aliases();
|
||||
});
|
||||
|
||||
let input = String::from("foo");
|
||||
let result = expand_aliases(input, HashSet::new());
|
||||
assert_eq!(result.as_str(),"foo bar")
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use getopt::get_opts_from_tokens;
|
||||
use getopt::{get_opts, get_opts_from_tokens};
|
||||
use parse::NdRule;
|
||||
use tests::get_nodes;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
#[test]
|
||||
fn lex_simple() {
|
||||
let input = "echo hello world";
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
use std::rc::Arc;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use super::*;
|
||||
use crate::libsh::error::{
|
||||
Note, ShErr, ShErrKind
|
||||
};
|
||||
use crate::parse::{
|
||||
node_operation, Node, NdRule, ParseStream,
|
||||
lex::{
|
||||
Tk, TkFlags, TkRule, LexFlags, LexStream
|
||||
}
|
||||
};
|
||||
use crate::expand::{
|
||||
expand_aliases, unescape_str
|
||||
};
|
||||
use crate::state::{
|
||||
write_logic, write_vars
|
||||
};
|
||||
|
||||
use crate::parse::{lex::{LexFlags, LexStream}, node_operation, Node, ParseStream};
|
||||
|
||||
pub mod lexer;
|
||||
pub mod parser;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use parse::{node_operation, NdRule, Node};
|
||||
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_simple() {
|
||||
@@ -170,13 +168,30 @@ esac";
|
||||
#[test]
|
||||
fn parse_case_nested() {
|
||||
let input = "case foo in
|
||||
foo) if true; then
|
||||
echo foo
|
||||
fi
|
||||
foo)
|
||||
if true; then
|
||||
while true; do
|
||||
echo foo
|
||||
done
|
||||
fi
|
||||
;;
|
||||
bar) if false; then
|
||||
echo bar
|
||||
fi
|
||||
bar)
|
||||
if false; then
|
||||
until false; do
|
||||
case foo in
|
||||
foo)
|
||||
if true; then
|
||||
echo foo
|
||||
fi
|
||||
;;
|
||||
bar)
|
||||
if false; then
|
||||
echo foo
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
;;
|
||||
esac";
|
||||
let tk_stream: Vec<_> = LexStream::new(Arc::new(input.to_string()), LexFlags::empty())
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: src/tests/error.rs
|
||||
expression: err_fmt
|
||||
---
|
||||
Execution failed
|
||||
[32mnote[0m: Execution failed for this reason
|
||||
|
||||
[32mnote[0m: Here is how to fix it: blah blah blah
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
source: src/tests/error.rs
|
||||
expression: err_fmt
|
||||
---
|
||||
Execution failed
|
||||
[32mnote[0m: Execution failed for this reason
|
||||
|
||||
[32mnote[0m: Here is how to fix it:
|
||||
[36m[1m-[0m blah
|
||||
[36m[1m-[0m blah
|
||||
[36m[1m-[0m blah
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user