@@ -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 => 45 ;
10+ plan tests => 48 ;
1111
1212# ...
1313ok(Extism::version());
@@ -213,3 +213,30 @@ eval {
213213ok($@ );
214214ok($@ -> {code } != 0);
215215ok($@ -> {message });
216+
217+ # Test host_context
218+ {
219+ my $voidfunction = Extism::Function-> new(" hello_void" , [], [], sub {
220+ ok(! defined Extism::CurrentPlugin::host_context);
221+ return ;
222+ });
223+ my $paramsfunction = Extism::Function-> new(" hello_params" , [Extism_F64, Extism_I32, Extism_F32, Extism_I64], [Extism_I64], sub {
224+ # not called
225+ });
226+ my $fplugin = Extism::Plugin-> new($hostwasm , {functions => [$voidfunction , $paramsfunction ], wasi => 1});
227+ $fplugin -> call(' call_hello_void' );
228+ }
229+ {
230+ my %context = ( abc => 123);
231+ my $voidfunction = Extism::Function-> new(" hello_void" , [], [], sub {
232+ my $ctx = Extism::CurrentPlugin::host_context;
233+ is_deeply($ctx , \%context );
234+ ok($ctx == \%context );
235+ return ;
236+ });
237+ my $paramsfunction = Extism::Function-> new(" hello_params" , [Extism_F64, Extism_I32, Extism_F32, Extism_I64], [Extism_I64], sub {
238+ # not called
239+ });
240+ my $fplugin = Extism::Plugin-> new($hostwasm , {functions => [$voidfunction , $paramsfunction ], wasi => 1});
241+ $fplugin -> call(' call_hello_void' , ' ' , \%context );
242+ }
0 commit comments