Skip to content

Commit 9a7a8cf

Browse files
committed
Add tests in preparation of boolean literal support in cfgs
1 parent 4fc4e12 commit 9a7a8cf

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed

tests/testsuite/cfg.rs

+235
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,238 @@ fn cfg_keywords() {
659659
"#]])
660660
.run();
661661
}
662+
663+
#[cargo_test]
664+
fn cfg_booleans() {
665+
let p = project()
666+
.file(
667+
"Cargo.toml",
668+
r#"
669+
[package]
670+
name = "a"
671+
version = "0.0.1"
672+
edition = "2015"
673+
authors = []
674+
675+
[target.'cfg(true)'.dependencies]
676+
b = { path = 'b' }
677+
678+
[target.'cfg(false)'.dependencies]
679+
c = { path = 'c' }
680+
"#,
681+
)
682+
.file("src/lib.rs", "")
683+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
684+
.file("b/src/lib.rs", "")
685+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
686+
.file("c/src/lib.rs", "")
687+
.build();
688+
689+
p.cargo("check")
690+
// FIXME: `b` should be compiled
691+
.with_stderr_data(str![[r#"
692+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(false)` will change in the future
693+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
694+
| In the future these will be built-in defines that will have the corresponding true/false value.
695+
| It is recommended to avoid using these configs until they are properly supported.
696+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
697+
|
698+
| [HELP] use raw-idents instead: `cfg(r#false)`
699+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(true)` will change in the future
700+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
701+
| In the future these will be built-in defines that will have the corresponding true/false value.
702+
| It is recommended to avoid using these configs until they are properly supported.
703+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
704+
|
705+
| [HELP] use raw-idents instead: `cfg(r#true)`
706+
[LOCKING] 2 packages to latest compatible versions
707+
[CHECKING] a v0.0.1 ([ROOT]/foo)
708+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
709+
710+
"#]])
711+
.run();
712+
}
713+
714+
#[cargo_test]
715+
fn cfg_booleans_config() {
716+
let p = project()
717+
.file(
718+
"Cargo.toml",
719+
r#"
720+
[package]
721+
name = "a"
722+
version = "0.0.1"
723+
edition = "2015"
724+
"#,
725+
)
726+
.file("src/lib.rs", "")
727+
.file(
728+
".cargo/config.toml",
729+
r#"
730+
[target.'cfg(true)']
731+
rustflags = []
732+
"#,
733+
)
734+
.build();
735+
736+
p.cargo("check")
737+
.with_stderr_data(str![[r#"
738+
[WARNING] [.cargo/config.toml] future-incompatibility: the meaning of `cfg(true)` will change in the future
739+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
740+
| In the future these will be built-in defines that will have the corresponding true/false value.
741+
| It is recommended to avoid using these configs until they are properly supported.
742+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
743+
|
744+
| [HELP] use raw-idents instead: `cfg(r#true)`
745+
[CHECKING] a v0.0.1 ([ROOT]/foo)
746+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
747+
748+
"#]])
749+
.run();
750+
}
751+
752+
#[cargo_test]
753+
fn cfg_booleans_not() {
754+
let p = project()
755+
.file(
756+
"Cargo.toml",
757+
r#"
758+
[package]
759+
name = "a"
760+
version = "0.0.1"
761+
edition = "2015"
762+
authors = []
763+
764+
[target.'cfg(not(false))'.dependencies]
765+
b = { path = 'b' }
766+
"#,
767+
)
768+
.file("src/lib.rs", "")
769+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
770+
.file("b/src/lib.rs", "")
771+
.build();
772+
773+
p.cargo("check")
774+
.with_stderr_data(str![[r#"
775+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(false)` will change in the future
776+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
777+
| In the future these will be built-in defines that will have the corresponding true/false value.
778+
| It is recommended to avoid using these configs until they are properly supported.
779+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
780+
|
781+
| [HELP] use raw-idents instead: `cfg(r#false)`
782+
[LOCKING] 1 package to latest compatible version
783+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
784+
[CHECKING] a v0.0.1 ([ROOT]/foo)
785+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
786+
787+
"#]])
788+
.run();
789+
}
790+
791+
#[cargo_test]
792+
fn cfg_booleans_combinators() {
793+
let p = project()
794+
.file(
795+
"Cargo.toml",
796+
r#"
797+
[package]
798+
name = "a"
799+
version = "0.0.1"
800+
edition = "2015"
801+
authors = []
802+
803+
[target.'cfg(all(any(true), not(false), true))'.dependencies]
804+
b = { path = 'b' }
805+
"#,
806+
)
807+
.file("src/lib.rs", "")
808+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
809+
.file("b/src/lib.rs", "")
810+
.build();
811+
812+
p.cargo("check")
813+
// FIXME: `b` should be compiled
814+
.with_stderr_data(str![[r#"
815+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(true)` will change in the future
816+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
817+
| In the future these will be built-in defines that will have the corresponding true/false value.
818+
| It is recommended to avoid using these configs until they are properly supported.
819+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
820+
|
821+
| [HELP] use raw-idents instead: `cfg(r#true)`
822+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(false)` will change in the future
823+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
824+
| In the future these will be built-in defines that will have the corresponding true/false value.
825+
| It is recommended to avoid using these configs until they are properly supported.
826+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
827+
|
828+
| [HELP] use raw-idents instead: `cfg(r#false)`
829+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(true)` will change in the future
830+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
831+
| In the future these will be built-in defines that will have the corresponding true/false value.
832+
| It is recommended to avoid using these configs until they are properly supported.
833+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
834+
|
835+
| [HELP] use raw-idents instead: `cfg(r#true)`
836+
[LOCKING] 1 package to latest compatible version
837+
[CHECKING] a v0.0.1 ([ROOT]/foo)
838+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
839+
840+
"#]])
841+
.run();
842+
}
843+
844+
#[cargo_test]
845+
fn cfg_booleans_rustflags_no_effect() {
846+
let p = project()
847+
.file(
848+
"Cargo.toml",
849+
r#"
850+
[package]
851+
name = "a"
852+
version = "0.0.1"
853+
edition = "2015"
854+
authors = []
855+
856+
[target.'cfg(true)'.dependencies]
857+
b = { path = 'b' }
858+
859+
[target.'cfg(false)'.dependencies]
860+
c = { path = 'c' }
861+
"#,
862+
)
863+
.file("src/lib.rs", "")
864+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
865+
.file("b/src/lib.rs", "")
866+
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
867+
.file("c/src/lib.rs", "")
868+
.build();
869+
870+
p.cargo("check")
871+
// FIXME: only `b` should be compiled, the rustflags don't take effect
872+
.env("RUSTFLAGS", "--cfg false")
873+
.with_stderr_data(str![[r#"
874+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(false)` will change in the future
875+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
876+
| In the future these will be built-in defines that will have the corresponding true/false value.
877+
| It is recommended to avoid using these configs until they are properly supported.
878+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
879+
|
880+
| [HELP] use raw-idents instead: `cfg(r#false)`
881+
[WARNING] [[ROOT]/foo/Cargo.toml] future-incompatibility: the meaning of `cfg(true)` will change in the future
882+
| Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.
883+
| In the future these will be built-in defines that will have the corresponding true/false value.
884+
| It is recommended to avoid using these configs until they are properly supported.
885+
| See <https://github.com/rust-lang/rust/issues/131204> for more information.
886+
|
887+
| [HELP] use raw-idents instead: `cfg(r#true)`
888+
[LOCKING] 2 packages to latest compatible versions
889+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
890+
[CHECKING] c v0.0.1 ([ROOT]/foo/c)
891+
[CHECKING] a v0.0.1 ([ROOT]/foo)
892+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
893+
894+
"#]])
895+
.run();
896+
}

0 commit comments

Comments
 (0)