@@ -12,6 +12,21 @@ use crate::{
1212} ;
1313use test_log:: test;
1414
15+ macro_rules! test {
16+ (
17+ $( #[ $attr: meta] ) *
18+ async fn $name: ident ( ) $( -> $ret: ty) ? $body: block
19+ ) => {
20+ $( #[ $attr] ) *
21+ #[ test]
22+ fn $name( ) $( -> $ret) ? {
23+ async_io:: block_on( async {
24+ $body
25+ } )
26+ }
27+ }
28+ }
29+
1530pub const TEST_APPID : AppID = AppID ( std:: borrow:: Cow :: Borrowed (
1631 "magic-wormhole.github.io/magic-wormhole.rs/test" ,
1732) ) ;
@@ -30,7 +45,7 @@ const TIMEOUT: Duration = Duration::from_secs(60);
3045///
3146/// ```no_run
3247/// use magic_wormhole as mw;
33- /// # smol ::block_on(async {
48+ /// # async_io ::block_on(async {
3449/// # let derived_key = unimplemented!();
3550/// # let their_abilities = unimplemented!();
3651/// # let their_hints = unimplemented!();
@@ -53,7 +68,7 @@ fn default_relay_hints() -> Vec<transit::RelayHint> {
5368 ]
5469}
5570
56- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
71+ #[ test( macro_rules_attribute:: apply( test!) ) ]
5772#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
5873async fn test_connect_with_unknown_code_and_allocate_passes ( ) {
5974 let code = generate_random_code ( ) ;
@@ -70,7 +85,7 @@ async fn test_connect_with_unknown_code_and_allocate_passes() {
7085 . unwrap ( )
7186}
7287
73- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
88+ #[ test( macro_rules_attribute:: apply( test!) ) ]
7489#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
7590async fn test_connect_with_unknown_code_and_no_allocate_fails ( ) {
7691 tracing:: info!( "hola!" ) ;
@@ -117,7 +132,7 @@ async fn file_offers()
117132 move || {
118133 let data = data. clone ( ) ;
119134 Box :: pin ( async move {
120- Ok ( Box :: new ( smol :: io :: Cursor :: new ( data) )
135+ Ok ( Box :: new ( async_io :: Cursor :: new ( data) )
121136 as Box <
122137 dyn crate :: transfer:: offer:: AsyncReadSeek
123138 + std:: marker:: Send
@@ -134,7 +149,7 @@ async fn file_offers()
134149 #[ cfg( not( target_family = "wasm" ) ) ]
135150 let ( data, offer) = {
136151 let path = format ! ( "tests/{name}" ) ;
137- let data = smol :: fs :: read ( & path) . await . unwrap ( ) ;
152+ let data = async_fs :: read ( & path) . await . unwrap ( ) ;
138153 let offer = transfer:: offer:: OfferSend :: new_file_or_folder ( name. into ( ) , & path)
139154 . await
140155 . unwrap ( ) ;
@@ -227,7 +242,7 @@ async fn file_offers()
227242
228243/** Send a file using the Rust implementation. This does not guarantee compatibility with Python! ;) */
229244#[ cfg( feature = "transfer" ) ]
230- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
245+ #[ test( macro_rules_attribute:: apply( test!) ) ]
231246// TODO Wasm test disabled, it crashes
232247// #[cfg_attr(target_arch = "wasm32", test(wasm_bindgen_test::wasm_bindgen_test))]
233248async fn test_file_rust2rust ( ) {
@@ -307,7 +322,7 @@ async fn test_file_rust2rust() {
307322/** Test the functionality used by the `send-many` subcommand.
308323 */
309324#[ cfg( feature = "transfer" ) ]
310- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
325+ #[ test( macro_rules_attribute:: apply( test!) ) ]
311326// TODO Wasm test disabled, it crashes
312327// #[cfg_attr(target_arch = "wasm32", test(wasm_bindgen_test::wasm_bindgen_test))]
313328async fn test_send_many ( ) {
@@ -327,15 +342,15 @@ async fn test_send_many() {
327342
328343 /* Send many */
329344 let sender_code = code. clone ( ) ;
330- let senders = smol :: spawn ( async move {
331- // let mut senders = Vec::<smol ::Task<std::result::Result<std::vec::Vec<u8>, eyre::Error>>>::new();
332- let mut senders: Vec < smol :: Task < eyre:: Result < ( ) > > > = Vec :: new ( ) ;
345+ let senders = crate :: util :: spawn ( async move {
346+ // let mut senders = Vec::<async_task ::Task<std::result::Result<std::vec::Vec<u8>, eyre::Error>>>::new();
347+ let mut senders: Vec < async_task :: Task < eyre:: Result < ( ) > > > = Vec :: new ( ) ;
333348
334349 /* The first time, we reuse the current session for sending */
335350 {
336351 tracing:: info!( "Sending file #{}" , 0 ) ;
337352 let wormhole = crate :: Wormhole :: connect ( mailbox) . await ?;
338- senders. push ( smol :: spawn ( async move {
353+ senders. push ( crate :: util :: spawn ( async move {
339354 eyre:: Result :: Ok (
340355 crate :: transfer:: send (
341356 wormhole,
@@ -362,7 +377,7 @@ async fn test_send_many() {
362377 . await ?,
363378 )
364379 . await ?;
365- senders. push ( smol :: spawn ( async move {
380+ senders. push ( crate :: util :: spawn ( async move {
366381 eyre:: Result :: Ok (
367382 crate :: transfer:: send (
368383 wormhole,
@@ -381,7 +396,7 @@ async fn test_send_many() {
381396 } ) ;
382397
383398 // Sleep one second
384- smol :: Timer :: after ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
399+ async_io :: Timer :: after ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
385400
386401 /* Receive many */
387402 for i in 0 ..5usize {
@@ -443,12 +458,12 @@ async fn test_send_many() {
443458}
444459
445460/// Try to send a file, but use a bad code, and see how it's handled
446- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
461+ #[ test( macro_rules_attribute:: apply( test!) ) ]
447462#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
448463async fn test_wrong_code ( ) {
449464 let ( code_tx, code_rx) = futures:: channel:: oneshot:: channel ( ) ;
450465
451- let sender_task = smol :: spawn ( async {
466+ let sender_task = crate :: util :: spawn ( async {
452467 let mailbox = MailboxConnection :: create ( APP_CONFIG , 2 ) . await . unwrap ( ) ;
453468 if let Some ( welcome) = & mailbox. welcome {
454469 tracing:: info!( "Got welcome: {}" , welcome) ;
@@ -463,7 +478,7 @@ async fn test_wrong_code() {
463478 eyre:: Result :: < _ > :: Ok ( ( ) )
464479 } ) ;
465480
466- let receiver_task = smol :: spawn ( async {
481+ let receiver_task = crate :: util :: spawn ( async {
467482 let nameplate = code_rx. await ?;
468483 tracing:: info!( "Got nameplate over local: {}" , & nameplate) ;
469484 let result = crate :: Wormhole :: connect (
@@ -488,7 +503,7 @@ async fn test_wrong_code() {
488503}
489504
490505/** Connect three people to the party and watch it explode … gracefully */
491- #[ test( macro_rules_attribute:: apply( smol_macros :: test!) ) ]
506+ #[ test( macro_rules_attribute:: apply( test!) ) ]
492507#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
493508async fn test_crowded ( ) {
494509 let initial_mailbox_connection = MailboxConnection :: create ( APP_CONFIG , 2 ) . await . unwrap ( ) ;
@@ -511,7 +526,7 @@ async fn test_crowded() {
511526 }
512527}
513528
514- #[ macro_rules_attribute:: apply( smol_macros :: test!) ]
529+ #[ macro_rules_attribute:: apply( test!) ]
515530#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
516531async fn test_connect_with_code_expecting_nameplate ( ) {
517532 let code = generate_random_code ( ) ;
0 commit comments