Skip to content

Commit 20bbe3b

Browse files
committed
Add tests in preparation of boolean literal support in cfgs
1 parent c552ec3 commit 20bbe3b

File tree

1 file changed

+241
-0
lines changed

1 file changed

+241
-0
lines changed

tests/testsuite/cfg.rs

+241
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,244 @@ error[E0463]: can't find crate for `bar`
521521
"#]])
522522
.run();
523523
}
524+
525+
#[cargo_test]
526+
fn cfg_booleans_gate() {
527+
let p = project()
528+
.file(
529+
"Cargo.toml",
530+
r#"
531+
[package]
532+
name = "a"
533+
version = "0.0.1"
534+
edition = "2015"
535+
authors = []
536+
537+
[target.'cfg(true)'.dependencies]
538+
b = { path = 'b' }
539+
540+
[target.'cfg(false)'.dependencies]
541+
c = { path = 'c' }
542+
"#,
543+
)
544+
.file("src/lib.rs", "")
545+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
546+
.file("b/src/lib.rs", "")
547+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
548+
.file("c/src/lib.rs", "")
549+
.build();
550+
551+
p.cargo("check")
552+
// FIXME: true/false should error out as they are gated
553+
.with_stderr_data(str![[r#"
554+
[LOCKING] 2 packages to latest compatible versions
555+
[CHECKING] a v0.0.1 ([ROOT]/foo)
556+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
557+
558+
"#]])
559+
.run();
560+
}
561+
562+
#[cargo_test]
563+
fn cfg_booleans_gate_config() {
564+
let p = project()
565+
.file(
566+
"Cargo.toml",
567+
r#"
568+
[package]
569+
name = "a"
570+
version = "0.0.1"
571+
edition = "2015"
572+
"#,
573+
)
574+
.file("src/lib.rs", "")
575+
.file(
576+
".cargo/config.toml",
577+
r#"
578+
[target.'cfg(true)']
579+
rustflags = []
580+
"#,
581+
)
582+
.build();
583+
584+
p.cargo("check")
585+
// FIXME: true/false should error out as they are gated
586+
.with_stderr_data(str![[r#"
587+
[CHECKING] a v0.0.1 ([ROOT]/foo)
588+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
589+
590+
"#]])
591+
.run();
592+
}
593+
594+
#[cargo_test]
595+
fn cfg_booleans() {
596+
let p = project()
597+
.file(
598+
"Cargo.toml",
599+
r#"
600+
[package]
601+
name = "a"
602+
version = "0.0.1"
603+
edition = "2015"
604+
authors = []
605+
606+
[target.'cfg(true)'.dependencies]
607+
b = { path = 'b' }
608+
609+
[target.'cfg(false)'.dependencies]
610+
c = { path = 'c' }
611+
"#,
612+
)
613+
.file("src/lib.rs", "")
614+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
615+
.file("b/src/lib.rs", "")
616+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
617+
.file("c/src/lib.rs", "")
618+
.build();
619+
620+
p.cargo("check")
621+
// FIXME: `b` should be compiled
622+
.with_stderr_data(str![[r#"
623+
[LOCKING] 2 packages to latest compatible versions
624+
[CHECKING] a v0.0.1 ([ROOT]/foo)
625+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
626+
627+
"#]])
628+
.run();
629+
}
630+
631+
#[cargo_test]
632+
fn cfg_booleans_config() {
633+
let p = project()
634+
.file(
635+
"Cargo.toml",
636+
r#"
637+
[package]
638+
name = "a"
639+
version = "0.0.1"
640+
edition = "2015"
641+
"#,
642+
)
643+
.file("src/lib.rs", "")
644+
.file(
645+
".cargo/config.toml",
646+
r#"
647+
[target.'cfg(true)']
648+
rustflags = []
649+
"#,
650+
)
651+
.build();
652+
653+
p.cargo("check")
654+
.with_stderr_data(str![[r#"
655+
[CHECKING] a v0.0.1 ([ROOT]/foo)
656+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
657+
658+
"#]])
659+
.run();
660+
}
661+
662+
#[cargo_test]
663+
fn cfg_booleans_not() {
664+
let p = project()
665+
.file(
666+
"Cargo.toml",
667+
r#"
668+
[package]
669+
name = "a"
670+
version = "0.0.1"
671+
edition = "2015"
672+
authors = []
673+
674+
[target.'cfg(not(false))'.dependencies]
675+
b = { path = 'b' }
676+
"#,
677+
)
678+
.file("src/lib.rs", "")
679+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
680+
.file("b/src/lib.rs", "")
681+
.build();
682+
683+
p.cargo("check")
684+
.with_stderr_data(str![[r#"
685+
[LOCKING] 1 package to latest compatible version
686+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
687+
[CHECKING] a v0.0.1 ([ROOT]/foo)
688+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
689+
690+
"#]])
691+
.run();
692+
}
693+
694+
#[cargo_test]
695+
fn cfg_booleans_combinators() {
696+
let p = project()
697+
.file(
698+
"Cargo.toml",
699+
r#"
700+
[package]
701+
name = "a"
702+
version = "0.0.1"
703+
edition = "2015"
704+
authors = []
705+
706+
[target.'cfg(all(any(true), not(false), true))'.dependencies]
707+
b = { path = 'b' }
708+
"#,
709+
)
710+
.file("src/lib.rs", "")
711+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
712+
.file("b/src/lib.rs", "")
713+
.build();
714+
715+
p.cargo("check")
716+
// FIXME: `b` should be compiled
717+
.with_stderr_data(str![[r#"
718+
[LOCKING] 1 package to latest compatible version
719+
[CHECKING] a v0.0.1 ([ROOT]/foo)
720+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
721+
722+
"#]])
723+
.run();
724+
}
725+
726+
#[cargo_test]
727+
fn cfg_booleans_rustflags_no_effect() {
728+
let p = project()
729+
.file(
730+
"Cargo.toml",
731+
r#"
732+
[package]
733+
name = "a"
734+
version = "0.0.1"
735+
edition = "2015"
736+
authors = []
737+
738+
[target.'cfg(true)'.dependencies]
739+
b = { path = 'b' }
740+
741+
[target.'cfg(false)'.dependencies]
742+
c = { path = 'c' }
743+
"#,
744+
)
745+
.file("src/lib.rs", "")
746+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
747+
.file("b/src/lib.rs", "")
748+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
749+
.file("c/src/lib.rs", "")
750+
.build();
751+
752+
p.cargo("check")
753+
// FIXME: only `b` should be compiled, the rustflags don't take effect
754+
.with_stderr_data(str![[r#"
755+
[LOCKING] 2 packages to latest compatible versions
756+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
757+
[CHECKING] c v0.0.1 ([ROOT]/foo/c)
758+
[CHECKING] a v0.0.1 ([ROOT]/foo)
759+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
760+
761+
"#]])
762+
.env("RUSTFLAGS", "--cfg true --cfg false")
763+
.run();
764+
}

0 commit comments

Comments
 (0)