How do you test code that uses FFI::Platypus?

FFI::Platypus makes it easy to call C functions from Perl. Testing your code that involves FFI can be tricky due to the dependencies on external libraries. This guide provides an example of how to create and test a Perl program using FFI::Platypus.
FFI::Platypus, Perl testing, FFI testing, calling C from Perl, Perl programming
#!/usr/bin/env perl use strict; use warnings; use FFI::Platypus; my $ffi = FFI::Platypus->new( api => 1 ); # Load a C library, for example, the math library $ffi->lib('libm.so'); # Declare a C function to call $ffi->attach( cos => 'cos' => 'double' => 'double' ); # Test our attachment by calling cos my $angle = 0; # angle in radians my $result = cos($angle); print "The cosine of $angle is $result\n"; # You can incorporate tests using Test::More use Test::More; is(cos(0), 1, 'cos(0) should be 1'); is(cos(pi/2), 0, 'cos(pi/2) should be 0'); done_testing();

FFI::Platypus Perl testing FFI testing calling C from Perl Perl programming