This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
abstract code for C<use Foo 1.23 @ary;> into a Perl_load_module()
[perl5.git] / t / comp / require.t
CommitLineData
f46d017c
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
93430cb4 5 unshift @INC, ('.', '../lib');
f46d017c
GS
6}
7
8# don't make this lexical
9$i = 1;
dbe7b177 10print "1..19\n";
f46d017c
GS
11
12sub do_require {
13 %INC = ();
4a9ae47a 14 write_file('bleah.pm',@_);
f46d017c
GS
15 eval { require "bleah.pm" };
16 my @a; # magic guard for scope violations (must be first lexical in file)
17}
18
4a9ae47a
GS
19sub write_file {
20 my $f = shift;
21 open(REQ,">$f") or die "Can't write '$f': $!";
22 print REQ @_;
23 close REQ;
24}
25
9f3d182e
GS
26eval {require 5.005};
27print "# $@\nnot " if $@;
28print "ok ",$i++,"\n";
29
30eval { require 5.005 };
31print "# $@\nnot " if $@;
32print "ok ",$i++,"\n";
33
34eval { require 5.005; };
35print "# $@\nnot " if $@;
36print "ok ",$i++,"\n";
37
38eval {
39 require 5.005
40};
41print "# $@\nnot " if $@;
42print "ok ",$i++,"\n";
43
a7cb1f99
GS
44# new style version numbers
45
46eval { require v5.5.630; };
47print "# $@\nnot " if $@;
48print "ok ",$i++,"\n";
49
dd629d5b 50eval { require 10.0.2; };
a7cb1f99
GS
51print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
52print "ok ",$i++,"\n";
53
54eval q{ use v5.5.630; };
55print "# $@\nnot " if $@;
56print "ok ",$i++,"\n";
57
dd629d5b 58eval q{ use 10.0.2; };
a7cb1f99
GS
59print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.2 required/;
60print "ok ",$i++,"\n";
61
44dcb63b 62my $ver = 5.005_63;
a7cb1f99
GS
63eval { require $ver; };
64print "# $@\nnot " if $@;
65print "ok ",$i++,"\n";
66
44dcb63b 67# check inaccurate fp
dbe7b177
GS
68$ver = 10.2;
69eval { require $ver; };
70print "# $@\nnot " unless $@ =~ /^Perl v10\.200\.0 required/;
71print "ok ",$i++,"\n";
44dcb63b
GS
72
73$ver = 10.000_02;
a7cb1f99 74eval { require $ver; };
44dcb63b 75print "# $@\nnot " unless $@ =~ /^Perl v10\.0\.20 required/;
a7cb1f99
GS
76print "ok ",$i++,"\n";
77
dd629d5b 78print "not " unless 5.5.1 gt v5.5;
a7cb1f99
GS
79print "ok ",$i++,"\n";
80
a7cb1f99
GS
81{
82 use utf8;
83 print "not " unless v5.5.640 eq "\x{5}\x{5}\x{280}";
84 print "ok ",$i++,"\n";
85
86 print "not " unless v7.15 eq "\x{7}\x{f}";
87 print "ok ",$i++,"\n";
88
89 print "not "
90 unless v1.20.300.4000.50000.600000 eq "\x{1}\x{14}\x{12c}\x{fa0}\x{c350}\x{927c0}";
91 print "ok ",$i++,"\n";
92}
93
4a9ae47a
GS
94# interaction with pod (see the eof)
95write_file('bleah.pm', "print 'ok $i\n'; 1;\n");
96require "bleah.pm";
97$i++;
98
f46d017c
GS
99# run-time failure in require
100do_require "0;\n";
101print "# $@\nnot " unless $@ =~ /did not return a true/;
102print "ok ",$i++,"\n";
103
104# compile-time failure in require
105do_require "1)\n";
f0ec1f9a 106# bison says 'parse error' instead of 'syntax error',
d91e2bdb 107# various yaccs may or may not capitalize 'syntax'.
f0ec1f9a 108print "# $@\nnot " unless $@ =~ /(syntax|parse) error/mi;
f46d017c
GS
109print "ok ",$i++,"\n";
110
111# successful require
112do_require "1";
113print "# $@\nnot " if $@;
114print "ok ",$i++,"\n";
115
562a7b0c 116END { 1 while unlink 'bleah.pm'; }
4a9ae47a
GS
117
118# ***interaction with pod (don't put any thing after here)***
119
120=pod