1 //! proc-macro tests
2
3 #[macro_use]
4 mod utils;
5 use expect_test::expect;
6 use paths::AbsPathBuf;
7 use utils::*;
8
9 #[test]
test_derive_empty()10 fn test_derive_empty() {
11 assert_expand("DeriveEmpty", r#"struct S;"#, expect![[r#"SUBTREE $"#]]);
12 }
13
14 #[test]
test_derive_error()15 fn test_derive_error() {
16 assert_expand(
17 "DeriveError",
18 r#"struct S;"#,
19 expect![[r##"
20 SUBTREE $
21 IDENT compile_error 4294967295
22 PUNCH ! [alone] 4294967295
23 SUBTREE () 4294967295
24 LITERAL "#[derive(DeriveError)] struct S ;" 4294967295
25 PUNCH ; [alone] 4294967295"##]],
26 );
27 }
28
29 #[test]
test_fn_like_macro()30 fn test_fn_like_macro() {
31 assert_expand(
32 "fn_like_noop",
33 r#"ident, 0, 1, []"#,
34 expect![[r#"
35 SUBTREE $
36 IDENT ident 4294967295
37 PUNCH , [alone] 4294967295
38 LITERAL 0 4294967295
39 PUNCH , [alone] 4294967295
40 LITERAL 1 4294967295
41 PUNCH , [alone] 4294967295
42 SUBTREE [] 4294967295"#]],
43 );
44 }
45
46 #[test]
test_fn_like_macro2()47 fn test_fn_like_macro2() {
48 assert_expand(
49 "fn_like_clone_tokens",
50 r#"ident, []"#,
51 expect![[r#"
52 SUBTREE $
53 IDENT ident 4294967295
54 PUNCH , [alone] 4294967295
55 SUBTREE [] 4294967295"#]],
56 );
57 }
58
59 #[test]
test_attr_macro()60 fn test_attr_macro() {
61 // Corresponds to
62 // #[proc_macro_test::attr_error(some arguments)]
63 // mod m {}
64 assert_expand_attr(
65 "attr_error",
66 r#"mod m {}"#,
67 r#"some arguments"#,
68 expect![[r##"
69 SUBTREE $
70 IDENT compile_error 4294967295
71 PUNCH ! [alone] 4294967295
72 SUBTREE () 4294967295
73 LITERAL "#[attr_error(some arguments)] mod m {}" 4294967295
74 PUNCH ; [alone] 4294967295"##]],
75 );
76 }
77
78 /// Tests that we find and classify all proc macros correctly.
79 #[test]
list_test_macros()80 fn list_test_macros() {
81 let res = list().join("\n");
82
83 expect![[r#"
84 fn_like_noop [FuncLike]
85 fn_like_panic [FuncLike]
86 fn_like_error [FuncLike]
87 fn_like_clone_tokens [FuncLike]
88 attr_noop [Attr]
89 attr_panic [Attr]
90 attr_error [Attr]
91 DeriveEmpty [CustomDerive]
92 DerivePanic [CustomDerive]
93 DeriveError [CustomDerive]"#]]
94 .assert_eq(&res);
95 }
96
97 #[test]
test_version_check()98 fn test_version_check() {
99 let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
100 let info = proc_macro_api::read_dylib_info(&path).unwrap();
101 assert!(info.version.1 >= 50);
102 }
103