vendredi 29 novembre 2019

Test failing when executed in a different order

When I execute this program:

use Test;
use NativeCall;

constant LIB  = ('gsl', v23);

sub gsl_sf_airy_Ai(num64 $x, uint32 $mode --> num64) is native(LIB) is export { * }
sub Ai(Numeric $x, UInt $mode --> Num) is export { gsl_sf_airy_Ai($x.Num, $mode) }

ok Ai(0, 0) == 0.3550280538878172, 'Ai 1';
ok gsl_sf_airy_Ai(0e0, 0) == 0.3550280538878172, 'Ai 2';

the tests work fine, even if I swap the two "ok" tests this way:

ok gsl_sf_airy_Ai(0e0, 0) == 0.3550280538878172, 'Ai 2';
ok Ai(0, 0) == 0.3550280538878172, 'Ai 1';

If I move the declarations to a module:

unit module mymodule;
use NativeCall;

constant LIB  = ('gsl', v23);

sub gsl_sf_airy_Ai(num64 $x, uint32 $mode --> num64) is native(LIB) is export { * }
sub Ai(Numeric $x, UInt $mode --> Num) is export { gsl_sf_airy_Ai($x.Num, $mode) }

and write a test program:

use Test;
use lib '.';
use mymodule;

ok Ai(0, 0) == 0.3550280538878172, 'Ai 1';
ok gsl_sf_airy_Ai(0e0, 0) == 0.3550280538878172, 'Ai 2';

again the two tests are executed without errors, but if I swap the last two lines:

ok gsl_sf_airy_Ai(0e0, 0) == 0.3550280538878172, 'Ai 2';
ok Ai(0, 0) == 0.3550280538878172, 'Ai 1';

I get this error: Type check failed for return value; expected Num but got Whatever (*) and I don't understand why. I even suspected a possible memory corruption, so I executed the test program using valgrind, but apparently there's nothing wrong in that department. Any hint?

Aucun commentaire:

Enregistrer un commentaire