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 --"
3
3
stale-label = " run --package xtask-stale-label --"
4
4
bump-check = " run --package xtask-bump-check --"
5
5
lint-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 {
80
80
}
81
81
82
82
pub use cargo_util:: ProcessBuilder ;
83
- pub use snapbox:: file;
84
83
pub 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
+ }
86
109
87
110
/// `panic!`, reporting the specified error , see also [`t!`]
88
111
#[ track_caller]
Original file line number Diff line number Diff line change @@ -610,6 +610,7 @@ mod tests {
610
610
use itertools:: Itertools ;
611
611
use snapbox:: ToDebug ;
612
612
use std:: collections:: HashSet ;
613
+ use std:: path:: Path ;
613
614
614
615
#[ test]
615
616
fn ensure_sorted_lints ( ) {
@@ -647,7 +648,7 @@ mod tests {
647
648
648
649
#[ test]
649
650
fn ensure_updated_lints ( ) {
650
- let path = snapbox :: utils :: current_rs! ( ) ;
651
+ let path = Path :: new ( std :: env! ( "CARGO_MANIFEST_DIR" ) ) . join ( file ! ( ) ) ;
651
652
let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
652
653
let expected = expected
653
654
. lines ( )
@@ -686,7 +687,7 @@ mod tests {
686
687
687
688
#[ test]
688
689
fn ensure_updated_lint_groups ( ) {
689
- let path = snapbox :: utils :: current_rs! ( ) ;
690
+ let path = Path :: new ( std :: env! ( "CARGO_MANIFEST_DIR" ) ) . join ( file ! ( ) ) ;
690
691
let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
691
692
let expected = expected
692
693
. lines ( )
You can’t perform that action at this time.
0 commit comments