mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
test: add tests for CARGO_MANIFEST_PATH in build.rs
- Uses same checks as for already existing CARGO_MANIFEST_DIR
This commit is contained in:
parent
051478c12e
commit
d4ac929563
@ -1625,6 +1625,7 @@ fn crate_env_vars() {
|
|||||||
static VERSION_PRE: &'static str = env!("CARGO_PKG_VERSION_PRE");
|
static VERSION_PRE: &'static str = env!("CARGO_PKG_VERSION_PRE");
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||||
static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
|
static CARGO_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
|
||||||
|
static CARGO_MANIFEST_PATH: &'static str = env!("CARGO_MANIFEST_PATH");
|
||||||
static PKG_NAME: &'static str = env!("CARGO_PKG_NAME");
|
static PKG_NAME: &'static str = env!("CARGO_PKG_NAME");
|
||||||
static HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE");
|
static HOMEPAGE: &'static str = env!("CARGO_PKG_HOMEPAGE");
|
||||||
static REPOSITORY: &'static str = env!("CARGO_PKG_REPOSITORY");
|
static REPOSITORY: &'static str = env!("CARGO_PKG_REPOSITORY");
|
||||||
@ -1638,9 +1639,9 @@ fn crate_env_vars() {
|
|||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let s = format!("{}-{}-{} @ {} in {}", VERSION_MAJOR,
|
let s = format!("{}-{}-{} @ {} in {} file {}", VERSION_MAJOR,
|
||||||
VERSION_MINOR, VERSION_PATCH, VERSION_PRE,
|
VERSION_MINOR, VERSION_PATCH, VERSION_PRE,
|
||||||
CARGO_MANIFEST_DIR);
|
CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH);
|
||||||
assert_eq!(s, foo::version());
|
assert_eq!(s, foo::version());
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
assert_eq!("foo", PKG_NAME);
|
assert_eq!("foo", PKG_NAME);
|
||||||
@ -1674,12 +1675,13 @@ fn crate_env_vars() {
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn version() -> String {
|
pub fn version() -> String {
|
||||||
format!("{}-{}-{} @ {} in {}",
|
format!("{}-{}-{} @ {} in {} file {}",
|
||||||
env!("CARGO_PKG_VERSION_MAJOR"),
|
env!("CARGO_PKG_VERSION_MAJOR"),
|
||||||
env!("CARGO_PKG_VERSION_MINOR"),
|
env!("CARGO_PKG_VERSION_MINOR"),
|
||||||
env!("CARGO_PKG_VERSION_PATCH"),
|
env!("CARGO_PKG_VERSION_PATCH"),
|
||||||
env!("CARGO_PKG_VERSION_PRE"),
|
env!("CARGO_PKG_VERSION_PRE"),
|
||||||
env!("CARGO_MANIFEST_DIR"))
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
env!("CARGO_MANIFEST_PATH"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_no_int_test_env() {
|
pub fn check_no_int_test_env() {
|
||||||
@ -1795,7 +1797,7 @@ fn crate_env_vars() {
|
|||||||
println!("bin");
|
println!("bin");
|
||||||
p.process(&p.bin("foo-bar"))
|
p.process(&p.bin("foo-bar"))
|
||||||
.with_stdout_data(str![[r#"
|
.with_stdout_data(str![[r#"
|
||||||
0-5-1 @ alpha.1 in [ROOT]/foo
|
0-5-1 @ alpha.1 in [ROOT]/foo file [ROOT]/foo/Cargo.toml
|
||||||
|
|
||||||
"#]])
|
"#]])
|
||||||
.run();
|
.run();
|
||||||
@ -1863,12 +1865,15 @@ fn cargo_rustc_current_dir_foreign_workspace_dep() {
|
|||||||
fn baz_env() {
|
fn baz_env() {
|
||||||
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
|
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
|
||||||
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
||||||
|
let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
|
||||||
let current_dir = std::env::current_dir().expect("current_dir");
|
let current_dir = std::env::current_dir().expect("current_dir");
|
||||||
let file_path = workspace_dir.join(file!());
|
let file_path = workspace_dir.join(file!());
|
||||||
assert!(file_path.exists(), "{}", file_path.display());
|
assert!(file_path.exists(), "{}", file_path.display());
|
||||||
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
|
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
|
||||||
|
let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
|
||||||
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
|
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
|
||||||
assert_eq!(workspace_dir, manifest_dir);
|
assert_eq!(workspace_dir, manifest_dir.clone());
|
||||||
|
assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
@ -1957,12 +1962,15 @@ fn cargo_rustc_current_dir_non_local_dep() {
|
|||||||
fn bar_env() {
|
fn bar_env() {
|
||||||
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
|
let workspace_dir = Path::new(option_env!("CARGO_RUSTC_CURRENT_DIR").expect("CARGO_RUSTC_CURRENT_DIR"));
|
||||||
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
let manifest_dir = Path::new(option_env!("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
|
||||||
|
let manifest_path = Path::new(option_env!("CARGO_MANIFEST_PATH").expect("CARGO_MANIFEST_PATH"));
|
||||||
let current_dir = std::env::current_dir().expect("current_dir");
|
let current_dir = std::env::current_dir().expect("current_dir");
|
||||||
let file_path = workspace_dir.join(file!());
|
let file_path = workspace_dir.join(file!());
|
||||||
assert!(file_path.exists(), "{}", file_path.display());
|
assert!(file_path.exists(), "{}", file_path.display());
|
||||||
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
|
let workspace_dir = std::fs::canonicalize(current_dir.join(workspace_dir)).expect("CARGO_RUSTC_CURRENT_DIR");
|
||||||
|
let manifest_path = std::fs::canonicalize(current_dir.join(manifest_dir.clone()).join("Cargo.toml")).expect("CARGO_MANIFEST_PATH");
|
||||||
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
|
let manifest_dir = std::fs::canonicalize(current_dir.join(manifest_dir)).expect("CARGO_MANIFEST_DIR");
|
||||||
assert_eq!(workspace_dir, manifest_dir);
|
assert_eq!(workspace_dir, manifest_dir.clone());
|
||||||
|
assert_eq!(manifest_dir.join("Cargo.toml"), manifest_path);
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user