Skip to content

Commit d1b1867

Browse files
Merge #9083
9083: internal: Simplify proc_macro_srv tests r=jonas-schievink a=jonas-schievink Removes `serde_derive`, instead using `proc_macro_test` macros. Should fix #9067 bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents 70e3473 + cfcadcb commit d1b1867

File tree

6 files changed

+117
-242
lines changed

6 files changed

+117
-242
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/proc_macro_srv/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" }
2020

2121
[dev-dependencies]
2222
test_utils = { path = "../test_utils" }
23+
toolchain = { path = "../toolchain" }
2324
cargo_metadata = "0.13"
25+
expect-test = "1.1.0"
2426

2527
# used as proc macro test targets
26-
serde_derive = "1.0.106"
2728
proc_macro_test = { path = "../proc_macro_test" }
28-
29-
toolchain = { path = "../toolchain" }

crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt

Lines changed: 0 additions & 181 deletions
This file was deleted.

crates/proc_macro_srv/src/tests/mod.rs

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,86 @@
22
33
#[macro_use]
44
mod utils;
5-
use test_utils::assert_eq_text;
5+
use expect_test::expect;
66
use utils::*;
77

88
#[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() {
1015
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"##]],
1625
);
1726
}
1827

1928
#[test]
20-
fn test_derive_serialize_proc_macro_failed() {
29+
fn test_fn_like_macro() {
2130
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"#]],
3342
);
3443
}
3544

3645
#[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"##]],
4461
);
4562
}
4663

47-
/// Tests that we find and classify non-derive macros correctly.
64+
/// Tests that we find and classify all proc macros correctly.
4865
#[test]
4966
fn list_test_macros() {
50-
let res = list("proc_macro_test", "0.0.0").join("\n");
67+
let res = list().join("\n");
5168

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);
5880
}
5981

6082
#[test]
6183
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();
6385
let info = proc_macro_api::read_dylib_info(&path).unwrap();
6486
assert!(info.version.1 >= 50);
6587
}

0 commit comments

Comments
 (0)