flagon-io/hello

public

Greets people from the command line. The sample repository for g1t.

hello/tests/cli.rs

48 lines1,178 bytesCodeBlame

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 exits1use std::process::Command;
2
3#[test]
4fn 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 times15
16fn 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]
24fn 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(),
29 "Hello, Ada!\n".repeat(3)
30 );
31}
32
33#[test]
34fn 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(),
39 "HELLO, ADA!\n".repeat(2)
40 );
41}
42
43#[test]
44fn times_with_bad_value_fails() {
45 let output = run(&["--times", "abc"]);
46 assert!(!output.status.success());
47 assert!(!output.stderr.is_empty());
48}