Skip to content

Commit e0ce066

Browse files
committed
test: migrate proc_macro to snapbox
1 parent ad6f029 commit e0ce066

File tree

1 file changed

+71
-26
lines changed

1 file changed

+71
-26
lines changed

tests/testsuite/proc_macro.rs

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Tests for proc-macros.
22
3-
#![allow(deprecated)]
4-
3+
use cargo_test_support::prelude::*;
54
use cargo_test_support::project;
5+
use cargo_test_support::str;
66

77
#[cargo_test]
88
fn probe_cfg_before_crate_type_discovery() {
@@ -207,7 +207,12 @@ fn impl_and_derive() {
207207
.build();
208208

209209
p.cargo("build").run();
210-
p.cargo("run").with_stdout("X { success: true }").run();
210+
p.cargo("run")
211+
.with_stdout_data(str![[r#"
212+
X { success: true }
213+
214+
"#]])
215+
.run();
211216
}
212217

213218
#[cargo_test]
@@ -251,8 +256,21 @@ fn proc_macro_doctest() {
251256
.build();
252257

253258
foo.cargo("test")
254-
.with_stdout_contains("test a ... ok")
255-
.with_stdout_contains_n("test [..] ... ok", 2)
259+
.with_stdout_data(str![[r#"
260+
261+
running 1 test
262+
test a ... ok
263+
264+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
265+
266+
267+
running 1 test
268+
test src/lib.rs - derive (line 8) ... ok
269+
270+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
271+
272+
273+
"#]])
256274
.run();
257275
}
258276

@@ -319,8 +337,21 @@ fn proc_macro_crate_type() {
319337
.build();
320338

321339
foo.cargo("test")
322-
.with_stdout_contains("test tests::it_works ... ok")
323-
.with_stdout_contains_n("test [..] ... ok", 2)
340+
.with_stdout_data(str![[r#"
341+
342+
running 1 test
343+
test tests::it_works ... ok
344+
345+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
346+
347+
348+
running 1 test
349+
test src/lib.rs - (line 2) ... ok
350+
351+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
352+
353+
354+
"#]])
324355
.run();
325356
}
326357

@@ -342,8 +373,12 @@ fn proc_macro_crate_type_warning() {
342373
.build();
343374

344375
foo.cargo("check")
345-
.with_stderr_contains(
346-
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
376+
.with_stderr_data(str![[r#"
377+
[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`
378+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
379+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
380+
381+
"#]])
347382
.run();
348383
}
349384

@@ -365,7 +400,12 @@ fn lib_plugin_unused_key_warning() {
365400
.build();
366401

367402
foo.cargo("check")
368-
.with_stderr_contains("[WARNING] unused manifest key: lib.plugin")
403+
.with_stderr_data(str![[r#"
404+
[WARNING] unused manifest key: lib.plugin
405+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
406+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
407+
408+
"#]])
369409
.run();
370410
}
371411

@@ -387,9 +427,13 @@ fn proc_macro_crate_type_warning_plugin() {
387427
.build();
388428

389429
foo.cargo("check")
390-
.with_stderr_contains(
391-
"[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`")
392-
.run();
430+
.with_stderr_data(str![[r#"
431+
[WARNING] library `foo` should only specify `proc-macro = true` instead of setting `crate-type`
432+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
433+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
434+
435+
"#]])
436+
.run();
393437
}
394438

395439
#[cargo_test]
@@ -410,14 +454,13 @@ fn proc_macro_crate_type_multiple() {
410454
.build();
411455

412456
foo.cargo("check")
413-
.with_stderr(
414-
"\
415-
[ERROR] failed to parse manifest at `[..]/foo/Cargo.toml`
457+
.with_stderr_data(str![[r#"
458+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
416459
417460
Caused by:
418461
cannot mix `proc-macro` crate type with others
419-
",
420-
)
462+
463+
"#]])
421464
.with_status(101)
422465
.run();
423466
}
@@ -508,19 +551,21 @@ fn proc_macro_built_once() {
508551
.file("the-macro/src/lib.rs", "")
509552
.build();
510553
p.cargo("build --verbose")
511-
.with_stderr_unordered(
512-
"\
554+
.with_stderr_data(
555+
str![[r#"
513556
[LOCKING] 3 packages to latest compatible versions
514-
[COMPILING] the-macro [..]
557+
[COMPILING] the-macro v0.1.0 ([ROOT]/foo/the-macro)
515558
[RUNNING] `rustc --crate-name the_macro [..]`
516-
[COMPILING] b [..]
559+
[COMPILING] b v0.1.0 ([ROOT]/foo/b)
517560
[RUNNING] `rustc --crate-name b [..]`
518-
[COMPILING] a [..]
561+
[COMPILING] a v0.1.0 ([ROOT]/foo/a)
519562
[RUNNING] `rustc --crate-name build_script_build [..]`
520-
[RUNNING] `[..]build[..]script[..]build[..]`
563+
[RUNNING] `[ROOT]/foo/target/debug/build/a-[HASH]/build-script-build`
521564
[RUNNING] `rustc --crate-name a [..]`
522-
[FINISHED] [..]
523-
",
565+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
566+
567+
"#]]
568+
.unordered(),
524569
)
525570
.run();
526571
}

0 commit comments

Comments
 (0)