diff --git a/Cargo.toml b/Cargo.toml index 2086689..974af93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,7 @@ serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } dirs = "4.0.0" anyhow = "1.0.62" -enigo = "0.0.14" \ No newline at end of file +enigo = "0.0.14" + +[dev-dependencies] +assert_cmd = "2.0.12" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2e6cf7f..1af57eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,3 +7,35 @@ mod keyboard; fn main() { cli::parse(); } + +#[cfg(test)] +mod tests { + use assert_cmd::Command; + + #[test] + fn main() { + let mut cmd = Command::cargo_bin("ka").unwrap(); + cmd.arg("-h"); + cmd.assert().success(); + let expected_output = format!( + r###"Keep you machine awake + +USAGE: + ka [SUBCOMMAND] + +OPTIONS: + -h, --help Print help information + -V, --version Print version information + +SUBCOMMANDS: + help Print this message or the help of the given subcommand(s) + keyboard Use keyboard to keep your machine awake [default tab & windows/super/command] + mouse Use mouse to keep your machine awake + programname Set name for this program +"### + ); + let actual_output = String::from_utf8(cmd.assert().get_output().to_owned().stdout).unwrap(); + assert!(actual_output.contains(&expected_output)); + } + +} \ No newline at end of file