File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed
crates/cargo-test-support/src Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,3 @@ build-man = "run --package xtask-build-man --"
33stale-label = " run --package xtask-stale-label --"
44bump-check = " run --package xtask-bump-check --"
55lint-docs = " run --package xtask-lint-docs --"
6-
7- [env ]
8- # HACK: Until this is stabilized, `snapbox`s polyfill could get confused
9- # inside of the rust-lang/rust repo because it looks for the furthest-away `Cargo.toml`
10- CARGO_RUSTC_CURRENT_DIR = { value = " " , relative = true }
Original file line number Diff line number Diff line change @@ -80,9 +80,32 @@ macro_rules! t {
8080}
8181
8282pub use cargo_util:: ProcessBuilder ;
83- pub use snapbox:: file;
8483pub use snapbox:: str;
85- pub use snapbox:: utils:: current_dir;
84+
85+ /// Find the directory for your source file
86+ #[ macro_export]
87+ macro_rules! current_dir {
88+ ( ) => { {
89+ let root = :: std:: path:: Path :: new( :: std:: env!( "CARGO_MANIFEST_DIR" ) ) ;
90+ let file = :: std:: file!( ) ;
91+ let rel_path = :: std:: path:: Path :: new( file) . parent( ) . unwrap( ) ;
92+ root. join( rel_path)
93+ } } ;
94+ }
95+
96+ /// Declare an expected value for an assert from a file
97+ ///
98+ /// This is relative to the source file the macro is run from
99+ ///
100+ /// Output type: [`snapbox::Data`]
101+ #[ macro_export]
102+ macro_rules! file {
103+ [ $path: literal] => { {
104+ let mut path = $crate:: current_dir!( ) ;
105+ path. push( $path) ;
106+ :: snapbox:: Data :: read_from( & path, None )
107+ } } ;
108+ }
86109
87110/// `panic!`, reporting the specified error , see also [`t!`]
88111#[ track_caller]
Original file line number Diff line number Diff line change @@ -610,6 +610,7 @@ mod tests {
610610 use itertools:: Itertools ;
611611 use snapbox:: ToDebug ;
612612 use std:: collections:: HashSet ;
613+ use std:: path:: Path ;
613614
614615 #[ test]
615616 fn ensure_sorted_lints ( ) {
@@ -647,7 +648,7 @@ mod tests {
647648
648649 #[ test]
649650 fn ensure_updated_lints ( ) {
650- let path = snapbox :: utils :: current_rs! ( ) ;
651+ let path = Path :: new ( std :: env! ( "CARGO_MANIFEST_DIR" ) ) . join ( file ! ( ) ) ;
651652 let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
652653 let expected = expected
653654 . lines ( )
@@ -686,7 +687,7 @@ mod tests {
686687
687688 #[ test]
688689 fn ensure_updated_lint_groups ( ) {
689- let path = snapbox :: utils :: current_rs! ( ) ;
690+ let path = Path :: new ( std :: env! ( "CARGO_MANIFEST_DIR" ) ) . join ( file ! ( ) ) ;
690691 let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
691692 let expected = expected
692693 . lines ( )
You can’t perform that action at this time.
0 commit comments