From fd823c090b2a1cd95c237206f9887215c0f9230a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 10 Jan 2022 01:49:49 -0500 Subject: fix tests --- src/parse/test_ast.rs | 211 +++++++++++--------------------------------------- 1 file changed, 45 insertions(+), 166 deletions(-) diff --git a/src/parse/test_ast.rs b/src/parse/test_ast.rs index 81d6ef6..b16eba4 100644 --- a/src/parse/test_ast.rs +++ b/src/parse/test_ast.rs @@ -7,22 +7,20 @@ impl From for Command { } macro_rules! cs { - ($input_string:expr, $($commands:expr),*) => { + ($($commands:expr),*) => { Commands { commands: [$($commands),*] .into_iter() .map(|c| c.into()) .collect(), - input_string: $input_string.to_string(), } }; } macro_rules! p { - ($input_string:expr, $($exes:expr),*) => { + ($($exes:expr),*) => { Pipeline { exes: vec![$($exes),*], - input_string: $input_string.to_string(), } }; } @@ -113,182 +111,93 @@ macro_rules! parse_eq { #[test] fn test_basic() { - parse_eq!("foo", cs!("foo", p!("foo", e!(w!("foo"))))); - parse_eq!( - "foo bar", - cs!("foo bar", p!("foo bar", e!(w!("foo"), w!("bar")))) - ); - parse_eq!( - "foo bar baz", - cs!( - "foo bar baz", - p!("foo bar baz", e!(w!("foo"), w!("bar"), w!("baz"))) - ) - ); - parse_eq!( - "foo | bar", - cs!("foo | bar", p!("foo | bar", e!(w!("foo")), e!(w!("bar")))) - ); + parse_eq!("foo", cs!(p!(e!(w!("foo"))))); + parse_eq!("foo bar", cs!(p!(e!(w!("foo"), w!("bar"))))); + parse_eq!("foo bar baz", cs!(p!(e!(w!("foo"), w!("bar"), w!("baz"))))); + parse_eq!("foo | bar", cs!(p!(e!(w!("foo")), e!(w!("bar"))))); parse_eq!( "command ls; perl -E 'say foo' | tr a-z A-Z; builtin echo bar", cs!( - "command ls; perl -E 'say foo' | tr a-z A-Z; builtin echo bar", - p!("command ls", e!(w!("command"), w!("ls"))), + p!(e!(w!("command"), w!("ls"))), p!( - "perl -E 'say foo' | tr a-z A-Z", e!(w!("perl"), w!("-E"), w!(wps!("say foo"))), e!(w!("tr"), w!("a-z"), w!("A-Z")) ), - p!("builtin echo bar", e!(w!("builtin"), w!("echo"), w!("bar"))) + p!(e!(w!("builtin"), w!("echo"), w!("bar"))) ) ); } #[test] fn test_whitespace() { - parse_eq!(" foo ", cs!("foo", p!("foo", e!(w!("foo"))))); - parse_eq!( - " foo # this is a comment", - cs!("foo", p!("foo", e!(w!("foo")))) - ); - parse_eq!("foo#comment", cs!("foo", p!("foo", e!(w!("foo"))))); + parse_eq!(" foo ", cs!(p!(e!(w!("foo"))))); + parse_eq!(" foo # this is a comment", cs!(p!(e!(w!("foo"))))); + parse_eq!("foo#comment", cs!(p!(e!(w!("foo"))))); parse_eq!( "foo;bar|baz;quux#comment", cs!( - "foo;bar|baz;quux", - p!("foo", e!(w!("foo"))), - p!("bar|baz", e!(w!("bar")), e!(w!("baz"))), - p!("quux", e!(w!("quux"))) - ) - ); - parse_eq!( - "foo | bar ", - cs!( - "foo | bar", - p!("foo | bar", e!(w!("foo")), e!(w!("bar"))) + p!(e!(w!("foo"))), + p!(e!(w!("bar")), e!(w!("baz"))), + p!(e!(w!("quux"))) ) ); + parse_eq!("foo | bar ", cs!(p!(e!(w!("foo")), e!(w!("bar"))))); parse_eq!( " abc def ghi |jkl mno| pqr stu; vwxyz # comment", cs!( - "abc def ghi |jkl mno| pqr stu; vwxyz", p!( - "abc def ghi |jkl mno| pqr stu", e!(w!("abc"), w!("def"), w!("ghi")), e!(w!("jkl"), w!("mno")), e!(w!("pqr"), w!("stu")) ), - p!("vwxyz", e!(w!("vwxyz"))) + p!(e!(w!("vwxyz"))) ) ); parse_eq!( "foo 'bar # baz' \"quux # not a comment\" # comment", - cs!( - "foo 'bar # baz' \"quux # not a comment\"", - p!( - "foo 'bar # baz' \"quux # not a comment\"", - e!( - w!("foo"), - w!(wps!("bar # baz")), - w!(wpd!("quux # not a comment")) - ) - ) - ) + cs!(p!(e!( + w!("foo"), + w!(wps!("bar # baz")), + w!(wpd!("quux # not a comment")) + ))) ); } #[test] fn test_redirect() { - parse_eq!( - "foo > bar", - cs!( - "foo > bar", - p!("foo > bar", e!(w!("foo") ; r!(1, w!("bar"), Out))) - ) - ); - parse_eq!( - "foo bar", cs!(p!(e!(w!("foo") ; r!(1, w!("bar"), Out))))); + parse_eq!("foo /dev/null 2>&1", - cs!( - "foo > /dev/null 2>&1", - p!( - "foo > /dev/null 2>&1", - e!( - w!("foo") ; - r!(1, w!("/dev/null"), Out), r!(2, w!("&1"), Out) - ) - ) - ) + cs!(p!(e!( + w!("foo") ; + r!(1, w!("/dev/null"), Out), r!(2, w!("&1"), Out) + ))) ); parse_eq!( "foo >>bar", - cs!( - "foo >>bar", - p!("foo >>bar", e!(w!("foo") ; r!(1, w!("bar"), Append))) - ) + cs!(p!(e!(w!("foo") ; r!(1, w!("bar"), Append)))) ); parse_eq!( "foo >> bar", - cs!( - "foo >> bar", - p!("foo >> bar", e!(w!("foo") ; r!(1, w!("bar"), Append))) - ) + cs!(p!(e!(w!("foo") ; r!(1, w!("bar"), Append)))) ); parse_eq!( "foo > 'bar baz'", - cs!( - "foo > 'bar baz'", - p!( - "foo > 'bar baz'", - e!(w!("foo") ; r!(1, w!(wps!("bar baz")), Out)) - ) - ) + cs!(p!(e!(w!("foo") ; r!(1, w!(wps!("bar baz")), Out)))) ); } #[test] fn test_escape() { - parse_eq!( - "foo\\ bar", - cs!("foo\\ bar", p!("foo\\ bar", e!(w!("foo bar")))) - ); - parse_eq!( - "'foo\\ bar'", - cs!("'foo\\ bar'", p!("'foo\\ bar'", e!(w!(wps!("foo\\ bar"))))) - ); - parse_eq!( - "\"foo\\ bar\"", - cs!( - "\"foo\\ bar\"", - p!("\"foo\\ bar\"", e!(w!(wpd!("foo bar")))) - ) - ); - parse_eq!( - "\"foo\\\"bar\"", - cs!( - "\"foo\\\"bar\"", - p!("\"foo\\\"bar\"", e!(w!(wpd!("foo\"bar")))) - ) - ); - parse_eq!( - "'foo\\'bar\\\\'", - cs!( - "'foo\\'bar\\\\'", - p!("'foo\\'bar\\\\'", e!(w!(wps!("foo'bar\\")))) - ) - ); + parse_eq!("foo\\ bar", cs!(p!(e!(w!("foo bar"))))); + parse_eq!("'foo\\ bar'", cs!(p!(e!(w!(wps!("foo\\ bar")))))); + parse_eq!("\"foo\\ bar\"", cs!(p!(e!(w!(wpd!("foo bar")))))); + parse_eq!("\"foo\\\"bar\"", cs!(p!(e!(w!(wpd!("foo\"bar")))))); + parse_eq!("'foo\\'bar\\\\'", cs!(p!(e!(w!(wps!("foo'bar\\")))))); parse_eq!( "foo > bar\\ baz", - cs!( - "foo > bar\\ baz", - p!("foo > bar\\ baz", e!(w!("foo") ; r!(1, w!("bar baz"), Out))) - ) + cs!(p!(e!(w!("foo") ; r!(1, w!("bar baz"), Out)))) ); } @@ -296,59 +205,29 @@ fn test_escape() { fn test_parts() { parse_eq!( "echo \"$HOME/bin\"", - cs!( - "echo \"$HOME/bin\"", - p!( - "echo \"$HOME/bin\"", - e!(w!("echo"), w!(wpv!("HOME"), wpd!("/bin"))) - ) - ) + cs!(p!(e!(w!("echo"), w!(wpv!("HOME"), wpd!("/bin"))))) ); parse_eq!( "echo $HOME/bin", - cs!( - "echo $HOME/bin", - p!( - "echo $HOME/bin", - e!(w!("echo"), w!(wpv!("HOME"), wpb!("/bin"))) - ) - ) + cs!(p!(e!(w!("echo"), w!(wpv!("HOME"), wpb!("/bin"))))) ); parse_eq!( "echo '$HOME/bin'", - cs!( - "echo '$HOME/bin'", - p!("echo '$HOME/bin'", e!(w!("echo"), w!(wps!("$HOME/bin")))) - ) + cs!(p!(e!(w!("echo"), w!(wps!("$HOME/bin"))))) ); parse_eq!( "echo \"foo\"\"bar\"", - cs!( - "echo \"foo\"\"bar\"", - p!( - "echo \"foo\"\"bar\"", - e!(w!("echo"), w!(wpd!("foo"), wpd!("bar"))) - ) - ) + cs!(p!(e!(w!("echo"), w!(wpd!("foo"), wpd!("bar"))))) ); parse_eq!( "echo $foo$bar$baz", - cs!( - "echo $foo$bar$baz", - p!( - "echo $foo$bar$baz", - e!(w!("echo"), w!(wpv!("foo"), wpv!("bar"), wpv!("baz"))) - ) - ) + cs!(p!(e!( + w!("echo"), + w!(wpv!("foo"), wpv!("bar"), wpv!("baz")) + ))) ); parse_eq!( "perl -E'say \"foo\"'", - cs!( - "perl -E'say \"foo\"'", - p!( - "perl -E'say \"foo\"'", - e!(w!("perl"), w!(wpb!("-E"), wps!("say \"foo\""))) - ) - ) + cs!(p!(e!(w!("perl"), w!(wpb!("-E"), wps!("say \"foo\""))))) ); } -- cgit v1.2.3-54-g00ecf