@@ -105,14 +105,14 @@ impl MockNodeKind {
105105 }
106106}
107107
108- fn testname_from_backtrace ( bn : & str ) -> String {
108+ fn testname_from_backtrace ( bn : & str ) -> Option < String > {
109109 log:: info!( "Test name to regex match: {}" , & bn) ;
110110 // Extract test name
111- let captures = Regex :: new ( r"(.*)::(.*)::.*" ) . unwrap ( ) . captures ( bn) . unwrap ( ) ;
111+ let captures = Regex :: new ( r"(.*)::(.*)::.*" ) . unwrap ( ) . captures ( bn) ? ;
112112 let filename = captures. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
113113 let testname = captures. get ( 2 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
114114
115- format ! ( "{}.{}" , filename, testname)
115+ Some ( format ! ( "{}.{}" , filename, testname) )
116116}
117117
118118impl MarketsNetwork {
@@ -122,19 +122,35 @@ impl MarketsNetwork {
122122 pub async fn new ( test_name : Option < & str > ) -> Self {
123123 std:: env:: set_var ( "RUST_LOG" , "debug" ) ;
124124 let _ = env_logger:: builder ( ) . try_init ( ) ;
125- // level 1 is this function.
126- // level 2 is <core::future::from_generator::GenFuture<T> as
127- // core::future::future::Future>::poll::XXX> (async)
128- // We want to know the caller.
129- let mut bn = crate :: testing:: backtrace_util:: generate_backtraced_name ( Some ( 3 ) ) ;
130- // Special case for mac&windows. Tests are run in adifferent way on those systems and we
131- // have to dive one less level down the stack to find the caller (test_* module).
132- if !bn. starts_with ( "test_" ) {
133- bn = crate :: testing:: backtrace_util:: generate_backtraced_name ( Some ( 2 ) ) ;
134- }
135- bn = testname_from_backtrace ( & bn) ;
136125
137- let test_name = test_name. unwrap_or ( & bn) . to_string ( ) ;
126+ let test_name_from_bt = || {
127+ // level 1 is this function.
128+ // level 2 is <core::future::from_generator::GenFuture<T> as
129+ // core::future::future::Future>::poll::XXX> (async)
130+ // We want to know the caller.
131+ crate :: testing:: backtrace_util:: generate_backtraced_name ( Some ( 3 ) )
132+ . and_then ( |name| {
133+ // Special case for mac&windows. Tests are run in adifferent way on those systems and we
134+ // have to dive one less level down the stack to find the caller (test_* module).
135+ if !name. starts_with ( "test_" ) {
136+ crate :: testing:: backtrace_util:: generate_backtraced_name ( Some ( 2 ) )
137+ } else {
138+ Some ( name)
139+ }
140+ } )
141+ . as_deref ( )
142+ . and_then ( testname_from_backtrace)
143+ } ;
144+
145+ let unknown_test_name = || {
146+ let nonce = rand:: random :: < u128 > ( ) ;
147+ format ! ( "unknown-test-{:#32x}" , nonce)
148+ } ;
149+
150+ let test_name = test_name
151+ . map ( String :: from)
152+ . or_else ( test_name_from_bt)
153+ . unwrap_or_else ( unknown_test_name) ;
138154 log:: info!( "Intializing MarketsNetwork. tn={}" , test_name) ;
139155
140156 MockNet :: default ( ) . bind_gsb ( ) ;
0 commit comments