|
2 | 2 |
|
3 | 3 | #[macro_use]
|
4 | 4 | mod utils;
|
5 |
| -use test_utils::assert_eq_text; |
| 5 | +use expect_test::expect; |
6 | 6 | use utils::*;
|
7 | 7 |
|
8 | 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 | 15 | assert_expand(
|
11 |
| - "serde_derive", |
12 |
| - "Serialize", |
13 |
| - "1.0", |
14 |
| - r"struct Foo {}", |
15 |
| - include_str!("fixtures/test_serialize_proc_macro.txt"), |
| 16 | + "DeriveError", |
| 17 | + r#"struct S;"#, |
| 18 | + expect![[r##" |
| 19 | + SUBTREE $ |
| 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 | 28 | #[test]
|
20 |
| -fn test_derive_serialize_proc_macro_failed() { |
| 29 | +fn test_fn_like_macro() { |
21 | 30 | assert_expand(
|
22 |
| - "serde_derive", |
23 |
| - "Serialize", |
24 |
| - "1.0", |
25 |
| - r"struct {}", |
26 |
| - r##" |
27 |
| -SUBTREE $ |
28 |
| - IDENT compile_error 4294967295 |
29 |
| - PUNCH ! [alone] 4294967295 |
30 |
| - SUBTREE {} 4294967295 |
31 |
| - LITERAL "expected identifier" 4294967295 |
32 |
| -"##, |
| 31 | + "fn_like_noop", |
| 32 | + r#"ident, 0, 1, []"#, |
| 33 | + expect![[r#" |
| 34 | + SUBTREE $ |
| 35 | + IDENT ident 4294967295 |
| 36 | + PUNCH , [alone] 4294967295 |
| 37 | + LITERAL 0 4294967295 |
| 38 | + PUNCH , [alone] 4294967295 |
| 39 | + LITERAL 1 4294967295 |
| 40 | + PUNCH , [alone] 4294967295 |
| 41 | + SUBTREE [] 4294967295"#]], |
33 | 42 | );
|
34 | 43 | }
|
35 | 44 |
|
36 | 45 | #[test]
|
37 |
| -fn test_derive_proc_macro_list() { |
38 |
| - let res = list("serde_derive", "1").join("\n"); |
39 |
| - |
40 |
| - assert_eq_text!( |
41 |
| - r#"Serialize [CustomDerive] |
42 |
| -Deserialize [CustomDerive]"#, |
43 |
| - &res |
| 46 | +fn test_attr_macro() { |
| 47 | + // Corresponds to |
| 48 | + // #[proc_macro_test::attr_error(some arguments)] |
| 49 | + // mod m {} |
| 50 | + assert_expand_attr( |
| 51 | + "attr_error", |
| 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 | 65 | #[test]
|
49 | 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!( |
53 |
| - r#"function_like_macro [FuncLike] |
54 |
| -attribute_macro [Attr] |
55 |
| -DummyTrait [CustomDerive]"#, |
56 |
| - &res |
57 |
| - ); |
| 69 | + expect![[r#" |
| 70 | + fn_like_noop [FuncLike] |
| 71 | + fn_like_panic [FuncLike] |
| 72 | + fn_like_error [FuncLike] |
| 73 | + attr_noop [Attr] |
| 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 | 82 | #[test]
|
61 | 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 | 85 | let info = proc_macro_api::read_dylib_info(&path).unwrap();
|
64 | 86 | assert!(info.version.1 >= 50);
|
65 | 87 | }
|
0 commit comments