diff options
Diffstat (limited to 'third_party/rust/rustversion/tests')
14 files changed, 250 insertions, 0 deletions
diff --git a/third_party/rust/rustversion/tests/compiletest.rs b/third_party/rust/rustversion/tests/compiletest.rs new file mode 100644 index 0000000000..7974a6249e --- /dev/null +++ b/third_party/rust/rustversion/tests/compiletest.rs @@ -0,0 +1,7 @@ +#[rustversion::attr(not(nightly), ignore)] +#[cfg_attr(miri, ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/third_party/rust/rustversion/tests/test_const.rs b/third_party/rust/rustversion/tests/test_const.rs new file mode 100644 index 0000000000..3c4f7d5b69 --- /dev/null +++ b/third_party/rust/rustversion/tests/test_const.rs @@ -0,0 +1,39 @@ +#![allow(clippy::semicolon_if_nothing_returned)] // https://github.com/rust-lang/rust-clippy/issues/7324 + +#[rustversion::attr(all(), const)] +fn _basic() {} +const _BASIC: () = _basic(); + +#[rustversion::attr(all(), const)] +unsafe fn _unsafe() {} +const _UNSAFE: () = unsafe { _unsafe() }; + +macro_rules! item { + ($i:item) => { + #[rustversion::attr(all(), const)] + $i + }; +} + +item! {fn _item() {}} +const _ITEM: () = _item(); + +macro_rules! ident { + ($fn:ident) => { + #[rustversion::attr(all(), const)] + $fn _ident() {} + }; +} + +ident! {fn} +const _IDENT: () = _ident(); + +#[rustversion::attr(all(), const)] +/// doc +fn _doc_below() {} +const _DOC_BELOW: () = _doc_below(); + +/// doc +#[rustversion::attr(all(), const)] +fn _doc_above() {} +const _DOC_ABOVE: () = _doc_above(); diff --git a/third_party/rust/rustversion/tests/test_eval.rs b/third_party/rust/rustversion/tests/test_eval.rs new file mode 100644 index 0000000000..c044e8599f --- /dev/null +++ b/third_party/rust/rustversion/tests/test_eval.rs @@ -0,0 +1,20 @@ +#[rustversion::any( + stable, + stable(1.34), + stable(1.34.0), + beta, + nightly, + nightly(2020-02-25), + since(1.34), + since(2020-02-25), + before(1.34), + before(2020-02-25), + not(nightly), + all(stable, beta, nightly), +)] +fn success() {} + +#[test] +fn test() { + success(); +} diff --git a/third_party/rust/rustversion/tests/test_parse.rs b/third_party/rust/rustversion/tests/test_parse.rs new file mode 100644 index 0000000000..95064eece7 --- /dev/null +++ b/third_party/rust/rustversion/tests/test_parse.rs @@ -0,0 +1,103 @@ +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::enum_glob_use, + clippy::must_use_candidate +)] + +include!("../build/rustc.rs"); + +#[test] +fn test_parse() { + let cases = &[ + ( + "rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)", + Version { + minor: 0, + patch: 0, + channel: Stable, + }, + ), + ( + "rustc 1.18.0", + Version { + minor: 18, + patch: 0, + channel: Stable, + }, + ), + ( + "rustc 1.24.1 (d3ae9a9e0 2018-02-27)", + Version { + minor: 24, + patch: 1, + channel: Stable, + }, + ), + ( + "rustc 1.35.0-beta.3 (c13114dc8 2019-04-27)", + Version { + minor: 35, + patch: 0, + channel: Beta, + }, + ), + ( + "rustc 1.36.0-nightly (938d4ffe1 2019-04-27)", + Version { + minor: 36, + patch: 0, + channel: Nightly(Date { + year: 2019, + month: 4, + day: 27, + }), + }, + ), + ( + "rustc 1.36.0-dev", + Version { + minor: 36, + patch: 0, + channel: Dev, + }, + ), + ( + "rustc 1.36.0-nightly", + Version { + minor: 36, + patch: 0, + channel: Dev, + }, + ), + ( + "warning: invalid logging spec 'warning', ignoring it + rustc 1.30.0-nightly (3bc2ca7e4 2018-09-20)", + Version { + minor: 30, + patch: 0, + channel: Nightly(Date { + year: 2018, + month: 9, + day: 20, + }), + }, + ), + ( + "rustc 1.52.1-nightly (gentoo)", + Version { + minor: 52, + patch: 1, + channel: Dev, + }, + ), + ]; + + for (string, expected) in cases { + match parse(string) { + ParseResult::Success(version) => assert_eq!(version, *expected), + ParseResult::OopsClippy | ParseResult::Unrecognized => { + panic!("unrecognized: {:?}", string); + } + } + } +} diff --git a/third_party/rust/rustversion/tests/ui/bad-bound.rs b/third_party/rust/rustversion/tests/ui/bad-bound.rs new file mode 100644 index 0000000000..add8792eb1 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-bound.rs @@ -0,0 +1,7 @@ +#[rustversion::since(stable)] +struct S; + +#[rustversion::any(since(stable))] +struct S; + +fn main() {} diff --git a/third_party/rust/rustversion/tests/ui/bad-bound.stderr b/third_party/rust/rustversion/tests/ui/bad-bound.stderr new file mode 100644 index 0000000000..77956c66db --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-bound.stderr @@ -0,0 +1,11 @@ +error: expected rustc release number like 1.31, or nightly date like 2020-02-25 + --> tests/ui/bad-bound.rs:1:22 + | +1 | #[rustversion::since(stable)] + | ^^^^^^ + +error: expected rustc release number like 1.31, or nightly date like 2020-02-25 + --> tests/ui/bad-bound.rs:4:26 + | +4 | #[rustversion::any(since(stable))] + | ^^^^^^ diff --git a/third_party/rust/rustversion/tests/ui/bad-date.rs b/third_party/rust/rustversion/tests/ui/bad-date.rs new file mode 100644 index 0000000000..09846254b0 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-date.rs @@ -0,0 +1,7 @@ +#[rustversion::nightly(stable)] +struct S; + +#[rustversion::any(nightly(stable))] +struct S; + +fn main() {} diff --git a/third_party/rust/rustversion/tests/ui/bad-date.stderr b/third_party/rust/rustversion/tests/ui/bad-date.stderr new file mode 100644 index 0000000000..378b00e0da --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-date.stderr @@ -0,0 +1,11 @@ +error: expected nightly date, like 2020-02-25 + --> tests/ui/bad-date.rs:1:24 + | +1 | #[rustversion::nightly(stable)] + | ^^^^^^ + +error: expected nightly date, like 2020-02-25 + --> tests/ui/bad-date.rs:4:28 + | +4 | #[rustversion::any(nightly(stable))] + | ^^^^^^ diff --git a/third_party/rust/rustversion/tests/ui/bad-not.rs b/third_party/rust/rustversion/tests/ui/bad-not.rs new file mode 100644 index 0000000000..058f340f69 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-not.rs @@ -0,0 +1,7 @@ +#[rustversion::any(not)] +struct S; + +#[rustversion::any(not, not)] +struct S; + +fn main() {} diff --git a/third_party/rust/rustversion/tests/ui/bad-not.stderr b/third_party/rust/rustversion/tests/ui/bad-not.stderr new file mode 100644 index 0000000000..2b0c699332 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-not.stderr @@ -0,0 +1,11 @@ +error: expected `(` after `not` + --> tests/ui/bad-not.rs:1:20 + | +1 | #[rustversion::any(not)] + | ^^^ + +error: expected `(` + --> tests/ui/bad-not.rs:4:23 + | +4 | #[rustversion::any(not, not)] + | ^ diff --git a/third_party/rust/rustversion/tests/ui/bad-version.rs b/third_party/rust/rustversion/tests/ui/bad-version.rs new file mode 100644 index 0000000000..1fe8dba166 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-version.rs @@ -0,0 +1,7 @@ +#[rustversion::stable(nightly)] +struct S; + +#[rustversion::any(stable(nightly))] +struct S; + +fn main() {} diff --git a/third_party/rust/rustversion/tests/ui/bad-version.stderr b/third_party/rust/rustversion/tests/ui/bad-version.stderr new file mode 100644 index 0000000000..bf3f144b15 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/bad-version.stderr @@ -0,0 +1,11 @@ +error: expected rustc release number, like 1.31 + --> tests/ui/bad-version.rs:1:23 + | +1 | #[rustversion::stable(nightly)] + | ^^^^^^^ + +error: expected rustc release number, like 1.31 + --> tests/ui/bad-version.rs:4:27 + | +4 | #[rustversion::any(stable(nightly))] + | ^^^^^^^ diff --git a/third_party/rust/rustversion/tests/ui/const-not-fn.rs b/third_party/rust/rustversion/tests/ui/const-not-fn.rs new file mode 100644 index 0000000000..215df7d7d0 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/const-not-fn.rs @@ -0,0 +1,4 @@ +#[rustversion::attr(all(), const)] +pub struct S; + +fn main() {} diff --git a/third_party/rust/rustversion/tests/ui/const-not-fn.stderr b/third_party/rust/rustversion/tests/ui/const-not-fn.stderr new file mode 100644 index 0000000000..d3cb4aa678 --- /dev/null +++ b/third_party/rust/rustversion/tests/ui/const-not-fn.stderr @@ -0,0 +1,5 @@ +error: only allowed on a fn item + --> tests/ui/const-not-fn.rs:1:28 + | +1 | #[rustversion::attr(all(), const)] + | ^^^^^ |