#[macro_use] extern crate lazy_static; extern crate find_folder; use find_folder::Search; extern crate unichars; use unichars::*; lazy_static! { static ref PATH: ::std::path::PathBuf = { Search::ParentsThenKids(3, 3).for_folder("target").unwrap().join(::std::path::Path::new("debug/pwgenr")) }; } macro_rules! exe { ($($arg:expr),*) => { match ::std::process::Command::new(&*PATH) // Start a repetition: $( // Each repeat will contain the following statement, with // $arg replaced with the corresponding expression. .arg($arg) )* .output() .expect("failed to execute process") { ::std::process::Output { status: _, stdout: out, stderr: err } => { let out = String::from_utf8(out).unwrap(); let err = String::from_utf8(err).unwrap(); println!("out\n{}\nerr\n{}", out, err); // skip last empty line (out.rsplit('\n').skip(1).map(|x| x.to_string()).collect::>(), err) } } } } #[test] fn length_amount() { let (out, _) = exe!("19", "15"); assert_eq!(out.len(), 15); for line in &out { assert_eq!(line.chars().count(), 19); } } #[test] fn ascii() { let (out, _) = exe!("-a", "1", "10"); assert_eq!(out.len(), 10); for line in &out { assert_eq!(line.chars().count(), 1); for c in line.chars() { assert!(ASCII.contains(&c)); } } } #[test] fn categories() { let (out, _) = exe!("-c", "box", "arrows", "--", "16", "20"); assert_eq!(out.len(), 20); for line in &out { assert_eq!(line.chars().count(), 16); for c in line.chars() { assert!(BOX.contains(&c) || ARROWS.contains(&c)); } } } #[test] fn empty() { let (out, _) = exe!("0", "0"); assert_eq!(out.len(), 0); }