Skip to content

Commit e5a3134

Browse files
committed
fixup tests
1 parent 1f7d2c7 commit e5a3134

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

tests/testsuite/feature_unification.rs

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,180 @@ fn package_feature_unification() {
253253
.with_stderr_data(str![[r#"
254254
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
255255
256+
"#]])
257+
.run();
258+
// Sanity check that compilation without package feature unification does not work
259+
p.cargo("check -p a -p b")
260+
.arg("-Zfeature-unification")
261+
.masquerade_as_nightly_cargo(&["feature-unification"])
262+
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "selected")
263+
.with_status(101)
264+
.with_stderr_contains("[ERROR] features were unified")
265+
.run();
266+
}
267+
268+
#[cargo_test]
269+
fn feature_unification_cargo_tree() {
270+
Package::new("outside", "0.1.0")
271+
.feature("a", &[])
272+
.feature("b", &[])
273+
.file(
274+
"src/lib.rs",
275+
r#"
276+
#[cfg(all(feature = "a", feature = "b"))]
277+
compile_error!("features were unified");
278+
#[cfg(feature = "a")]
279+
pub fn a() {}
280+
#[cfg(feature = "b")]
281+
pub fn b() {}
282+
"#,
283+
)
284+
.publish();
285+
286+
let p = project()
287+
.file(
288+
"Cargo.toml",
289+
r#"
290+
[workspace]
291+
resolver = "2"
292+
members = ["common", "a", "b"]
293+
"#,
294+
)
295+
.file(
296+
"common/Cargo.toml",
297+
r#"
298+
[package]
299+
name = "common"
300+
version = "0.1.0"
301+
edition = "2021"
302+
303+
[features]
304+
a = []
305+
b = []
306+
"#,
307+
)
308+
.file(
309+
"common/src/lib.rs",
310+
r#"
311+
#[cfg(all(feature = "a", feature = "b"))]
312+
compile_error!("features were unified");
313+
#[cfg(feature = "a")]
314+
pub fn a() {}
315+
#[cfg(feature = "b")]
316+
pub fn b() {}
317+
"#,
318+
)
319+
.file(
320+
"a/Cargo.toml",
321+
r#"
322+
[package]
323+
name = "a"
324+
version = "0.1.0"
325+
edition = "2021"
326+
327+
[dependencies]
328+
common = { path = "../common", features = ["a"] }
329+
outside = { version = "0.1.0", features = ["a"] }
330+
"#,
331+
)
332+
.file("a/src/lib.rs", "pub use common::a;")
333+
.file(
334+
"b/Cargo.toml",
335+
r#"
336+
[package]
337+
name = "b"
338+
version = "0.1.0"
339+
edition = "2021"
340+
341+
[dependencies]
342+
common = { path = "../common", features = ["b"] }
343+
outside = { version = "0.1.0", features = ["b"] }
344+
"#,
345+
)
346+
.file("b/src/lib.rs", "pub use common::b;")
347+
.build();
348+
349+
p.cargo("tree -e features")
350+
.arg("-Zfeature-unification")
351+
.masquerade_as_nightly_cargo(&["feature-unification"])
352+
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "selected")
353+
.with_stdout_data(str![[r#"
354+
common v0.1.0 ([ROOT]/foo/common)
355+
a v0.1.0 ([ROOT]/foo/a)
356+
├── common feature "a"
357+
│ └── common v0.1.0 ([ROOT]/foo/common)
358+
├── common feature "default"
359+
│ └── common v0.1.0 ([ROOT]/foo/common)
360+
├── outside feature "a"
361+
│ └── outside v0.1.0
362+
└── outside feature "default"
363+
└── outside v0.1.0
364+
b v0.1.0 ([ROOT]/foo/b)
365+
├── common feature "b"
366+
│ └── common v0.1.0 ([ROOT]/foo/common)
367+
├── common feature "default"
368+
│ └── common v0.1.0 ([ROOT]/foo/common)
369+
├── outside feature "b"
370+
│ └── outside v0.1.0
371+
└── outside feature "default"
372+
└── outside v0.1.0 ([ROOT]/foo/common)
373+
374+
"#]])
375+
.run();
376+
377+
p.cargo("tree -e features")
378+
.arg("-Zfeature-unification")
379+
.masquerade_as_nightly_cargo(&["feature-unification"])
380+
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "package")
381+
.with_stdout_data(str![[r#"
382+
common v0.1.0 ([ROOT]/foo/common)
383+
a v0.1.0 ([ROOT]/foo/a)
384+
├── common feature "a"
385+
│ └── common v0.1.0 ([ROOT]/foo/common)
386+
├── common feature "default"
387+
│ └── common v0.1.0 ([ROOT]/foo/common)
388+
├── outside feature "a"
389+
│ └── outside v0.1.0
390+
└── outside feature "default"
391+
└── outside v0.1.0
392+
b v0.1.0 ([ROOT]/foo/b)
393+
├── common feature "b"
394+
│ └── common v0.1.0 ([ROOT]/foo/common)
395+
├── common feature "default"
396+
│ └── common v0.1.0 ([ROOT]/foo/common)
397+
├── outside feature "b"
398+
│ └── outside v0.1.0
399+
└── outside feature "default"
400+
└── outside v0.1.0
401+
402+
"#]])
403+
.run();
404+
405+
p.cargo("tree -e features")
406+
.arg("-Zfeature-unification")
407+
.masquerade_as_nightly_cargo(&["feature-unification"])
408+
.env("CARGO_RESOLVER_FEATURE_UNIFICATION", "workspace")
409+
.with_stdout_data(str![[r#"
410+
a v0.1.0 ([ROOT]/foo/a)
411+
├── common feature "a"
412+
│ └── common v0.1.0 ([ROOT]/foo/common)
413+
├── common feature "default" (command-line)
414+
│ └── common v0.1.0 ([ROOT]/foo/common)
415+
├── outside feature "a"
416+
│ └── outside v0.1.0
417+
└── outside feature "default"
418+
└── outside v0.1.0
419+
420+
b v0.1.0 ([ROOT]/foo/b)
421+
├── common feature "b"
422+
│ └── common v0.1.0 ([ROOT]/foo/common)
423+
├── common feature "default" (command-line) (*)
424+
├── outside feature "b"
425+
│ └── outside v0.1.0
426+
└── outside feature "default" (*)
427+
428+
common v0.1.0 ([ROOT]/foo/common)
429+
256430
"#]])
257431
.run();
258432
}

0 commit comments

Comments
 (0)