Alien-Role-Dino

 view release on metacpan or  search on metacpan

t/alien_role_dino.t  view on Meta::CPAN


    subtest 'use xs' => sub {

      xs_ok { xs => $xs, verbose => 1 }, with_subtest {
        my($mod) = @_;
        is($mod->is_palindrome("Something that is not a palindrome"), 0);
        is($mod->is_palindrome("Was it a car or a cat I saw?"), 1);
      };
    };

    subtest 'use ffi' => sub {

      ffi_ok { symbols => ['is_palindrome'] }, with_subtest {
        my ($ffi) = @_;
  
        my $is_palindrome = $ffi->function(is_palindrome => ['string'] => 'int');
  
        is($is_palindrome->("Something that is not a palindrome"), 0);
        is($is_palindrome->("Was it a car or a cat I saw?"), 1);
      };
    };

    subtest 'use exe' => sub {

      local $ENV{PATH} = $ENV{PATH};

      unshift @PATH, $alien->bin_dir;

      run_ok(['palx', 'Something that is not a palindrome'])
        ->note
        ->exit_is(2);

      run_ok(['palx', 'Was it a car or a cat I saw?'])
        ->note
        ->success;

      run_ok(['palx', 'racecar'])
        ->note
        ->success;

    };
  }
}

done_testing

__DATA__
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <libpalindrome.h>

MODULE = TA_MODULE PACKAGE = TA_MODULE

int
is_palindrome(klass, word)
    const char *klass
    const char *word
  CODE:
    RETVAL = is_palindrome(word);
  OUTPUT:
    RETVAL



( run in 0.822 second using v1.01-cache-2.11-cpan-13bb782fe5a )