Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion toolproof/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,20 @@ async fn main_inner() -> Result<(), ()> {
);
println!("{}", msg.green());
Ok(success)
} else if universe.ctx.params.update {
if let Err(e) = std::fs::write(&file.file_path, &output_doc) {
eprintln!("Unable to write updated snapshot to disk.\n{e}");
return Err(HoldingError::TestFailure);
}
let msg = format!(
"{}{}{} {}",
"✓ ".green(),
dur.green().dimmed(),
&file.name.green(),
"(snapshot updated)".cyan()
);
println!("{}", msg);
Ok(ToolproofTestSuccess::Passed { attempts: 0 })
} else {
println!(
"{}",
Expand All @@ -577,7 +591,7 @@ async fn main_inner() -> Result<(), ()> {
);
println!(
"\n{}",
"Run in interactive mode (-i) to accept new snapshots\n"
"Run in interactive mode (-i) or with --update (-u) to accept new snapshots\n"
.bright_red()
.bold()
);
Expand Down
14 changes: 14 additions & 0 deletions toolproof/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ fn get_cli_matches() -> ArgMatches {
)
.action(clap::ArgAction::SetTrue),
)
.arg(
arg!(
-u --update ... "Automatically accept all snapshot changes"
)
.action(clap::ArgAction::SetTrue),
)
.arg(
arg!(
-s --skiphooks ... "Skip running any hooks (e.g. before_all)"
Expand Down Expand Up @@ -203,6 +209,10 @@ pub struct ToolproofParams {
/// Run all tests when in interactive mode
pub all: bool,

/// Automatically accept all snapshot changes
#[setting(env = "TOOLPROOF_UPDATE")]
pub update: bool,

/// Run a specific test
#[setting(env = "TOOLPROOF_RUN_NAME")]
pub run_name: Option<String>,
Expand Down Expand Up @@ -305,6 +315,10 @@ impl ToolproofParams {
self.all = true;
}

if cli_matches.get_flag("update") {
self.update = true;
}

if cli_matches.get_flag("skiphooks") {
self.skip_hooks = true;
}
Expand Down
2 changes: 1 addition & 1 deletion toolproof/test_suite/base/snapshot.toolproof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ steps:
╎--- END SNAPSHOT CHANGE ---
╎Run in interactive mode (-i) to accept new snapshots
╎Run in interactive mode (-i) or with --update (-u) to accept new snapshots
╎Finished running tests
Expand Down
39 changes: 39 additions & 0 deletions toolproof/test_suite/base/snapshot_update.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Snapshots can be auto-updated with --update flag

steps:
- step: I have a "my_test.toolproof.yml" file with the content {yaml}
yaml: |-
name: Inner snapshot test with wrong content

steps:
- I run 'echo "Aenean eu leo quam"'
- snapshot: stdout
snapshot_content: |-
╎bad
- I run "%toolproof_path% --porcelain -u"
- snapshot: stdout
snapshot_content: |-
╎Running tests
╎✓ Inner snapshot test with wrong content (snapshot updated)
╎Finished running tests
╎Total passing tests: 1
╎Passed after retry: 0
╎Failing tests: 0
╎Skipped tests: 0
╎All tests passed
- step: I have a "expected_updated.toolproof.yml" file with the content {yaml}
yaml: |-
name: Inner snapshot test with wrong content

steps:
- I run 'echo "Aenean eu leo quam"'
- snapshot: stdout
snapshot_content: |-
╎Aenean eu leo quam
- I run "diff my_test.toolproof.yml expected_updated.toolproof.yml"
- stderr should be empty
Loading