Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/libtest2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ escargot = "0.5.8"
once_cell_polyfill = "1.56.0"
pathdiff = "0.2.1"
snapbox = { version = "0.6.0", features = ["json"] }
trybuild = "1.0.111"

[lints]
workspace = true
5 changes: 5 additions & 0 deletions crates/libtest2/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
8 changes: 8 additions & 0 deletions crates/libtest2/tests/ui/ignore_incorrect_usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
#[ignore(reason = "invalid syntax right here")]
fn test(_: &libtest2::TestContext) {
panic!("We just need to compile this");
}
7 changes: 7 additions & 0 deletions crates/libtest2/tests/ui/ignore_incorrect_usage.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: unknown attribute 'ignore(reason = "invalid syntax right here")'
--> tests/ui/ignore_incorrect_usage.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
8 changes: 8 additions & 0 deletions crates/libtest2/tests/ui/should_panic_attribute_typo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
#[should_panic(expect = "something")]
fn test(_: &libtest2::TestContext) {
panic!("the correct attribute is 'expected = \"...\"'");
}
7 changes: 7 additions & 0 deletions crates/libtest2/tests/ui/should_panic_attribute_typo.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: unknown attribute 'should_panic(expect = "something")'
--> tests/ui/should_panic_attribute_typo.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
17 changes: 17 additions & 0 deletions crates/libtest2/tests/ui/should_panic_multiple_attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
#[should_panic]
#[should_panic]
fn test_1(_: &libtest2::TestContext) {}

#[libtest2::test]
#[should_panic]
#[should_panic(reason = "something")]
fn test_2(_: &libtest2::TestContext) {}

#[libtest2::test]
#[should_panic = "anything"]
#[should_panic]
fn test_3(_: &libtest2::TestContext) {}
23 changes: 23 additions & 0 deletions crates/libtest2/tests/ui/should_panic_multiple_attributes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: annotating a test with multiple 'should_panic' attributes is not allowed
--> tests/ui/should_panic_multiple_attributes.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)

error: annotating a test with multiple 'should_panic' attributes is not allowed
--> tests/ui/should_panic_multiple_attributes.rs:9:1
|
9 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)

error: annotating a test with multiple 'should_panic' attributes is not allowed
--> tests/ui/should_panic_multiple_attributes.rs:14:1
|
14 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 6 additions & 0 deletions crates/libtest2/tests/ui/unsupported_attribute.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
#[unsafe(no_mangle)] // we just need some unknown attribute here
fn test(_: &libtest2::TestContext) {}
7 changes: 7 additions & 0 deletions crates/libtest2/tests/ui/unsupported_attribute.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: unknown attribute 'unsafe(no_mangle)'
--> tests/ui/unsupported_attribute.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
5 changes: 5 additions & 0 deletions crates/libtest2/tests/ui/unsupported_parameter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
fn takes_integer(_: i32) {}
17 changes: 17 additions & 0 deletions crates/libtest2/tests/ui/unsupported_parameter.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> tests/ui/unsupported_parameter.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
| |
| expected `i32`, found `&TestContext`
| arguments to this function are incorrect
|
note: function defined here
--> tests/ui/unsupported_parameter.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
5 | fn takes_integer(_: i32) {}
| ------
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
12 changes: 12 additions & 0 deletions crates/libtest2/tests/ui/unsupported_result_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
fn bad_ok_variant(_: &libtest2::TestContext) -> Result<i32, std::io::Error> {
Ok(0)
}

#[libtest2::test]
fn bad_err_variant(_: &libtest2::TestContext) -> Result<(), String> {
Ok(())
}
28 changes: 28 additions & 0 deletions crates/libtest2/tests/ui/unsupported_result_types.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0277]: the trait bound `Result<i32, std::io::Error>: IntoRunResult` is not satisfied
--> tests/ui/unsupported_result_types.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
| |
| the trait `IntoRunResult` is not implemented for `Result<i32, std::io::Error>`
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoRunResult`:
Result<(), E>
Result<(), RunError>
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `String: std::error::Error` is not satisfied
--> tests/ui/unsupported_result_types.rs:9:1
|
9 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
| |
| the trait `std::error::Error` is not implemented for `String`
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoRunResult`:
Result<(), E>
Result<(), RunError>
= note: required for `Result<(), String>` to implement `IntoRunResult`
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)
7 changes: 7 additions & 0 deletions crates/libtest2/tests/ui/unsupported_return_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[libtest2::main]
fn main() {}

#[libtest2::test]
fn integer(_: &libtest2::TestContext) -> i32 {
0
}
14 changes: 14 additions & 0 deletions crates/libtest2/tests/ui/unsupported_return_type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0277]: the trait bound `i32: IntoRunResult` is not satisfied
--> tests/ui/unsupported_return_type.rs:4:1
|
4 | #[libtest2::test]
| ^^^^^^^^^^^^^^^^^
| |
| the trait `IntoRunResult` is not implemented for `i32`
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoRunResult`:
()
Result<(), E>
Result<(), RunError>
= note: this error originates in the macro `$crate::_private::test_parse` which comes from the expansion of the attribute macro `libtest2::test` (in Nightly builds, run with -Z macro-backtrace for more info)