Skip to content

Commit dc5d023

Browse files
committed
Add tests for namespaced features
1 parent cb533ae commit dc5d023

File tree

1 file changed

+259
-0
lines changed

1 file changed

+259
-0
lines changed

tests/testsuite/features.rs

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,3 +1714,262 @@ fn combining_features_and_package() {
17141714
execs().with_status(0),
17151715
);
17161716
}
1717+
1718+
#[test]
1719+
fn namespaced_invalid_feature() {
1720+
let p = project("foo")
1721+
.file(
1722+
"Cargo.toml",
1723+
r#"
1724+
[project]
1725+
name = "foo"
1726+
version = "0.0.1"
1727+
authors = []
1728+
namespaced-features = true
1729+
1730+
[features]
1731+
bar = ["baz"]
1732+
"#,
1733+
)
1734+
.file("src/main.rs", "")
1735+
.build();
1736+
1737+
assert_that(
1738+
p.cargo("build"),
1739+
execs().with_status(101).with_stderr(
1740+
"\
1741+
[ERROR] failed to parse manifest at `[..]`
1742+
1743+
Caused by:
1744+
Feature `bar` includes `baz` which is not defined as a feature
1745+
",
1746+
),
1747+
);
1748+
}
1749+
1750+
#[test]
1751+
fn namespaced_invalid_dependency() {
1752+
let p = project("foo")
1753+
.file(
1754+
"Cargo.toml",
1755+
r#"
1756+
[project]
1757+
name = "foo"
1758+
version = "0.0.1"
1759+
authors = []
1760+
namespaced-features = true
1761+
1762+
[features]
1763+
bar = ["crate:baz"]
1764+
"#,
1765+
)
1766+
.file("src/main.rs", "")
1767+
.build();
1768+
1769+
assert_that(
1770+
p.cargo("build"),
1771+
execs().with_status(101).with_stderr(
1772+
"\
1773+
[ERROR] failed to parse manifest at `[..]`
1774+
1775+
Caused by:
1776+
Feature `bar` includes `crate:baz` which is not a known dependency
1777+
",
1778+
),
1779+
);
1780+
}
1781+
1782+
#[test]
1783+
fn namespaced_non_optional_dependency() {
1784+
let p = project("foo")
1785+
.file(
1786+
"Cargo.toml",
1787+
r#"
1788+
[project]
1789+
name = "foo"
1790+
version = "0.0.1"
1791+
authors = []
1792+
namespaced-features = true
1793+
1794+
[features]
1795+
bar = ["crate:baz"]
1796+
1797+
[dependencies]
1798+
baz = "0.1"
1799+
"#,
1800+
)
1801+
.file("src/main.rs", "")
1802+
.build();
1803+
1804+
assert_that(
1805+
p.cargo("build"),
1806+
execs().with_status(101).with_stderr(
1807+
"\
1808+
[ERROR] failed to parse manifest at `[..]`
1809+
1810+
Caused by:
1811+
Feature `bar` includes `crate:baz` which is not an optional dependency.
1812+
Consider adding `optional = true` to the dependency
1813+
",
1814+
),
1815+
);
1816+
}
1817+
1818+
#[test]
1819+
fn namespaced_implicit_feature() {
1820+
let p = project("foo")
1821+
.file(
1822+
"Cargo.toml",
1823+
r#"
1824+
[project]
1825+
name = "foo"
1826+
version = "0.0.1"
1827+
authors = []
1828+
namespaced-features = true
1829+
1830+
[features]
1831+
bar = ["baz"]
1832+
1833+
[dependencies]
1834+
baz = { version = "0.1", optional = true }
1835+
"#,
1836+
)
1837+
.file("src/main.rs", "fn main() {}")
1838+
.build();
1839+
1840+
assert_that(p.cargo("build"), execs().with_status(0));
1841+
}
1842+
1843+
#[test]
1844+
fn namespaced_shadowed_dep() {
1845+
let p = project("foo")
1846+
.file(
1847+
"Cargo.toml",
1848+
r#"
1849+
[project]
1850+
name = "foo"
1851+
version = "0.0.1"
1852+
authors = []
1853+
namespaced-features = true
1854+
1855+
[features]
1856+
baz = []
1857+
1858+
[dependencies]
1859+
baz = { version = "0.1", optional = true }
1860+
"#,
1861+
)
1862+
.file("src/main.rs", "fn main() {}")
1863+
.build();
1864+
1865+
assert_that(
1866+
p.cargo("build"),
1867+
execs().with_status(101).with_stderr(
1868+
"\
1869+
[ERROR] failed to parse manifest at `[..]`
1870+
1871+
Caused by:
1872+
Feature `baz` includes the optional dependency of the same name, but this is left implicit in the features included by this feature.
1873+
Consider adding `crate:baz` to this feature's requirements.
1874+
",
1875+
),
1876+
);
1877+
}
1878+
1879+
#[test]
1880+
fn namespaced_shadowed_non_optional() {
1881+
let p = project("foo")
1882+
.file(
1883+
"Cargo.toml",
1884+
r#"
1885+
[project]
1886+
name = "foo"
1887+
version = "0.0.1"
1888+
authors = []
1889+
namespaced-features = true
1890+
1891+
[features]
1892+
baz = []
1893+
1894+
[dependencies]
1895+
baz = "0.1"
1896+
"#,
1897+
)
1898+
.file("src/main.rs", "fn main() {}")
1899+
.build();
1900+
1901+
assert_that(
1902+
p.cargo("build"),
1903+
execs().with_status(101).with_stderr(
1904+
"\
1905+
[ERROR] failed to parse manifest at `[..]`
1906+
1907+
Caused by:
1908+
Feature `baz` includes the dependency of the same name, but this is left implicit in the features included by this feature.
1909+
Additionally, the dependency must be marked as optional to be included in the feature definition.
1910+
Consider adding `crate:baz` to this feature's requirements and marking the dependency as `optional = true`
1911+
",
1912+
),
1913+
);
1914+
}
1915+
1916+
#[test]
1917+
fn namespaced_implicit_non_optional() {
1918+
let p = project("foo")
1919+
.file(
1920+
"Cargo.toml",
1921+
r#"
1922+
[project]
1923+
name = "foo"
1924+
version = "0.0.1"
1925+
authors = []
1926+
namespaced-features = true
1927+
1928+
[features]
1929+
bar = ["baz"]
1930+
1931+
[dependencies]
1932+
baz = "0.1"
1933+
"#,
1934+
)
1935+
.file("src/main.rs", "fn main() {}")
1936+
.build();
1937+
1938+
assert_that(
1939+
p.cargo("build"),
1940+
execs().with_status(101).with_stderr(
1941+
"\
1942+
[ERROR] failed to parse manifest at `[..]`
1943+
1944+
Caused by:
1945+
Feature `bar` includes `baz` which is not defined as a feature.
1946+
A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition
1947+
",
1948+
),
1949+
);
1950+
}
1951+
1952+
#[test]
1953+
fn namespaced_same_name() {
1954+
let p = project("foo")
1955+
.file(
1956+
"Cargo.toml",
1957+
r#"
1958+
[project]
1959+
name = "foo"
1960+
version = "0.0.1"
1961+
authors = []
1962+
namespaced-features = true
1963+
1964+
[features]
1965+
baz = ["crate:baz"]
1966+
1967+
[dependencies]
1968+
baz = { version = "0.1", optional = true }
1969+
"#,
1970+
)
1971+
.file("src/main.rs", "fn main() {}")
1972+
.build();
1973+
1974+
assert_that(p.cargo("build"), execs().with_status(0));
1975+
}

0 commit comments

Comments
 (0)