Add first tests
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
af8e669859
commit
7aeeeae2f1
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.1.6", features = ["derive"] }
|
||||
regex = { version = "*" }
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,3 +1,16 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Parser;
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Arguments {
|
||||
#[clap(short, long, default_value = ".carman")]
|
||||
conf_file: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Arguments::parse();
|
||||
|
||||
println!("Hello, world!");
|
||||
println!("{:?}", args);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// filename: tests/integration.rs
|
||||
|
||||
|
||||
mod integration {
|
||||
use regex::Regex;
|
||||
use std::process::Command;
|
||||
use std::process::Output;
|
||||
|
||||
static WITHOUT_ARGS_OUTPUT: &'static str = " USAGE:
|
||||
carman [FLAGS] [OPTIONS] <URL>
|
||||
|
@ -10,12 +11,24 @@ mod integration {
|
|||
";
|
||||
|
||||
#[test]
|
||||
fn calling_carman_without_args() {
|
||||
let output = Command::new("./target/debug/carman")
|
||||
fn calling_carman_without_args_returns_result() {
|
||||
let output = Command::new("./target/debug/carman")
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
let re = Regex::new(r"^Hello").unwrap();
|
||||
assert!(re.is_match(&String::from_utf8_lossy(&output.stdout)));
|
||||
}
|
||||
|
||||
assert_eq!(String::from_utf8_lossy(&output.stderr), WITHOUT_ARGS_OUTPUT);
|
||||
#[test]
|
||||
fn calling_carman_with_help_returns_usage() {
|
||||
let output = Command::new("./target/debug/carman")
|
||||
.arg("--help")
|
||||
.output()
|
||||
.expect("failed to execute process");
|
||||
let re = Regex::new(r"^carman").unwrap();
|
||||
assert!(re.is_match(&String::from_utf8_lossy(&output.stdout)));
|
||||
let re = Regex::new(r"--help").unwrap();
|
||||
assert!(re.is_match(&String::from_utf8_lossy(&output.stdout)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue