Refactor command-line handling into modules per subcommands

This commit is contained in:
Dustin J. Mitchell 2020-11-23 19:33:04 -05:00
parent e0b69a62b1
commit fe4183c3ca
12 changed files with 560 additions and 59 deletions

42
cli/tests/cli.rs Normal file
View file

@ -0,0 +1,42 @@
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
// This tests that the task binary is running and parsing arguments. The details of subcommands
// are handled with unit tests.
#[test]
fn help() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("task")?;
cmd.arg("--help");
cmd.assert()
.success()
.stdout(predicate::str::contains("Personal task-tracking"));
Ok(())
}
#[test]
fn version() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("task")?;
cmd.arg("--version");
cmd.assert()
.success()
.stdout(predicate::str::contains("TaskChampion"));
Ok(())
}
#[test]
fn invalid_option() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("task")?;
cmd.arg("--no-such-option");
cmd.assert()
.failure()
.stderr(predicate::str::contains("USAGE"));
Ok(())
}