File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,19 @@ async fn test_async_function_wrap() -> Result<()> {
4848 let res: String = lua. load ( r#"f("hello")"# ) . eval_async ( ) . await ?;
4949 assert_eq ! ( res, "hello" ) ;
5050
51+ // Return error
52+ let ferr = Function :: wrap_async ( || async move { Err :: < ( ) , _ > ( Error :: runtime ( "some async error" ) ) } ) ;
53+ lua. globals ( ) . set ( "ferr" , ferr) ?;
54+ lua. load (
55+ r#"
56+ local ok, err = pcall(ferr)
57+ assert(not ok and tostring(err):find("some async error"))
58+ "# ,
59+ )
60+ . exec_async ( )
61+ . await
62+ . unwrap ( ) ;
63+
5164 Ok ( ( ) )
5265}
5366
@@ -376,6 +389,13 @@ async fn test_async_table_object_like() -> Result<()> {
376389 table. set_metatable ( Some ( metatable) ) ;
377390 assert_eq ! ( table. call_async:: <i64 >( ( ) ) . await . unwrap( ) , 15 ) ;
378391
392+ match table. call_async_method :: < ( ) > ( "non_existent" , ( ) ) . await {
393+ Err ( Error :: RuntimeError ( err) ) => {
394+ assert ! ( err. contains( "attempt to call a nil value (function 'non_existent')" ) )
395+ }
396+ r => panic ! ( "expected RuntimeError, got {r:?}" ) ,
397+ }
398+
379399 Ok ( ( ) )
380400}
381401
You can’t perform that action at this time.
0 commit comments