diff options
Diffstat (limited to 'crates/proc_macro_srv/src/tests/mod.rs')
-rw-r--r-- | crates/proc_macro_srv/src/tests/mod.rs | 92 |
1 files changed, 57 insertions, 35 deletions
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 @@ | |||
2 | 2 | ||
3 | #[macro_use] | 3 | #[macro_use] |
4 | mod utils; | 4 | mod utils; |
5 | use test_utils::assert_eq_text; | 5 | use expect_test::expect; |
6 | use utils::*; | 6 | use utils::*; |
7 | 7 | ||
8 | #[test] | 8 | #[test] |
9 | fn test_derive_serialize_proc_macro() { | 9 | fn test_derive_empty() { |
10 | assert_expand("DeriveEmpty", r#"struct S;"#, expect![[r#"SUBTREE $"#]]); | ||
11 | } | ||
12 | |||
13 | #[test] | ||
14 | fn test_derive_error() { | ||
10 | assert_expand( | 15 | assert_expand( |
11 | "serde_derive", | 16 | "DeriveError", |
12 | "Serialize", | 17 | r#"struct S;"#, |
13 | "1.0", | 18 | expect![[r##" |
14 | r"struct Foo {}", | 19 | SUBTREE $ |
15 | include_str!("fixtures/test_serialize_proc_macro.txt"), | 20 | IDENT compile_error 4294967295 |
21 | PUNCH ! [alone] 4294967295 | ||
22 | SUBTREE () 4294967295 | ||
23 | LITERAL "#[derive(DeriveError)] struct S ;" 4294967295 | ||
24 | PUNCH ; [alone] 4294967295"##]], | ||
16 | ); | 25 | ); |
17 | } | 26 | } |
18 | 27 | ||
19 | #[test] | 28 | #[test] |
20 | fn test_derive_serialize_proc_macro_failed() { | 29 | fn test_fn_like_macro() { |
21 | assert_expand( | 30 | assert_expand( |
22 | "serde_derive", | 31 | "fn_like_noop", |
23 | "Serialize", | 32 | r#"ident, 0, 1, []"#, |
24 | "1.0", | 33 | expect![[r#" |
25 | r"struct {}", | 34 | SUBTREE $ |
26 | r##" | 35 | IDENT ident 4294967295 |
27 | SUBTREE $ | 36 | PUNCH , [alone] 4294967295 |
28 | IDENT compile_error 4294967295 | 37 | LITERAL 0 4294967295 |
29 | PUNCH ! [alone] 4294967295 | 38 | PUNCH , [alone] 4294967295 |
30 | SUBTREE {} 4294967295 | 39 | LITERAL 1 4294967295 |
31 | LITERAL "expected identifier" 4294967295 | 40 | PUNCH , [alone] 4294967295 |
32 | "##, | 41 | SUBTREE [] 4294967295"#]], |
33 | ); | 42 | ); |
34 | } | 43 | } |
35 | 44 | ||
36 | #[test] | 45 | #[test] |
37 | fn test_derive_proc_macro_list() { | 46 | fn test_attr_macro() { |
38 | let res = list("serde_derive", "1").join("\n"); | 47 | // Corresponds to |
39 | 48 | // #[proc_macro_test::attr_error(some arguments)] | |
40 | assert_eq_text!( | 49 | // mod m {} |
41 | r#"Serialize [CustomDerive] | 50 | assert_expand_attr( |
42 | Deserialize [CustomDerive]"#, | 51 | "attr_error", |
43 | &res | 52 | r#"mod m {}"#, |
53 | r#"some arguments"#, | ||
54 | expect![[r##" | ||
55 | SUBTREE $ | ||
56 | IDENT compile_error 4294967295 | ||
57 | PUNCH ! [alone] 4294967295 | ||
58 | SUBTREE () 4294967295 | ||
59 | LITERAL "#[attr_error(some arguments)] mod m {}" 4294967295 | ||
60 | PUNCH ; [alone] 4294967295"##]], | ||
44 | ); | 61 | ); |
45 | } | 62 | } |
46 | 63 | ||
47 | /// Tests that we find and classify non-derive macros correctly. | 64 | /// Tests that we find and classify all proc macros correctly. |
48 | #[test] | 65 | #[test] |
49 | fn list_test_macros() { | 66 | fn list_test_macros() { |
50 | let res = list("proc_macro_test", "0.0.0").join("\n"); | 67 | let res = list().join("\n"); |
51 | 68 | ||
52 | assert_eq_text!( | 69 | expect![[r#" |
53 | r#"function_like_macro [FuncLike] | 70 | fn_like_noop [FuncLike] |
54 | attribute_macro [Attr] | 71 | fn_like_panic [FuncLike] |
55 | DummyTrait [CustomDerive]"#, | 72 | fn_like_error [FuncLike] |
56 | &res | 73 | attr_noop [Attr] |
57 | ); | 74 | attr_panic [Attr] |
75 | attr_error [Attr] | ||
76 | DeriveEmpty [CustomDerive] | ||
77 | DerivePanic [CustomDerive] | ||
78 | DeriveError [CustomDerive]"#]] | ||
79 | .assert_eq(&res); | ||
58 | } | 80 | } |
59 | 81 | ||
60 | #[test] | 82 | #[test] |
61 | fn test_version_check() { | 83 | fn test_version_check() { |
62 | let path = fixtures::dylib_path("proc_macro_test", "0.0.0"); | 84 | let path = fixtures::proc_macro_test_dylib_path(); |
63 | let info = proc_macro_api::read_dylib_info(&path).unwrap(); | 85 | let info = proc_macro_api::read_dylib_info(&path).unwrap(); |
64 | assert!(info.version.1 >= 50); | 86 | assert!(info.version.1 >= 50); |
65 | } | 87 | } |