From f0b29aeeef41d4056095f44317e205bbe18c68ba Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 4 Aug 2024 14:30:43 -0700 Subject: [PATCH] Add `cargo-insta` version to env vars We don't use this yet, but could be helpful in areas such as #482 --- cargo-insta/src/cli.rs | 6 +++++- cargo-insta/src/utils.rs | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cargo-insta/src/cli.rs b/cargo-insta/src/cli.rs index 6b17827a..239f8fd5 100644 --- a/cargo-insta/src/cli.rs +++ b/cargo-insta/src/cli.rs @@ -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}; @@ -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 { diff --git a/cargo-insta/src/utils.rs b/cargo-insta/src/utils.rs index 2d1091a3..b5b22315 100644 --- a/cargo-insta/src/utils.rs +++ b/cargo-insta/src/utils.rs @@ -27,3 +27,9 @@ impl fmt::Display for ErrMsg { pub(crate) fn err_msg>(s: S) -> Box { 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() +}