@@ -27,7 +27,7 @@ struct SnapTestBuilder {
2727 fixture_dir : PathBuf ,
2828 snapshot_dir : PathBuf ,
2929 target_fn : syn:: Path ,
30- insta_assert_macro : syn :: Path ,
30+ debug_snap : bool ,
3131}
3232
3333impl SnapTestBuilder {
@@ -55,7 +55,7 @@ impl SnapTestBuilder {
5555 fixture_dir,
5656 snapshot_dir,
5757 target_fn : args. target_fn ,
58- insta_assert_macro : args. insta_assert_macro ,
58+ debug_snap : args. debug_snap . value ( ) ,
5959 } )
6060 }
6161
@@ -85,24 +85,33 @@ impl SnapTestBuilder {
8585
8686 let snapshot_dir = self . snapshot_dir . to_str ( ) . unwrap ( ) ;
8787 let target_fn = & self . target_fn ;
88- let insta_assert_macro = & self . insta_assert_macro ;
88+ let snapshot = syn:: Ident :: new ( "snapshot" , proc_macro2:: Span :: call_site ( ) ) ;
89+ let get_snapshot = if self . debug_snap {
90+ quote ! {
91+ let #snapshot = format!( "{:#?}" , #target_fn( & input) ) ;
92+ }
93+ } else {
94+ quote ! {
95+ let #snapshot = #target_fn( & input) ;
96+ }
97+ } ;
8998
9099 quote ! {
91100 #[ test]
92101 fn #test_fn_ident( ) {
93- let input = std:: fs:: read_to_string( #fixture_file) . unwrap( ) ;
94- let snapshot = #target_fn( & input) ;
95- fe_compiler_test_utils:: _insta:: with_settings! (
96- {
97- snapshot_path => #snapshot_dir,
98- input_file => Some ( #file_name. into( ) ) ,
99- prepend_module_to_snapshot => false ,
100- } ,
101- {
102- #insta_assert_macro!( snapshot) ;
103- } )
102+ let input = :: std:: fs:: read_to_string( #fixture_file) . unwrap( ) ;
103+ #get_snapshot
104+ let mut settings = :: fe_compiler_test_utils:: _macro_support:: _insta:: Settings :: new( ) ;
105+ settings. set_snapshot_path( #snapshot_dir) ;
106+ settings. set_input_file( #file_name) ;
107+ settings. set_prepend_module_to_snapshot( false ) ;
108+
109+
110+ :: fe_compiler_test_utils:: _insta_assert_snapshot!{
111+ #snapshot,
112+ settings
113+ }
104114 }
105-
106115 }
107116 }
108117}
@@ -123,7 +132,7 @@ struct Args {
123132 fixture_dir : syn:: LitStr ,
124133 snapshot_dir : syn:: LitStr ,
125134 target_fn : syn:: Path ,
126- insta_assert_macro : syn:: Path ,
135+ debug_snap : syn:: LitBool ,
127136}
128137
129138impl syn:: parse:: Parse for Args {
@@ -132,7 +141,7 @@ impl syn::parse::Parse for Args {
132141 fixture_dir: ..,
133142 snapshot_dir: ..,
134143 target_fn: ..,
135- insta_assert_macro : ..,
144+ debug_snap : ..
136145 }`" ;
137146
138147 let ident = input. parse :: < syn:: Ident > ( ) ?;
@@ -160,17 +169,17 @@ impl syn::parse::Parse for Args {
160169 input. parse :: < syn:: Token ![ , ] > ( ) ?;
161170
162171 let ident = input. parse :: < syn:: Ident > ( ) ?;
163- if ident != "insta_assert_macro " {
172+ if ident != "debug_snap " {
164173 return Err ( Error :: new_spanned ( ident, error_msg) ) ;
165174 }
166175 input. parse :: < syn:: Token ![ : ] > ( ) ?;
167- let insta_assert_macro = input. parse :: < syn:: Path > ( ) ?;
176+ let debug_snap = input. parse :: < syn:: LitBool > ( ) ?;
168177
169178 Ok ( Self {
170179 fixture_dir,
171180 snapshot_dir,
172181 target_fn,
173- insta_assert_macro ,
182+ debug_snap ,
174183 } )
175184 }
176185}
0 commit comments