mod math; use std::{ borrow::Cow, ffi::OsStr, io::{self, Write}, }; use expect_test::{expect, Expect}; use oyster_builtin_proc::builtin; use oyster_parser::ast; use oyster_runtime::Shell; use crate::collect_output; #[builtin(description = "test builtin")] fn test_builtin(_: &mut Shell, _: &[Cow]) { writeln!(io::stdout(), "this is a test").unwrap(); } fn check(ast: &ast::Code, expect: Expect) { let actual = collect_output(|| { let mut shell = Shell::new().unwrap(); shell.builtins_mut().add(test_builtin); shell.run(ast).unwrap(); }); expect.assert_debug_eq(&actual); } #[test] fn simple_builtin() { let ast = { use oyster_parser::ast::*; Code(vec![Statement::Pipeline(Pipeline(vec![Command( vec![Word(vec![WordPart::Text("test_builtin")])], Redirect::None, )]))]) }; check( &ast, expect![[r#" "this is a test\r\n" "#]], ); } #[test] fn builtin_redirection() { let ast = { use oyster_parser::ast::*; Code(vec![Statement::Pipeline(Pipeline(vec![ Command( vec![Word(vec![WordPart::Text("test_builtin")])], Redirect::Stdout, ), Command( vec![ Word(vec![WordPart::Text("wc")]), Word(vec![WordPart::Text("-c")]), ], Redirect::None, ), ]))]) }; check( &ast, expect![[r#" "15\r\n" "#]], ); }