Skip to content

Commit

Permalink
Add cargo-insta version to env vars (#554)
Browse files Browse the repository at this point in the history
We don't use this yet, but could be helpful in areas such as #482
  • Loading branch information
max-sixty authored Aug 9, 2024
1 parent 3db3ba8 commit 998d58a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use uuid::Uuid;

use crate::cargo::{find_snapshot_roots, Package};
use crate::container::{Operation, SnapshotContainer};
use crate::utils::cargo_insta_version;
use crate::utils::{err_msg, QuietExit};
use crate::walk::{find_snapshots, make_snapshot_walker, FindFlags};

Expand Down Expand Up @@ -863,6 +864,7 @@ fn prepare_test_runner<'snapshot_ref>(

// An env var to indicate we're running under cargo-insta
proc.env("INSTA_CARGO_INSTA", "1");
proc.env("INSTA_CARGO_INSTA_VERSION", cargo_insta_version());

let snapshot_ref_file = if unreferenced != UnreferencedSnapshots::Ignore {
match snapshot_ref_file {
Expand Down
6 changes: 6 additions & 0 deletions cargo-insta/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ impl fmt::Display for ErrMsg {
pub(crate) fn err_msg<S: Into<String>>(s: S) -> Box<dyn Error> {
Box::new(ErrMsg(s.into()))
}

/// cargo-insta version
// We could put this in a lazy_static
pub(crate) fn cargo_insta_version() -> String {
env!("CARGO_PKG_VERSION").to_string()
}

0 comments on commit 998d58a

Please sign in to comment.