2 # Copyright (C) 2001-2010, Parrot Foundation.
7 use lib qw( t . lib ../lib ../../lib );
10 use Parrot::Test tests => 2;
14 t/library/pcre.t - testing library/pcre.pir
18 % prove t/library/pcre.t
22 This program tests whether the 'pcre.pir' library accesses
23 the installed PCRE library, and matches patterns successfully.
27 # if we keep pcre, we need a config test
28 my $cmd = ( $^O =~ /MSWin32/ ) ? "pcregrep --version" : "pcre-config --version";
29 my $has_pcre = !Parrot::Test::run_command( $cmd, STDOUT => File::Spec->devnull ,STDERR => File::Spec->devnull, );
30 my $pcre_libpath = '';
32 # It's possible that libpcre is installed in some non-standard path...
33 if ($has_pcre && ($^O !~ /MSWin32/)) {
34 # Extract the library path for non-windows platforms (in case it isn't in
35 # the normal lookup locations)
36 my $outfile = 'pcre-config.out';
37 Parrot::Test::run_command('pcre-config --prefix', STDOUT => $outfile);
38 my $out = Parrot::Test::slurp_file($outfile);
41 $pcre_libpath = "$out/lib";
45 skip( 'no pcre-config', Test::Builder->new()->expected_tests() )
49 ## Check that the library can be loaded and initialized,
50 ## diganose the failure otherwise.
51 pir_output_is(<<"CODE", <<'OUT', 'libpcre loading');
53 .include 'iglobals.pasm'
54 .include 'libpaths.pasm'
61 lib_paths = interp[.IGLOBALS_LIB_PATHS]
63 .local pmc dynext_path
64 dynext_path = lib_paths[.PARROT_LIB_PATH_DYNEXT]
65 unshift dynext_path, '$pcre_libpath'
67 load_bytecode 'pcre.pbc'
71 get_global pcre_init, ['PCRE'], 'init'
72 if null pcre_init goto NOINIT
74 pcre_lib = pcre_init()
76 if null pcre_lib goto NULLINIT
77 unless pcre_lib goto FALSEINIT
82 .get_results(exception)
84 message = exception['message']
89 say 'No init function'
92 say 'init returned null value'
95 say 'init returned false value'
105 @todo = ( todo => '3..5 fail on Win32' ) if $^O =~ /MSWin32/;
106 pir_output_is( <<"CODE", <<'OUT', 'soup to nuts', @todo );
108 .include 'iglobals.pasm'
109 .include 'libpaths.pasm'
116 lib_paths = interp[.IGLOBALS_LIB_PATHS]
118 .local pmc dynext_path
119 dynext_path = lib_paths[.PARROT_LIB_PATH_DYNEXT]
120 unshift dynext_path, '$pcre_libpath'
122 load_bytecode 'pcre.pbc'
126 get_global func, ['PCRE'], 'init'
153 func= get_global ['PCRE'], 'compile'
154 ( code, error, errptr )= func( pat, 0 )
156 .local int is_code_defined
157 is_code_defined= defined code
158 if is_code_defined goto OK3
166 func= get_global ['PCRE'], 'match'
167 ( ok, result )= func( code, s, 0, 0 )
169 unless ok < 0 goto OK4
178 func = get_global ['PCRE'], 'dollar'
179 match = func( s, ok, result, i )
180 if 'a' == match goto OK5
198 # cperl-indent-level: 4
201 # vim: expandtab shiftwidth=4: