Skip to content

Commit

Permalink
Test command line argument parsing
Browse files Browse the repository at this point in the history
Clap / rustopt may be configured incorrectly and may refuse to
parse arguments if e.g. a default value of parameter is provided
incorrectly. This commit adds tests that check if the default
configuration for each command can be loaded.
  • Loading branch information
pkolaczk committed Sep 12, 2022
1 parent 697f3d8 commit e1f646b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ winapi-util = "0.1"
reflink = "0.1"

[dev-dependencies]
assert_matches = "1.5"
reflink = "0.1"
serde_test = "1.0"
tempfile = "3.3"
Expand Down
43 changes: 43 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,46 @@ pub struct Config {
#[structopt(subcommand)]
pub command: Command,
}

#[cfg(test)]
mod test {
use crate::config::{Command, Config};
use crate::path::Path;
use assert_matches::assert_matches;
use std::path::PathBuf;
use structopt::StructOpt;

#[test]
fn test_group_command() {
let config: Config = Config::from_iter(vec!["fclones", "group", "dir1", "dir2"]);
assert_matches!(
config.command,
Command::Group(g) if g.paths == vec![Path::from("dir1"), Path::from("dir2")]);
}

#[test]
fn test_dedupe_command() {
let config: Config = Config::from_iter(vec!["fclones", "dedupe"]);
assert_matches!(config.command, Command::Dedupe { .. });
}

#[test]
fn test_remove_command() {
let config: Config = Config::from_iter(vec!["fclones", "remove"]);
assert_matches!(config.command, Command::Remove { .. });
}

#[test]
fn test_link_command() {
let config: Config = Config::from_iter(vec!["fclones", "link"]);
assert_matches!(config.command, Command::Link { .. });
}

#[test]
fn test_move_command() {
let config: Config = Config::from_iter(vec!["fclones", "move", "target"]);
assert_matches!(
config.command,
Command::Move { target, .. } if target == PathBuf::from("target"));
}
}

0 comments on commit e1f646b

Please sign in to comment.