@@ -58,28 +58,32 @@ pub fn version() -> VersionInfo {
58
58
} ;
59
59
}
60
60
61
- // This is the version set in bootstrap, which we use to match rustc.
62
- let version = option_env_str ! ( "CFG_RELEASE" ) . unwrap_or_else ( || {
63
- // If cargo is not being built by bootstrap, then we just use the
64
- // version from cargo's own `Cargo.toml`.
65
- //
66
- // There are two versions at play here:
67
- // - version of cargo-the-binary, which you see when you type `cargo --version`
68
- // - version of cargo-the-library, which you download from crates.io for use
69
- // in your packages.
70
- //
71
- // The library is permanently unstable, so it always has a 0 major
72
- // version. However, the CLI now reports a stable 1.x version
73
- // (starting in 1.26) which stays in sync with rustc's version.
74
- //
75
- // Coincidentally, the minor version for cargo-the-library is always
76
- // +1 of rustc's minor version (that is, `rustc 1.11.0` corresponds to
77
- // `cargo `0.12.0`). The versions always get bumped in lockstep, so
78
- // this should continue to hold.
79
- let minor = env ! ( "CARGO_PKG_VERSION_MINOR" ) . parse :: < u8 > ( ) . unwrap ( ) - 1 ;
80
- let patch = env ! ( "CARGO_PKG_VERSION_PATCH" ) . parse :: < u8 > ( ) . unwrap ( ) ;
81
- format ! ( "1.{}.{}" , minor, patch)
82
- } ) ;
61
+ // __CARGO_TEST_CARGO_VERSION is for testing purposes only.
62
+ let version = std:: env:: var ( "__CARGO_TEST_CARGO_VERSION" )
63
+ . ok ( )
64
+ // This is the version set in bootstrap, which we use to match rustc.
65
+ . or_else ( || option_env_str ! ( "CFG_RELEASE" ) )
66
+ . unwrap_or_else ( || {
67
+ // If cargo is not being built by bootstrap, then we just use the
68
+ // version from cargo's own `Cargo.toml`.
69
+ //
70
+ // There are two versions at play here:
71
+ // - version of cargo-the-binary, which you see when you type `cargo --version`
72
+ // - version of cargo-the-library, which you download from crates.io for use
73
+ // in your packages.
74
+ //
75
+ // The library is permanently unstable, so it always has a 0 major
76
+ // version. However, the CLI now reports a stable 1.x version
77
+ // (starting in 1.26) which stays in sync with rustc's version.
78
+ //
79
+ // Coincidentally, the minor version for cargo-the-library is always
80
+ // +1 of rustc's minor version (that is, `rustc 1.11.0` corresponds to
81
+ // `cargo `0.12.0`). The versions always get bumped in lockstep, so
82
+ // this should continue to hold.
83
+ let minor = env ! ( "CARGO_PKG_VERSION_MINOR" ) . parse :: < u8 > ( ) . unwrap ( ) - 1 ;
84
+ let patch = env ! ( "CARGO_PKG_VERSION_PATCH" ) . parse :: < u8 > ( ) . unwrap ( ) ;
85
+ format ! ( "1.{}.{}" , minor, patch)
86
+ } ) ;
83
87
84
88
let release_channel = option_env_str ! ( "CFG_RELEASE_CHANNEL" ) ;
85
89
let commit_info = option_env_str ! ( "CARGO_COMMIT_HASH" ) . map ( |commit_hash| CommitInfo {
0 commit comments