mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
tests: fix incorrect argument passing; new test
This commit is contained in:
+11
-4
@@ -8,6 +8,8 @@
|
||||
mod cli;
|
||||
mod utils;
|
||||
|
||||
use std::env::args_os;
|
||||
|
||||
use bumpalo::Bump;
|
||||
use clap::Parser as _;
|
||||
use color_eyre::Result;
|
||||
@@ -20,14 +22,19 @@ use crate::{
|
||||
|
||||
fn main() {
|
||||
if let Err(e) = ensure_consistent_panic(uu_main) {
|
||||
exit_err(e)
|
||||
exit_err(Some(e))
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
fn uu_main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
println!("{args:?}");
|
||||
let args = match Args::try_parse_from(args_os()) {
|
||||
Ok(args) => args,
|
||||
Err(msg) => {
|
||||
msg.print()?;
|
||||
exit_err(Option::<&str>::None)
|
||||
}
|
||||
};
|
||||
|
||||
let arena = Bump::with_capacity(4000); // 4KB minus metadata-ish
|
||||
let mut parser = Parser::new(&arena);
|
||||
@@ -38,7 +45,7 @@ fn uu_main() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
println!("{ast}");
|
||||
println!("---\n{ast}");
|
||||
dbg!(arena.chunk_capacity());
|
||||
|
||||
// for token in lex {
|
||||
|
||||
+5
-3
@@ -65,13 +65,15 @@ pub fn exit_with(res: Result<Option<impl Into<ExitCode>>, impl Display + Debug>)
|
||||
let code = match res {
|
||||
Ok(Some(x)) => x.into(),
|
||||
Ok(None) => EXIT_SUCCESS,
|
||||
Err(e) => exit_err(e),
|
||||
Err(e) => exit_err(Some(e)),
|
||||
};
|
||||
|
||||
exit(code)
|
||||
}
|
||||
|
||||
pub fn exit_err(err: impl Display + Debug) -> ! {
|
||||
eprintln!("{err:?}");
|
||||
pub fn exit_err(err: Option<impl Display + Debug>) -> ! {
|
||||
if let Some(err) = err {
|
||||
eprintln!("{err}");
|
||||
}
|
||||
exit(EXIT_FAILURE)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::env;
|
||||
|
||||
use uutests::util::TestScenario;
|
||||
|
||||
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_awk");
|
||||
|
||||
#[ctor::ctor]
|
||||
@@ -12,5 +14,9 @@ fn init() {
|
||||
}
|
||||
}
|
||||
|
||||
fn ucmd() -> uutests::util::UCommand {
|
||||
TestScenario::new("awk").cmd(TESTS_BINARY)
|
||||
}
|
||||
|
||||
#[path = "by-util/test_awk.rs"]
|
||||
mod test_awk;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
use uutests::new_ucmd;
|
||||
use crate::ucmd;
|
||||
|
||||
#[test]
|
||||
fn empty_program_succeeds() {
|
||||
new_ucmd!().arg("").succeeds();
|
||||
ucmd().arg("").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "parser does not yet support print/field expressions"]
|
||||
fn print_first_field() {
|
||||
new_ucmd!().arg("{ print $1 }").succeeds();
|
||||
ucmd().args(&["{ print $1 }"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_args_fails_code_one() {
|
||||
ucmd().fails_with_code(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user