Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Add --version flag that prints the crate version and exits | 1 | use std::process::Command; |
| 2 | ||
| 3 | #[test] | |
| 4 | fn version_flag_prints_crate_version() { | |
| 5 | let output = Command::new(env!("CARGO_BIN_EXE_hello")) | |
| 6 | .arg("--version") | |
| 7 | .output() | |
| 8 | .unwrap(); | |
| 9 | assert!(output.status.success()); | |
| 10 | assert_eq!( | |
| 11 | String::from_utf8(output.stdout).unwrap(), | |
| 12 | format!("{}\n", env!("CARGO_PKG_VERSION")) | |
| 13 | ); | |
| 14 | } | |
| Add --times N flag that prints the greeting N times | 15 | |
| 16 | fn run(args: &[&str]) -> std::process::Output { | |
| 17 | Command::new(env!("CARGO_BIN_EXE_hello")) | |
| 18 | .args(args) | |
| 19 | .output() | |
| 20 | .unwrap() | |
| 21 | } | |
| 22 | ||
| 23 | #[test] | |
| 24 | fn times_prints_greeting_repeatedly() { | |
| 25 | let output = run(&["--times", "3", "Ada"]); | |
| 26 | assert!(output.status.success()); | |
| 27 | assert_eq!( | |
| 28 | String::from_utf8(output.stdout).unwrap(), | |
| Merge #42: Greet with Hi instead of Hello | 29 | "Hi, Ada!\n".repeat(3) |
| Add --times N flag that prints the greeting N times | 30 | ); |
| 31 | } | |
| 32 | ||
| 33 | #[test] | |
| 34 | fn times_combines_with_shout() { | |
| 35 | let output = run(&["--times", "2", "--shout", "Ada"]); | |
| 36 | assert!(output.status.success()); | |
| 37 | assert_eq!( | |
| 38 | String::from_utf8(output.stdout).unwrap(), | |
| Merge #42: Greet with Hi instead of Hello | 39 | "HI, ADA!\n".repeat(2) |
| Add --times N flag that prints the greeting N times | 40 | ); |
| 41 | } | |
| 42 | ||
| 43 | #[test] | |
| 44 | fn times_with_bad_value_fails() { | |
| 45 | let output = run(&["--times", "abc"]); | |
| 46 | assert!(!output.status.success()); | |
| 47 | assert!(!output.stderr.is_empty()); | |
| 48 | } | |
| Merge #53: Add a --lang option (en, es, fr) to the greeter | 49 | |
| 50 | #[test] | |
| 51 | fn lang_es_greets_in_spanish() { | |
| 52 | let output = run(&["--lang", "es", "Ana"]); | |
| 53 | assert!(output.status.success()); | |
| 54 | assert_eq!(String::from_utf8(output.stdout).unwrap(), "¡Hola, Ana!\n"); | |
| 55 | } | |
| 56 | ||
| 57 | #[test] | |
| 58 | fn lang_fr_greets_in_french() { | |
| 59 | let output = run(&["--lang", "fr", "Luc"]); | |
| 60 | assert!(output.status.success()); | |
| 61 | assert_eq!(String::from_utf8(output.stdout).unwrap(), "Bonjour, Luc !\n"); | |
| 62 | } | |
| 63 | ||
| 64 | #[test] | |
| 65 | fn lang_en_is_the_default() { | |
| 66 | let output = run(&["--lang", "en", "Ada"]); | |
| 67 | assert!(output.status.success()); | |
| 68 | assert_eq!(String::from_utf8(output.stdout).unwrap(), "Hi, Ada!\n"); | |
| 69 | let output = run(&["Ada"]); | |
| 70 | assert_eq!(String::from_utf8(output.stdout).unwrap(), "Hi, Ada!\n"); | |
| 71 | } | |
| 72 | ||
| 73 | #[test] | |
| 74 | fn lang_unknown_fails_naming_supported_languages() { | |
| 75 | let output = run(&["--lang", "de", "Ada"]); | |
| 76 | assert_eq!(output.status.code(), Some(2)); | |
| 77 | let stderr = String::from_utf8(output.stderr).unwrap(); | |
| 78 | assert!(stderr.contains("en, es, fr"), "stderr was {stderr:?}"); | |
| 79 | } | |
| 80 | ||
| 81 | #[test] | |
| 82 | fn lang_missing_value_fails() { | |
| 83 | let output = run(&["--lang"]); | |
| 84 | assert_eq!(output.status.code(), Some(2)); | |
| 85 | let stderr = String::from_utf8(output.stderr).unwrap(); | |
| 86 | assert!(stderr.contains("--lang requires a value"), "stderr was {stderr:?}"); | |
| 87 | } | |
| Add --quiet flag that prints nothing | 88 | |
| 89 | #[test] | |
| 90 | fn quiet_prints_nothing() { | |
| 91 | let output = run(&["--quiet", "Ada"]); | |
| 92 | assert!(output.status.success()); | |
| 93 | assert!(output.stdout.is_empty()); | |
| 94 | } | |
| Add --loud flag that ends the greeting with three exclamation marks | 95 | |
| 96 | #[test] | |
| 97 | fn loud_ends_with_three_exclamation_marks() { | |
| 98 | let output = run(&["--loud", "Ada"]); | |
| 99 | assert!(output.status.success()); | |
| 100 | assert_eq!(String::from_utf8(output.stdout).unwrap(), "Hi, Ada!!!\n"); | |
| 101 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.