@@ -7,7 +7,7 @@ use Extism ':all';
77use JSON::PP qw( encode_json decode_json) ;
88use File::Temp qw( tempfile) ;
99use Devel::Peek qw( Dump) ;
10- plan tests => 44 ;
10+ plan tests => 45 ;
1111
1212# ...
1313ok(Extism::version());
@@ -23,7 +23,10 @@ ok(Extism::version());
2323 my $tempfunc = sub {
2424 $log_text .= $_ [0];
2525 };
26- Extism::Plugin-> new(' ' );
26+ eval {
27+ Extism::Plugin-> new(' ' );
28+ fail(' Extism::Plugin->new("") should throw an exception' );
29+ };
2730 Extism::log_drain($tempfunc );
2831 $log_text or $rc = 1;
2932 POSIX::_exit($rc );
@@ -33,16 +36,12 @@ ok(Extism::version());
3336 }
3437}
3538
36- # test failing plugin new in scalar and list context
37- {
39+ # test failing plugin throws an exception
40+ eval {
3841 my $notplugin = Extism::Plugin-> new(' ' );
39- ok(!defined $notplugin );
40- }
41- {
42- my ($notplugin , $error ) = Extism::Plugin-> new(' ' );
43- ok(!defined $notplugin );
44- ok($error );
45- }
42+ fail(' Extism::Plugin->new("") should throw an exception' );
43+ };
44+ ok($@ );
4645
4746# test succeeding plugin new in scalar and list context
4847# also text various Plugin:: functions
@@ -65,7 +64,7 @@ my $wasm = do { local(@ARGV, $/) = 'count_vowels.wasm'; <> };
6564 ok($plugin -> reset ());
6665}
6766{
68- my ( $plugin , $error ) = Extism::Plugin-> new($wasm , {wasi => 1});
67+ my $plugin = Extism::Plugin-> new($wasm , {wasi => 1});
6968 ok($plugin );
7069 my ($output ) = $plugin -> call(' count_vowels' , " this is a test" );
7170 ok($output );
@@ -79,18 +78,31 @@ my $wasm = do { local(@ARGV, $/) = 'count_vowels.wasm'; <> };
7978 Extism::log_file($filename , " error" );
8079 my $failwasm = do { local (@ARGV , $/ ) = ' fail.wasm' ; <> };
8180 my $failplugin = Extism::Plugin-> new($failwasm , {wasi => 1});
82- my $failed = $failplugin -> call(' run_test' , " " );
83- ok(!$failed );
81+ eval {
82+ my $failed = $failplugin -> call(' run_test' , " " );
83+ fail(' calling run_test in failplugin should throw an exception' );
84+ };
85+ ok($@ );
8486 my $rc = read ($error_fh , my $filler , 1);
8587 ok($rc == 1);
8688 unlink ($filename );
8789 Extism::log_file(" /dev/stdout" , " error" );
88- my ($res , $rca , $info ) = $failplugin -> call(' run_test' , " " );
89- ok($rca == 1);
90- is($info , ' Some error message' );
90+ eval {
91+ $failplugin -> call(' run_test' , " " );
92+ fail(' calling run_test in failplugin should throw an exception' );
93+ };
94+ ok($@ );
95+ ok($@ -> {code } == 1);
96+ is($@ -> {message }, ' Some error message' );
9197}
9298
9399# test basic host functions
100+ eval {
101+ my $badname = Extism::Function-> new(" \x{D800} " , [], [], sub {});
102+ fail(' Function->new should throw an exception when an invalid name is passed' );
103+ };
104+ ok($@ );
105+
94106my $voidfunction = Extism::Function-> new(" hello_void" , [], [], sub {
95107 print " hello_void\n " ;
96108 return ;
@@ -101,6 +113,9 @@ my $paramsfunction = Extism::Function->new("hello_params", [Extism_F64, Extism_I
101113 return 18446744073709551615;
102114});
103115ok($paramsfunction );
116+ my $withnamespace = Extism::Function-> new(" with_namespace" , [], [], sub {
117+ }, ' namespace' );
118+ ok($withnamespace );
104119my $hostwasm = do { local (@ARGV , $/ ) = ' host.wasm' ; <> };
105120my $fplugin = Extism::Plugin-> new($hostwasm , {functions => [$voidfunction , $paramsfunction ], wasi => 1});
106121ok($fplugin );
@@ -191,7 +206,10 @@ my $unreachable = encode_json({
191206});
192207my $uplugin = Extism::Plugin-> new($unreachable , {wasi => 1});
193208ok($uplugin );
194- my ($ures , $urc , $uinfo ) = $uplugin -> call(' do_unreachable' );
195- ok(!defined $ures );
196- ok($urc != 0);
197- ok($uinfo );
209+ eval {
210+ $uplugin -> call(' do_unreachable' );
211+ fail(' calling do_unreachable should throw an exception' );
212+ };
213+ ok($@ );
214+ ok($@ -> {code } != 0);
215+ ok($@ -> {message });
0 commit comments