From 8ad5f9bf531a4848b1104b7b389a20171624c82f Mon Sep 17 00:00:00 2001 From: Abdou Seck Date: Thu, 4 Jun 2020 10:31:17 -0400 Subject: feat: Add a --nocapture option to display test harnesses' outputs This new feature can be accessed by invoking rustlings with --nocapture. Both unit and integration tests added. closes #262 BREAKING CHANGES: The following function take a new boolean argument: * `run` * `verify` * `test` * `compile_and_test` --- src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f3f7f07..9c64de2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,10 +28,9 @@ fn main() { .author("Olivia Hugger, Carol Nichols") .about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code") .arg( - Arg::with_name("verbose") - .short("V") - .long("verbose") - .help("Show tests' standard output") + Arg::with_name("nocapture") + .long("nocapture") + .help("Show outputs from the test exercises") ) .subcommand( SubCommand::with_name("verify") @@ -87,6 +86,7 @@ fn main() { let toml_str = &fs::read_to_string("info.toml").unwrap(); let exercises = toml::from_str::(toml_str).unwrap().exercises; + let verbose = matches.is_present("nocapture"); if let Some(ref matches) = matches.subcommand_matches("run") { let name = matches.value_of("name").unwrap(); @@ -98,7 +98,7 @@ fn main() { std::process::exit(1) }); - run(&exercise).unwrap_or_else(|_| std::process::exit(1)); + run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); } if let Some(ref matches) = matches.subcommand_matches("hint") { @@ -116,10 +116,10 @@ fn main() { } if matches.subcommand_matches("verify").is_some() { - verify(&exercises).unwrap_or_else(|_| std::process::exit(1)); + verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); } - if matches.subcommand_matches("watch").is_some() && watch(&exercises).is_ok() { + if matches.subcommand_matches("watch").is_some() && watch(&exercises, verbose).is_ok() { println!( "{emoji} All exercises completed! {emoji}", emoji = Emoji("🎉", "★") @@ -161,7 +161,7 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { }); } -fn watch(exercises: &[Exercise]) -> notify::Result<()> { +fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { /* Clears the terminal with an ANSI escape code. Works in UNIX and newer Windows terminals. */ fn clear_screen() { @@ -176,7 +176,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> { clear_screen(); let to_owned_hint = |t: &Exercise| t.hint.to_owned(); - let failed_exercise_hint = match verify(exercises.iter()) { + let failed_exercise_hint = match verify(exercises.iter(), verbose) { Ok(_) => return Ok(()), Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))), }; @@ -191,7 +191,7 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> { .iter() .skip_while(|e| !filepath.ends_with(&e.path)); clear_screen(); - match verify(pending_exercises) { + match verify(pending_exercises, verbose) { Ok(_) => return Ok(()), Err(exercise) => { let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap(); -- cgit v1.2.3