| | 1 | #! perl |
| | 2 | # Copyright (C) 2009, The Perl Foundation. |
| | 3 | # $Id$ |
| | 4 | |
| | 5 | use strict; |
| | 6 | use warnings; |
| | 7 | use lib qw( . lib ../lib ../../lib ); |
| | 8 | use Test::More; |
| | 9 | use Parrot::Test; |
| | 10 | use Parrot::Config; |
| | 11 | |
| | 12 | plan tests => 3; |
| | 13 | |
| | 14 | =head1 NAME |
| | 15 | |
| | 16 | t/src/library.t - Library search functions |
| | 17 | |
| | 18 | =head1 SYNOPSIS |
| | 19 | |
| | 20 | % prove t/src/library.t |
| | 21 | |
| | 22 | =head1 DESCRIPTION |
| | 23 | |
| | 24 | Test some library search functionality for load_bytecode and .include. |
| | 25 | The library search path, directories versus missing extensions, finding files |
| | 26 | without extensions. |
| | 27 | |
| | 28 | TT#123 remove more hard-coded runtime/ paths from libs |
| | 29 | TT#126 optimize load_bytecode, .include paths: no library/ and include/ prefix |
| | 30 | TT#127 do not stat extensions when an extension was already given. |
| | 31 | If the given string is a directory, do not fail, try the extensions instead. |
| | 32 | e.g. load_bytecode 'Test/Builder' |
| | 33 | TT#128 [TODO] Honor source filetype when a .pbc is present |
| | 34 | |
| | 35 | We test this seperately, because core has another load_bytecode failure RT #39807, |
| | 36 | tested in t/op/load_bytecode.t |
| | 37 | |
| | 38 | =cut |
| | 39 | |
| | 40 | c_output_is( <<'CODE', <<'OUTPUT', "Parrot_locate_runtime_file" ); |
| | 41 | |
| | 42 | #include <parrot/parrot.h> |
| | 43 | #include <parrot/embed.h> |
| | 44 | |
| | 45 | int |
| | 46 | main(int argc, char* argv[]) |
| | 47 | { |
| | 48 | Interp *interp; |
| | 49 | int error_val; |
| | 50 | char *path; |
| | 51 | |
| | 52 | interp = Parrot_new(NULL); |
| | 53 | if (!interp) { |
| | 54 | return 1; |
| | 55 | } |
| | 56 | path = Parrot_locate_runtime_file(interp, "Data/Dumper.pir", PARROT_RUNTIME_FT_SOURCE); |
| | 57 | printf("%s\n", path); |
| | 58 | if (path) free(path); |
| | 59 | path = Parrot_locate_runtime_file(interp, "Data/Dumper.pbc", PARROT_RUNTIME_FT_PBC); |
| | 60 | printf("%s\n", path); |
| | 61 | if (path) free(path); |
| | 62 | path = Parrot_locate_runtime_file(interp, "Data/Dumper", PARROT_RUNTIME_FT_PBC); |
| | 63 | printf("%s\n", path); |
| | 64 | if (path) free(path); |
| | 65 | path = Parrot_locate_runtime_file(interp, "Data/Dumper.pir", PARROT_RUNTIME_FT_INCLUDE); |
| | 66 | printf("%s\n", path); |
| | 67 | if (path) free(path); |
| | 68 | path = Parrot_locate_runtime_file(interp, "library/Data/Dumper.pir", PARROT_RUNTIME_FT_INCLUDE); |
| | 69 | printf("%s\n", path); |
| | 70 | if (path) free(path); |
| | 71 | |
| | 72 | Parrot_exit(interp, 0); |
| | 73 | return 0; |
| | 74 | } |
| | 75 | CODE |
| | 76 | ./runtime/parrot/library/Data/Dumper.pir |
| | 77 | ./runtime/parrot/library/Data/Dumper.pbc |
| | 78 | ./runtime/parrot/library/Data/Dumper.pbc |
| | 79 | (null) |
| | 80 | ./runtime/parrot/library/Data/Dumper.pir |
| | 81 | OUTPUT |
| | 82 | |
| | 83 | my $dynpath = "." . $PConfig{slash} . |
| | 84 | File::Spec->catfile("runtime","parrot","dynext","myops_ops") |
| | 85 | . $PConfig{load_ext}; |
| | 86 | c_output_is( <<'CODE', <<"OUTPUT", "FT_DYNEXT" ); |
| | 87 | |
| | 88 | #include <parrot/parrot.h> |
| | 89 | #include <parrot/embed.h> |
| | 90 | |
| | 91 | int |
| | 92 | main(int argc, char* argv[]) |
| | 93 | { |
| | 94 | Interp *interp; |
| | 95 | char *path; |
| | 96 | STRING *result, *full_name, *wo_ext; |
| | 97 | INTVAL i, n; |
| | 98 | |
| | 99 | interp = Parrot_new(NULL); |
| | 100 | if (!interp) { |
| | 101 | return 1; |
| | 102 | } |
| | 103 | |
| | 104 | wo_ext = const_string(interp, "myops_ops"); |
| | 105 | full_name = string_concat(interp, wo_ext, const_string(interp, PARROT_LOAD_EXT), 0); |
| | 106 | result = Parrot_locate_runtime_file_str(interp, full_name, |
| | 107 | PARROT_RUNTIME_FT_DYNEXT); |
| | 108 | if (result) { |
| | 109 | printf("%s\n", result->strstart); |
| | 110 | } |
| | 111 | else { |
| | 112 | if (!STREQ(PARROT_LOAD_EXT, PARROT_SHARE_EXT)) { |
| | 113 | full_name = string_concat(interp, wo_ext, const_string(interp, PARROT_SHARE_EXT), 0); |
| | 114 | result = Parrot_locate_runtime_file_str(interp, full_name, |
| | 115 | PARROT_RUNTIME_FT_DYNEXT); |
| | 116 | } |
| | 117 | printf("%s\n", result->strstart); |
| | 118 | } |
| | 119 | |
| | 120 | path = Parrot_locate_runtime_file(interp, "not_existing_op", PARROT_RUNTIME_FT_INCLUDE); |
| | 121 | printf("%s\n", path); |
| | 122 | if (path) free(path); |
| | 123 | |
| | 124 | Parrot_exit(interp, 0); |
| | 125 | return 0; |
| | 126 | } |
| | 127 | CODE |
| | 128 | $dynpath |
| | 129 | (null) |
| | 130 | OUTPUT |
| | 131 | |
| | 132 | c_output_is( <<'CODE', <<'OUTPUT', "FT_SOURCE, FT_PIR", 'todo' => 'TT #128 force pir') |
| | 133 | |
| | 134 | #include <parrot/parrot.h> |
| | 135 | #include <parrot/embed.h> |
| | 136 | |
| | 137 | int |
| | 138 | main(int argc, char* argv[]) |
| | 139 | { |
| | 140 | Interp *interp; |
| | 141 | int error_val; |
| | 142 | char *path; |
| | 143 | |
| | 144 | interp = Parrot_new(NULL); |
| | 145 | if (!interp) { |
| | 146 | return 1; |
| | 147 | } |
| | 148 | |
| | 149 | path = Parrot_locate_runtime_file(interp, "Data/Dumper", PARROT_RUNTIME_FT_SOURCE); |
| | 150 | printf("%s\n", path); |
| | 151 | if (path) free(path); |
| | 152 | path = Parrot_locate_runtime_file(interp, "Data/Dumper", PARROT_RUNTIME_FT_PIR); |
| | 153 | printf("%s\n", path); |
| | 154 | if (path) free(path); |
| | 155 | |
| | 156 | Parrot_exit(interp, 0); |
| | 157 | return 0; |
| | 158 | } |
| | 159 | CODE |
| | 160 | ./runtime/parrot/library/Data/Dumper.pir |
| | 161 | ./runtime/parrot/library/Data/Dumper.pir |
| | 162 | OUTPUT |
| | 163 | |
| | 164 | |
| | 165 | # Local Variables: |
| | 166 | # mode: cperl |
| | 167 | # cperl-indent-level: 4 |
| | 168 | # fill-column: 100 |
| | 169 | # End: |
| | 170 | # vim: expandtab shiftwidth=4: |