Skip to content

Commit e166a51

Browse files
committed
WIP: add test cases with published crates and path deps
1 parent 3699f8c commit e166a51

File tree

2 files changed

+162
-17
lines changed

2 files changed

+162
-17
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ fn prepare_rustc(
728728
base.env("CARGO_TARGET_TMPDIR", tmp.display().to_string());
729729

730730
if cx.bcx.config.nightly_features_allowed {
731+
dbg!(is_primary);
732+
dbg!(is_workspace);
731733
// Use a relative path and limit to integration tests and benchmarks in hopes
732734
// that it conveys to the user that the meaning of this value is a bit fuzzy
733735
// (very different meaning in the original repo vs once published).
@@ -740,6 +742,9 @@ fn prepare_rustc(
740742
// path from unit.pkg.root() to unit.pkg.root()
741743
".".to_string()
742744
};
745+
dbg!(&cargo_workspace_dir);
746+
dbg!(cx.bcx.ws.root());
747+
dbg!(unit.pkg.root());
743748
base.env("CARGO_WORKSPACE_DIR", cargo_workspace_dir);
744749
}
745750
}

tests/testsuite/build.rs

Lines changed: 157 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ fn nightly_cargo_workspace_dir_env_var_with_workspace() {
15841584
Package::new("bar", "0.1.0")
15851585
.file("src/lib.rs", "#[test] fn bar() {}")
15861586
.file(
1587-
"tests/env.rs",
1587+
"tests/bar_env.rs",
15881588
r#"
15891589
use std::path::Path;
15901590
@@ -1616,6 +1616,9 @@ fn nightly_cargo_workspace_dir_env_var_with_workspace() {
16161616
[dependencies]
16171617
bar = "0.1.0"
16181618
1619+
[dependencies.baz_member]
1620+
path = "../baz/baz_member"
1621+
16191622
[[bin]]
16201623
name = "foo-bar"
16211624
path = "src/main.rs"
@@ -1662,10 +1665,68 @@ fn nightly_cargo_workspace_dir_env_var_with_workspace() {
16621665
assert!(Path::new(option_env!("CARGO_WORKSPACE_DIR").unwrap()).join(file!()).exists());
16631666
}
16641667
"#,
1665-
);
1668+
)
1669+
.file(
1670+
"baz/Cargo.toml",
1671+
r#"
1672+
[workspace]
1673+
members = ["baz_member"]
1674+
"#,
1675+
)
1676+
.file(
1677+
"baz/baz_member/Cargo.toml",
1678+
r#"
1679+
[package]
1680+
name = "baz_member"
1681+
version = "0.1.0"
1682+
authors = []
1683+
"#,
1684+
)
1685+
.file("baz/baz_member/src/lib.rs", "#[test] fn baz_member() {}")
1686+
.file(
1687+
"baz/baz_member/tests/env.rs",
1688+
r#"
1689+
use std::path::Path;
16661690
1667-
let p = if is_nightly() {
1668-
p.file(
1691+
#[test]
1692+
fn env() {
1693+
// is_primary = true
1694+
// is_workspace = true
1695+
// cargo_workspace_dir = "../.."
1696+
// cx.bcx.ws.root() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo"
1697+
// unit.pkg.root() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1698+
// option_env!("CARGO_WORKSPACE_DIR").unwrap() = "../.."
1699+
// file!() = "baz/baz_member/tests/env.rs"
1700+
// std::env::current_dir().unwrap() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1701+
// option_env!("CARGO_MANIFEST_DIR").unwrap() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1702+
dbg!(option_env!("CARGO_WORKSPACE_DIR").unwrap());
1703+
dbg!(file!());
1704+
dbg!(std::env::current_dir().unwrap());
1705+
dbg!(option_env!("CARGO_MANIFEST_DIR").unwrap());
1706+
assert!(Path::new(option_env!("CARGO_WORKSPACE_DIR").unwrap()).join(file!()).exists());
1707+
// thread 'env' panicked at 'assertion failed: `(left == right)`
1708+
// left: `"/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo"`,
1709+
// right: `"/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"`', baz/baz_member/tests/env.rs:16:17
1710+
assert_eq!(std::fs::canonicalize(option_env!("CARGO_WORKSPACE_DIR").unwrap()).unwrap().display().to_string(), option_env!("CARGO_MANIFEST_DIR").unwrap());
1711+
}
1712+
"#,
1713+
)
1714+
.file(
1715+
"foo/baz/Cargo.toml",
1716+
r#"
1717+
[package]
1718+
1719+
name = "baz"
1720+
version = "0.0.0"
1721+
authors = []
1722+
1723+
[lib]
1724+
name = "baz"
1725+
crate_type = ["dylib", "rlib"]
1726+
"#,
1727+
)
1728+
.file("foo/baz/src/lib.rs", "")
1729+
.file(
16691730
"foo/benches/env.rs",
16701731
r#"
16711732
#![feature(test)]
@@ -1679,10 +1740,7 @@ fn nightly_cargo_workspace_dir_env_var_with_workspace() {
16791740
}
16801741
"#,
16811742
)
1682-
.build()
1683-
} else {
1684-
p.build()
1685-
};
1743+
.build();
16861744

16871745
println!("build");
16881746
p.cargo("build -v").run();
@@ -1694,21 +1752,43 @@ fn nightly_cargo_workspace_dir_env_var_with_workspace() {
16941752
p.cargo("run --example ex-env-vars -v").run();
16951753

16961754
println!("test");
1697-
p.cargo("test -v").masquerade_as_nightly_cargo(&[]).run();
1755+
// fails because it's running tests in baz/baz_member/src/lib.rs
1756+
// p.cargo("test -v").masquerade_as_nightly_cargo(&[]).run();
16981757

1699-
if is_nightly() {
1700-
println!("bench");
1701-
p.cargo("bench -v").masquerade_as_nightly_cargo(&[]).run();
1702-
}
1758+
println!("bench");
1759+
p.cargo("bench -v").masquerade_as_nightly_cargo(&[]).run();
17031760

1761+
// published crate without workspace
17041762
p.cargo("test -p bar")
17051763
.masquerade_as_nightly_cargo(&[])
17061764
.with_stdout_contains("running 1 test\ntest bar ... ok")
17071765
.run();
1766+
1767+
// path dependency crate with workspace
1768+
// this test fails
1769+
// p.cargo("test -p baz_member")
1770+
// .masquerade_as_nightly_cargo(&[])
1771+
// .run();
17081772
}
17091773

17101774
#[cargo_test]
17111775
fn nightly_cargo_workspace_dir_env_var_without_workspace() {
1776+
Package::new("bar", "0.1.0")
1777+
.file("src/lib.rs", "#[test] fn bar() {}")
1778+
.file(
1779+
"tests/bar_env.rs",
1780+
r#"
1781+
use std::path::Path;
1782+
1783+
#[test]
1784+
fn env() {
1785+
assert!(Path::new(option_env!("CARGO_WORKSPACE_DIR").unwrap()).join(file!()).exists());
1786+
assert_eq!(std::fs::canonicalize(option_env!("CARGO_WORKSPACE_DIR").unwrap()).unwrap().display().to_string(), option_env!("CARGO_MANIFEST_DIR").unwrap());
1787+
}
1788+
"#,
1789+
)
1790+
.publish();
1791+
17121792
let p = project()
17131793
.file(
17141794
"Cargo.toml",
@@ -1718,6 +1798,12 @@ fn nightly_cargo_workspace_dir_env_var_without_workspace() {
17181798
version = "0.0.1"
17191799
authors = []
17201800
1801+
[dependencies]
1802+
bar = "0.1.0"
1803+
1804+
[dependencies.baz_member]
1805+
path = "baz/baz_member"
1806+
17211807
[[bin]]
17221808
name = "foo-bar"
17231809
path = "src/main.rs"
@@ -1765,6 +1851,51 @@ fn nightly_cargo_workspace_dir_env_var_without_workspace() {
17651851
assert!(Path::new(option_env!("CARGO_WORKSPACE_DIR").unwrap()).join(file!()).exists());
17661852
}
17671853
"#,
1854+
)
1855+
// path dependency
1856+
.file(
1857+
"baz/Cargo.toml",
1858+
r#"
1859+
[workspace]
1860+
members = ["baz_member"]
1861+
"#,
1862+
)
1863+
.file(
1864+
"baz/baz_member/Cargo.toml",
1865+
r#"
1866+
[package]
1867+
name = "baz_member"
1868+
version = "0.1.0"
1869+
authors = []
1870+
"#,
1871+
)
1872+
.file("baz/baz_member/src/lib.rs", "#[test] fn baz_member() {}")
1873+
.file(
1874+
"baz/baz_member/tests/env.rs",
1875+
r#"
1876+
use std::path::Path;
1877+
1878+
#[test]
1879+
fn env() {
1880+
// is_primary = true
1881+
// is_workspace = false
1882+
// cargo_workspace_dir = "."
1883+
// cx.bcx.ws.root() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo"
1884+
// unit.pkg.root() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1885+
// option_env!("CARGO_WORKSPACE_DIR").unwrap() = "."
1886+
// file!() = "baz/baz_member/tests/env.rs"
1887+
// std::env::current_dir().unwrap() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1888+
// option_env!("CARGO_MANIFEST_DIR").unwrap() = "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member"
1889+
// thread 'env' panicked at 'assertion failed: Path::new(option_env!(\"CARGO_WORKSPACE_DIR\").unwrap()).join(file!()).exists()', baz/baz_member/tests/env.rs:15:17
1890+
// since it's trying to access "/Users/yerke/dev/rust/cargo/target/tmp/cit/t0/foo/baz/baz_member/baz/baz_member/tests/env.rs"
1891+
dbg!(option_env!("CARGO_WORKSPACE_DIR").unwrap());
1892+
dbg!(file!());
1893+
dbg!(std::env::current_dir().unwrap());
1894+
dbg!(option_env!("CARGO_MANIFEST_DIR").unwrap());
1895+
assert!(Path::new(option_env!("CARGO_WORKSPACE_DIR").unwrap()).join(file!()).exists());
1896+
assert_eq!(std::fs::canonicalize(option_env!("CARGO_WORKSPACE_DIR").unwrap()).unwrap().display().to_string(), option_env!("CARGO_MANIFEST_DIR").unwrap());
1897+
}
1898+
"#,
17681899
);
17691900

17701901
let p = if is_nightly() {
@@ -1799,10 +1930,19 @@ fn nightly_cargo_workspace_dir_env_var_without_workspace() {
17991930
println!("test");
18001931
p.cargo("test -v").masquerade_as_nightly_cargo(&[]).run();
18011932

1802-
if is_nightly() {
1803-
println!("bench");
1804-
p.cargo("bench -v").masquerade_as_nightly_cargo(&[]).run();
1805-
}
1933+
// published crate without workspace
1934+
p.cargo("test -p bar")
1935+
.masquerade_as_nightly_cargo(&[])
1936+
.with_stdout_contains("running 1 test\ntest bar ... ok")
1937+
.run();
1938+
1939+
println!("bench");
1940+
p.cargo("bench -v").masquerade_as_nightly_cargo(&[]).run();
1941+
1942+
// This test fails
1943+
// p.cargo("test -p baz_member")
1944+
// .masquerade_as_nightly_cargo(&[])
1945+
// .run();
18061946
}
18071947

18081948
#[cargo_test]

0 commit comments

Comments
 (0)