Skip to content

Commit

Permalink
[t][GH #368] Test library search paths
Browse files Browse the repository at this point in the history
Currently tests 1-4 fails because of duplicates.
Only works on slash eq "/"
  • Loading branch information
Reini Urban committed Dec 26, 2012
1 parent cec9d24 commit bf28913
Showing 1 changed file with 111 additions and 23 deletions.
134 changes: 111 additions & 23 deletions t/library/lib_search_path.t
@@ -1,45 +1,133 @@
#!./parrot
# Copyright (C) 2011 Parrot Foundation.
#!perl
# Copyright (C) 2012 Parrot Foundation.

use strict;
use warnings;
use lib qw(lib);

use Test::More;
use Parrot::Config;
use Parrot::Test;
if ($PConfig{slash} eq '/') {
plan tests => 5;
} else {
die "0..0 #SKIP $^O not yet supported\n";
}

=head1 NAME
t/library/lib_search_path.t - testing for proper search path precedence
t/library/lib_search_path.t - test proper library search path precedence
=head1 SYNOPSIS
This test program verifies that Parrot searches for libraries in the
This test program verifies that Parrot searches for code in the
proper order.
=head1 AUTHOR
.include, loadlib, load_bytecode, languages
Kevin Polulak (a.k.a. soh_cah_toa) kpolulak@gmail.com
=head1 DESCRIPTION
=cut
Check for proper loadlib libpath order.
if parrot is installed:
.const int TESTS = 3
$PARROT_LIBRARY
dynext/
$prefix/parrot/$ver/dynext/
.sub 'main' :main
.include 'test_more.pir'
if not installed:
.local pmc lib
$PARROT_LIBRARY
dynext/
$build_dir/runtime/parrot/dynext
plan(TESTS)
no duplicates
# Verify current working directory isn't searched
lib = loadlib 'lib_search_path.t'
is(lib, '', 'Verify current working directory not searched')
. at end (not for DYNEXT)
lib = loadlib 'dont_load_me.pir'
is(lib, '', 'Verify current working directory not searched')
=cut

# Verify runtime/parrot/dynext is searched
lib = loadlib 'osutils.pir'
isnt(lib, '', 'Verify runtime/parrot/dynext is searched')
local $ENV{PARROT_LIBRARY} = 'libenvdir';
local $ENV{PARROT_INCLUDE} = 'incenvdir';

my ($builddir, $versiondir, $prefix) = @PConfig{qw(build_dir versiondir prefix)};
my $what = 'DYNEXT';
my $code = <<"CODE";
.include 'iglobals.pasm'
.include 'libpaths.pasm'
.sub main :main
.local pmc interp
getinterp interp
.local pmc lib_paths
lib_paths = interp[.IGLOBALS_LIB_PATHS]
.local pmc path
path = lib_paths[.PARROT_LIB_PATH_$what]
.local pmc p
.local int i, size
size = path
i = 0
while_1:
p = path[i]
say p
i = i + 1
if i < size goto while_1
.end
CODE

my $dynext = Parrot::Test::_pir_stdin_output_slurp('', $code);
my $expected =
"dynext/
$builddir/runtime/parrot/dynext/
$prefix$versiondir/dynext/
";
is ($dynext, $expected, "dynext");

my $library = $code;
$library =~ s/DYNEXT/LIBRARY/;
$library = Parrot::Test::_pir_stdin_output_slurp('', $library);
$expected =
"libenvdir
$builddir/runtime/parrot/library/
$prefix$versiondir/library/
./
";
is ($library, $expected, "library");

my $include = $code;
$include =~ s/DYNEXT/INCLUDE/;
$include = Parrot::Test::_pir_stdin_output_slurp('', $include);
$expected =
"incenvdir
$builddir/
$builddir/runtime/parrot/include/
$prefix$versiondir/include/
./
";
is ($include, $expected, "include");

my $lang = $code;
$lang =~ s/DYNEXT/LANG/;
$lang = Parrot::Test::_pir_stdin_output_slurp('', $lang);
$expected =
"$builddir/runtime/parrot/languages/
$prefix$versiondir/languages/
./
";
is ($lang, $expected, "lang");


pir_output_is( <<'CODE', <<'OUTPUT', ". at end of dynext search path" );
.sub main :main
load_bytecode 't/pir/testlib/loadtest.pbc'
.end
CODE
loaded
OUTPUT

# Local Variables:
# mode: pir
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:

# vim: expandtab shiftwidth=4:

0 comments on commit bf28913

Please sign in to comment.