-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(stackable-versioned-macros): Use trybuild to test good/bad examp…
…les (#849) * fix(script): be more explicit about where to find Cargo.tomls * test(stackable-versioned-macros): move tests without assertions into trybuild pass/fail examples * ci(build): add rust-src component for testing
- Loading branch information
1 parent
ece7410
commit 68d0cb2
Showing
21 changed files
with
350 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ quote.workspace = true | |
|
||
[dev-dependencies] | ||
rstest.workspace = true | ||
trybuild.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# trybuild bad cases | ||
|
||
Code that is expected to fail lives here along with the expected compiler output | ||
for each case. Please see the docs in [tests/trybuild.rs]. | ||
|
||
[tests/trybuild.rs]: ../trybuild.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use stackable_versioned_macros::versioned; | ||
|
||
fn main() { | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version(name = "v1beta1"), | ||
version(name = "v1") | ||
)] | ||
struct Foo { | ||
#[deprecated] | ||
bar: usize, | ||
baz: bool, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: deprecation must be done using #[versioned(deprecated(since = "VERSION"))] | ||
--> tests/bad/deprecate.rs:10:9 | ||
| | ||
10 | #[deprecated] | ||
| ^ |
24 changes: 24 additions & 0 deletions
24
crates/stackable-versioned-macros/tests/bad/skip_from_all.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use stackable_versioned_macros::versioned; | ||
|
||
fn main() { | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version(name = "v1beta1"), | ||
version(name = "v1"), | ||
options(skip(from)) | ||
)] | ||
pub struct Foo { | ||
#[versioned( | ||
added(since = "v1beta1"), | ||
deprecated(since = "v1", note = "not needed") | ||
)] | ||
deprecated_bar: usize, | ||
baz: bool, | ||
} | ||
|
||
let foo_v1alpha1 = v1alpha1::Foo { baz: true }; | ||
|
||
// There are no From impls for any version. You need to convert it manually. | ||
#[allow(dead_code)] | ||
let foo_v1beta1 = v1beta1::Foo::from(foo_v1alpha1); | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/stackable-versioned-macros/tests/bad/skip_from_all.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0308]: mismatched types | ||
--> tests/bad/skip_from_all.rs:23:42 | ||
| | ||
23 | let foo_v1beta1 = v1beta1::Foo::from(foo_v1alpha1); | ||
| ------------------ ^^^^^^^^^^^^ expected `v1beta1::Foo`, found `v1alpha1::Foo` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: `v1alpha1::Foo` and `v1beta1::Foo` have similar names, but are actually distinct types | ||
note: `v1alpha1::Foo` is defined in module `crate::main::v1alpha1` of the current crate | ||
--> tests/bad/skip_from_all.rs:4:5 | ||
| | ||
4 | / #[versioned( | ||
5 | | version(name = "v1alpha1"), | ||
6 | | version(name = "v1beta1"), | ||
7 | | version(name = "v1"), | ||
8 | | options(skip(from)) | ||
9 | | )] | ||
| |______^ | ||
note: `v1beta1::Foo` is defined in module `crate::main::v1beta1` of the current crate | ||
--> tests/bad/skip_from_all.rs:4:5 | ||
| | ||
4 | / #[versioned( | ||
5 | | version(name = "v1alpha1"), | ||
6 | | version(name = "v1beta1"), | ||
7 | | version(name = "v1"), | ||
8 | | options(skip(from)) | ||
9 | | )] | ||
| |______^ | ||
note: associated function defined here | ||
--> $RUST/core/src/convert/mod.rs | ||
| | ||
| fn from(value: T) -> Self; | ||
| ^^^^ | ||
= note: this error originates in the attribute macro `versioned` (in Nightly builds, run with -Z macro-backtrace for more info) |
24 changes: 24 additions & 0 deletions
24
crates/stackable-versioned-macros/tests/bad/skip_from_version.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use stackable_versioned_macros::versioned; | ||
|
||
fn main() { | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version(name = "v1beta1", skip(from)), | ||
version(name = "v1") | ||
)] | ||
pub struct Foo { | ||
#[versioned( | ||
added(since = "v1beta1"), | ||
deprecated(since = "v1", note = "not needed") | ||
)] | ||
deprecated_bar: usize, | ||
baz: bool, | ||
} | ||
|
||
let foo_v1alpha1 = v1alpha1::Foo { baz: true }; | ||
let foo_v1beta1 = v1beta1::Foo::from(foo_v1alpha1); | ||
|
||
#[allow(dead_code)] | ||
// v1beta1 has no From impl. You need to convert it manually. | ||
let foo_v1 = v1::Foo::from(foo_v1beta1); | ||
} |
33 changes: 33 additions & 0 deletions
33
crates/stackable-versioned-macros/tests/bad/skip_from_version.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0308]: mismatched types | ||
--> tests/bad/skip_from_version.rs:23:32 | ||
| | ||
23 | let foo_v1 = v1::Foo::from(foo_v1beta1); | ||
| ------------- ^^^^^^^^^^^ expected `main::v1::Foo`, found `v1beta1::Foo` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: `v1beta1::Foo` and `main::v1::Foo` have similar names, but are actually distinct types | ||
note: `v1beta1::Foo` is defined in module `crate::main::v1beta1` of the current crate | ||
--> tests/bad/skip_from_version.rs:4:5 | ||
| | ||
4 | / #[versioned( | ||
5 | | version(name = "v1alpha1"), | ||
6 | | version(name = "v1beta1", skip(from)), | ||
7 | | version(name = "v1") | ||
8 | | )] | ||
| |______^ | ||
note: `main::v1::Foo` is defined in module `crate::main::v1` of the current crate | ||
--> tests/bad/skip_from_version.rs:4:5 | ||
| | ||
4 | / #[versioned( | ||
5 | | version(name = "v1alpha1"), | ||
6 | | version(name = "v1beta1", skip(from)), | ||
7 | | version(name = "v1") | ||
8 | | )] | ||
| |______^ | ||
note: associated function defined here | ||
--> $RUST/core/src/convert/mod.rs | ||
| | ||
| fn from(value: T) -> Self; | ||
| ^^^^ | ||
= note: this error originates in the attribute macro `versioned` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# trybuild good cases | ||
|
||
Code that is expected to compile lives here. Please see the docs in | ||
[tests/trybuild.rs]. | ||
|
||
[tests/trybuild.rs]: ../trybuild.rs |
Oops, something went wrong.