Skip to content

Commit

Permalink
Add cargo-insta version to env vars
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 mitsuhiko#482
  • Loading branch information
max-sixty committed Aug 4, 2024
1 parent 16d243d commit f0b29ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ use insta::_cargo_insta_support::{
use serde::Serialize;
use uuid::Uuid;

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

use clap::{Args, Parser, Subcommand, ValueEnum};

Expand Down Expand Up @@ -822,6 +825,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 f0b29ae

Please sign in to comment.