From cfcadcb2959d2dbaf7d95e8b9a33c48b75480e9f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 31 May 2021 17:32:56 +0200 Subject: Simplify proc_macro_srv tests --- crates/proc_macro_srv/src/tests/mod.rs | 92 +++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 35 deletions(-) (limited to 'crates/proc_macro_srv/src/tests/mod.rs') diff --git a/crates/proc_macro_srv/src/tests/mod.rs b/crates/proc_macro_srv/src/tests/mod.rs index b4ab4c077..5ca2b8a75 100644 --- a/crates/proc_macro_srv/src/tests/mod.rs +++ b/crates/proc_macro_srv/src/tests/mod.rs @@ -2,64 +2,86 @@ #[macro_use] mod utils; -use test_utils::assert_eq_text; +use expect_test::expect; use utils::*; #[test] -fn test_derive_serialize_proc_macro() { +fn test_derive_empty() { + assert_expand("DeriveEmpty", r#"struct S;"#, expect![[r#"SUBTREE $"#]]); +} + +#[test] +fn test_derive_error() { assert_expand( - "serde_derive", - "Serialize", - "1.0", - r"struct Foo {}", - include_str!("fixtures/test_serialize_proc_macro.txt"), + "DeriveError", + r#"struct S;"#, + expect![[r##" + SUBTREE $ + IDENT compile_error 4294967295 + PUNCH ! [alone] 4294967295 + SUBTREE () 4294967295 + LITERAL "#[derive(DeriveError)] struct S ;" 4294967295 + PUNCH ; [alone] 4294967295"##]], ); } #[test] -fn test_derive_serialize_proc_macro_failed() { +fn test_fn_like_macro() { assert_expand( - "serde_derive", - "Serialize", - "1.0", - r"struct {}", - r##" -SUBTREE $ - IDENT compile_error 4294967295 - PUNCH ! [alone] 4294967295 - SUBTREE {} 4294967295 - LITERAL "expected identifier" 4294967295 -"##, + "fn_like_noop", + r#"ident, 0, 1, []"#, + expect![[r#" + SUBTREE $ + IDENT ident 4294967295 + PUNCH , [alone] 4294967295 + LITERAL 0 4294967295 + PUNCH , [alone] 4294967295 + LITERAL 1 4294967295 + PUNCH , [alone] 4294967295 + SUBTREE [] 4294967295"#]], ); } #[test] -fn test_derive_proc_macro_list() { - let res = list("serde_derive", "1").join("\n"); - - assert_eq_text!( - r#"Serialize [CustomDerive] -Deserialize [CustomDerive]"#, - &res +fn test_attr_macro() { + // Corresponds to + // #[proc_macro_test::attr_error(some arguments)] + // mod m {} + assert_expand_attr( + "attr_error", + r#"mod m {}"#, + r#"some arguments"#, + expect![[r##" + SUBTREE $ + IDENT compile_error 4294967295 + PUNCH ! [alone] 4294967295 + SUBTREE () 4294967295 + LITERAL "#[attr_error(some arguments)] mod m {}" 4294967295 + PUNCH ; [alone] 4294967295"##]], ); } -/// Tests that we find and classify non-derive macros correctly. +/// Tests that we find and classify all proc macros correctly. #[test] fn list_test_macros() { - let res = list("proc_macro_test", "0.0.0").join("\n"); + let res = list().join("\n"); - assert_eq_text!( - r#"function_like_macro [FuncLike] -attribute_macro [Attr] -DummyTrait [CustomDerive]"#, - &res - ); + expect![[r#" + fn_like_noop [FuncLike] + fn_like_panic [FuncLike] + fn_like_error [FuncLike] + attr_noop [Attr] + attr_panic [Attr] + attr_error [Attr] + DeriveEmpty [CustomDerive] + DerivePanic [CustomDerive] + DeriveError [CustomDerive]"#]] + .assert_eq(&res); } #[test] fn test_version_check() { - let path = fixtures::dylib_path("proc_macro_test", "0.0.0"); + let path = fixtures::proc_macro_test_dylib_path(); let info = proc_macro_api::read_dylib_info(&path).unwrap(); assert!(info.version.1 >= 50); } -- cgit v1.2.3