Skip to content

Commit

Permalink
test: factor out begin command for keeping it dry
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
  • Loading branch information
simonsan committed Mar 1, 2024
1 parent f3d61e6 commit c9f902d
Showing 1 changed file with 22 additions and 60 deletions.
82 changes: 22 additions & 60 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ fn temp_dir_with(path: &str) -> TestResult<String> {
Ok(dir_str)
}

fn fixture_begin_activity(dir_str: &String) -> TestResult<()> {
StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;

Ok(())
}

#[test]
fn test_version_command_passes() -> TestResult<()> {
_ = pace_runner()?
Expand Down Expand Up @@ -89,18 +106,7 @@ fn test_now_no_activities_snapshot_passes() -> TestResult<()> {
fn test_now_with_active_activity_snapshot_passes() -> TestResult<()> {
let dir_str = temp_dir_with("activities.pace.toml")?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
&dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;
fixture_begin_activity(&dir_str)?;

assert_cmd_snapshot!(StdCommand::new(env!("CARGO_BIN_EXE_pace")).args([
"--activity-log-file",
Expand All @@ -115,18 +121,7 @@ fn test_now_with_active_activity_snapshot_passes() -> TestResult<()> {
fn test_end_with_active_activity_snapshot_passes() -> TestResult<()> {
let dir_str = temp_dir_with("activities.pace.toml")?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
&dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;
fixture_begin_activity(&dir_str)?;

assert_cmd_snapshot!(StdCommand::new(env!("CARGO_BIN_EXE_pace")).args([
"--activity-log-file",
Expand All @@ -141,18 +136,7 @@ fn test_end_with_active_activity_snapshot_passes() -> TestResult<()> {
fn test_hold_with_active_activity_snapshot_passes() -> TestResult<()> {
let dir_str = temp_dir_with("activities.pace.toml")?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
&dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;
fixture_begin_activity(&dir_str)?;

assert_cmd_snapshot!(StdCommand::new(env!("CARGO_BIN_EXE_pace")).args([
"--activity-log-file",
Expand All @@ -167,18 +151,7 @@ fn test_hold_with_active_activity_snapshot_passes() -> TestResult<()> {
fn test_resume_with_held_activity_snapshot_passes() -> TestResult<()> {
let dir_str = temp_dir_with("activities.pace.toml")?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
&dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;
fixture_begin_activity(&dir_str)?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args(["--activity-log-file", &dir_str, "hold"])
Expand All @@ -197,18 +170,7 @@ fn test_resume_with_held_activity_snapshot_passes() -> TestResult<()> {
fn test_adjust_activity_snapshot_passes() -> TestResult<()> {
let dir_str = temp_dir_with("activities.pace.toml")?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
"--activity-log-file",
&dir_str,
"begin",
"MyActivity",
"--tags",
"tag1,tag2",
"--category",
"MyCategory::SubCategory",
])
.output()?;
fixture_begin_activity(&dir_str)?;

StdCommand::new(env!("CARGO_BIN_EXE_pace"))
.args([
Expand Down

0 comments on commit c9f902d

Please sign in to comment.