Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cargo-insta version to env vars #554

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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()
}
Loading