From a15c3f638c073eae69802d442913ad53d0806d99 Mon Sep 17 00:00:00 2001 From: Filippo Costa Date: Sat, 26 Aug 2023 05:26:41 +0200 Subject: [PATCH] Attempt at trybuild test --- tests/Cargo.lock | 64 ++++++++++++++++++++- tests/Cargo.toml | 3 + tests/tests/trybuild.rs | 6 ++ tests/tests/trybuild/empty_main.rs | 1 + tests/tests/trybuild/fail_to_compile.rs | 3 + tests/tests/trybuild/fail_to_compile.stderr | 5 ++ 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 tests/tests/trybuild.rs create mode 100644 tests/tests/trybuild/empty_main.rs create mode 100644 tests/tests/trybuild/fail_to_compile.rs create mode 100644 tests/tests/trybuild/fail_to_compile.stderr diff --git a/tests/Cargo.lock b/tests/Cargo.lock index fcde97f..51ac318 100644 --- a/tests/Cargo.lock +++ b/tests/Cargo.lock @@ -14,6 +14,15 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +[[package]] +name = "basic-toml" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -148,6 +157,12 @@ dependencies = [ "pin-utils", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.14" @@ -524,6 +539,7 @@ version = "0.1.0" dependencies = [ "reqwest", "tikv-jemallocator", + "trybuild", "watto", ] @@ -568,9 +584,20 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.144" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" @@ -639,6 +666,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.33" @@ -767,6 +803,21 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "trybuild" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501dbdbb99861e4ab6b60eb6a7493956a9defb644fd034bc4a5ef27c693c8a3a" +dependencies = [ + "basic-toml", + "glob", + "once_cell", + "serde", + "serde_derive", + "serde_json", + "termcolor", +] + [[package]] name = "unicode-bidi" version = "0.3.8" @@ -923,6 +974,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/tests/Cargo.toml b/tests/Cargo.toml index c189021..ba14017 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -9,5 +9,8 @@ edition = "2021" reqwest = "0.11.18" watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102a124a460d64da25e303dc", features = ["strings"] } +[dev-dependencies] +trybuild = "1" + [target.'cfg(not(target_env = "msvc"))'.dependencies] tikv-jemallocator = "0.5.4" diff --git a/tests/tests/trybuild.rs b/tests/tests/trybuild.rs new file mode 100644 index 0000000..8a871f1 --- /dev/null +++ b/tests/tests/trybuild.rs @@ -0,0 +1,6 @@ +#[test] +fn test_trybuild() { + let t = trybuild::TestCases::new(); + t.pass("tests/trybuild/empty_main.rs"); + t.compile_fail("tests/trybuild/fail_to_compile.rs"); +} diff --git a/tests/tests/trybuild/empty_main.rs b/tests/tests/trybuild/empty_main.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/tests/tests/trybuild/empty_main.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/tests/trybuild/fail_to_compile.rs b/tests/tests/trybuild/fail_to_compile.rs new file mode 100644 index 0000000..4de098c --- /dev/null +++ b/tests/tests/trybuild/fail_to_compile.rs @@ -0,0 +1,3 @@ +fn main() { + "foobar".foobar(); +} diff --git a/tests/tests/trybuild/fail_to_compile.stderr b/tests/tests/trybuild/fail_to_compile.stderr new file mode 100644 index 0000000..fac6619 --- /dev/null +++ b/tests/tests/trybuild/fail_to_compile.stderr @@ -0,0 +1,5 @@ +error[E0599]: no method named `foobar` found for reference `&'static str` in the current scope + --> tests/trybuild/fail_to_compile.rs:2:14 + | +2 | "foobar".foobar(); + | ^^^^^^ method not found in `&str`