This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: t/op/ver.t using skip() improperly
[perl5.git] / t / op / ver.t
CommitLineData
3cb0bbe5
GS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
e83d50c9 6 $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN };
3cb0bbe5
GS
7}
8
e83d50c9 9$DOWARN = 1; # enable run-time warnings now
3cb0bbe5 10
e83d50c9
JP
11use Config;
12$tests = $Config{'uvsize'} == 8 ? 47 : 44;
3cb0bbe5 13
e83d50c9
JP
14require Test::More;
15Test::More->import( tests => $tests );
fd36d4b8 16
e83d50c9
JP
17eval { use v5.5.640; };
18is( $@, '', "use v5.5.640; $@");
fd36d4b8 19
e83d50c9 20require_ok('v5.5.640');
3cb0bbe5 21
e526c9e6 22# printing characters should work
7bd40e26 23if (ord("\t") == 9) { # ASCII
e83d50c9 24 is('ok ',v111.107.32,'ASCII printing characters');
7bd40e26
PP
25
26 # hash keys too
27 $h{v111.107} = "ok";
e83d50c9 28 is('ok',$h{v111.107},'ASCII hash keys');
7bd40e26
PP
29}
30else { # EBCDIC
e83d50c9 31 is('ok ',v150.146.64,'EBCDIC printing characters');
7bd40e26
PP
32
33 # hash keys too
34 $h{v150.146} = "ok";
e83d50c9 35 is('ok',$h{v111.107},'ASCII hash keys');
7bd40e26 36}
e526c9e6
GS
37
38# poetry optimization should also
39sub v77 { "ok" }
40$x = v77;
e83d50c9 41is('ok',$x,'poetry optimization');
e526c9e6
GS
42
43# but not when dots are involved
7bd40e26
PP
44if (ord("\t") == 9) { # ASCII
45 $x = v77.78.79;
46}
47else {
48 $x = v212.213.214;
49}
e83d50c9 50is($x, 'MNO','poetry optimization with dots');
e526c9e6 51
e83d50c9 52is(v1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}",'compare embedded \x{} string');
3cb0bbe5 53
dd629d5b
GS
54#
55# now do the same without the "v"
e83d50c9
JP
56eval { use 5.5.640; };
57is( $@, '', "use 5.5.640; $@");
58
59require_ok('5.5.640');
dd629d5b
GS
60
61# hash keys too
7bd40e26
PP
62if (ord("\t") == 9) { # ASCII
63 $h{111.107.32} = "ok";
64}
65else {
66 $h{150.146.64} = "ok";
67}
e83d50c9 68is('ok',$h{ok },'hash keys w/o v');
dd629d5b 69
7bd40e26
PP
70if (ord("\t") == 9) { # ASCII
71 $x = 77.78.79;
72}
73else {
74 $x = 212.213.214;
75}
e83d50c9 76is($x, 'MNO','poetry optimization with dots w/o v');
dd629d5b 77
e83d50c9 78is(1.20.300.4000, "\x{1}\x{14}\x{12c}\x{fa0}",'compare embedded \x{} string w/o v');
dd629d5b
GS
79
80# test sprintf("%vd"...) etc
7bd40e26 81if (ord("\t") == 9) { # ASCII
e83d50c9 82 is(sprintf("%vd", "Perl"), '80.101.114.108', 'ASCII sprintf("%vd", "Perl")');
7bd40e26
PP
83}
84else {
e83d50c9 85 is(sprintf("%vd", "Perl"), '215.133.153.147', 'EBCDIC sprintf("%vd", "Perl")');
7bd40e26 86}
3cb0bbe5 87
e83d50c9 88is(sprintf("%vd", v1.22.333.4444), '1.22.333.4444', 'sprintf("%vd", v1.22.333.4444)');
b22c7a20 89
7bd40e26 90if (ord("\t") == 9) { # ASCII
e83d50c9 91 is(sprintf("%vx", "Perl"), '50.65.72.6c', 'ASCII sprintf("%vx", "Perl")');
7bd40e26
PP
92}
93else {
e83d50c9 94 is(sprintf("%vx", "Perl"), 'd7.85.99.93', 'EBCDIC sprintf("%vx", "Perl")');
7bd40e26 95}
b22c7a20 96
e83d50c9 97is(sprintf("%vX", 1.22.333.4444), '1.16.14D.115C','ASCII sprintf("%vX", 1.22.333.4444)');
b22c7a20 98
7bd40e26 99if (ord("\t") == 9) { # ASCII
e83d50c9 100 is(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154', 'ASCII sprintf("%vo", "Perl")');
7bd40e26
PP
101}
102else {
e83d50c9 103 is(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223', 'EBCDIC sprintf("%vo", "Perl")');
7bd40e26 104}
b22c7a20 105
e83d50c9
JP
106is(sprintf("%*vb", "##", v1.22.333.4444),
107 '1##10110##101001101##1000101011100', 'sprintf("%vb", 1.22.333.4444)');
3cb0bbe5 108
e83d50c9 109is(sprintf("%vd", join("", map { chr }
fd36d4b8 110 unpack 'U*', pack('U*',2001,2002,2003))),
e83d50c9 111 '2001.2002.2003','unpack/pack U*');
8dbfaa5d 112
3cb0bbe5 113{
8058d7ab 114 use bytes;
fd36d4b8 115
7bd40e26 116 if (ord("\t") == 9) { # ASCII
e83d50c9 117 is(sprintf("%vd", "Perl"), '80.101.114.108', 'ASCII sprintf("%vd", "Perl") w/use bytes');
7bd40e26
PP
118 }
119 else {
e83d50c9 120 is(sprintf("%vd", "Perl"), '215.133.153.147', 'EBCDIC sprintf("%vd", "Perl") w/use bytes');
7bd40e26 121 }
b22c7a20 122
210db7fc 123 if (ord("\t") == 9) { # ASCII
e83d50c9 124 is(sprintf("%vd", 1.22.333.4444), '1.22.197.141.225.133.156', 'ASCII sprintf("%vd", v1.22.333.4444 w/use bytes');
210db7fc
PP
125 }
126 else {
e83d50c9 127 is(sprintf("%vd", 1.22.333.4444), '1.22.142.84.187.81.112', 'EBCDIC sprintf("%vd", v1.22.333.4444 w/use bytes');
210db7fc 128 }
b22c7a20 129
7bd40e26 130 if (ord("\t") == 9) { # ASCII
e83d50c9 131 is(sprintf("%vx", "Perl"), '50.65.72.6c', 'ASCII sprintf("%vx", "Perl")');
7bd40e26
PP
132 }
133 else {
e83d50c9 134 is(sprintf("%vx", "Perl"), 'd7.85.99.93', 'EBCDIC sprintf("%vx", "Perl")');
7bd40e26 135 }
b22c7a20 136
210db7fc 137 if (ord("\t") == 9) { # ASCII
e83d50c9 138 is(sprintf("%vX", v1.22.333.4444), '1.16.C5.8D.E1.85.9C', 'ASCII sprintf("%vX", v1.22.333.4444)');
210db7fc
PP
139 }
140 else {
e83d50c9 141 is(sprintf("%vX", v1.22.333.4444), '1.16.8E.54.BB.51.70', 'EBCDIC sprintf("%vX", v1.22.333.4444)');
210db7fc 142 }
b22c7a20 143
7bd40e26 144 if (ord("\t") == 9) { # ASCII
e83d50c9 145 is(sprintf("%#*vo", ":", "Perl"), '0120:0145:0162:0154', 'ASCII sprintf("%#*vo", ":", "Perl")');
7bd40e26
PP
146 }
147 else {
e83d50c9 148 is(sprintf("%#*vo", ":", "Perl"), '0327:0205:0231:0223', 'EBCDIC sprintf("%#*vo", ":", "Perl")');
7bd40e26 149 }
b22c7a20 150
210db7fc 151 if (ord("\t") == 9) { # ASCII
e83d50c9
JP
152 is(sprintf("%*vb", "##", v1.22.333.4444),
153 '1##10110##11000101##10001101##11100001##10000101##10011100',
154 'ASCII sprintf("%*vb", "##", v1.22.333.4444)');
210db7fc
PP
155 }
156 else {
e83d50c9
JP
157 is(sprintf("%*vb", "##", v1.22.333.4444),
158 '1##10110##10001110##1010100##10111011##1010001##1110000',
159 'EBCDIC sprintf("%*vb", "##", v1.22.333.4444)');
210db7fc 160 }
3cb0bbe5 161}
00387047
JH
162
163{
164 # bug id 20000323.056
165
e83d50c9
JP
166 is( "\x{41}", +v65, 'bug id 20000323.056');
167 is( "\x41", +v65, 'bug id 20000323.056');
168 is( "\x{c8}", +v200, 'bug id 20000323.056');
169 is( "\xc8", +v200, 'bug id 20000323.056');
170 is( "\x{221b}", +v8731, 'bug id 20000323.056');
00387047 171}
fd36d4b8
JH
172
173# See if the things Camel-III says are true: 29..33
174
175# Chapter 2 pp67/68
176my $vs = v1.20.300.4000;
e83d50c9
JP
177is($vs,"\x{1}\x{14}\x{12c}\x{fa0}","v-string ne \\x{}");
178is($vs,chr(1).chr(20).chr(300).chr(4000),"v-string ne chr()");
179is('foo',((chr(193) eq 'A') ? v134.150.150 : v102.111.111),"v-string ne ''");
fd36d4b8
JH
180
181# Chapter 15, pp403
182
183# See if sane addr and gethostbyaddr() work
2a52c5cc 184eval { require Socket; gethostbyaddr(v127.0.0.1, Socket::AF_INET) };
7a9ee8c4 185if ($@) {
e83d50c9 186 # No - so do not test insane fails.
7a9ee8c4 187 $@ =~ s/\n/\n# /g;
7a9ee8c4 188}
58d344df 189SKIP: {
190 skip("No Socket::AF_INET # $@") if $@;
7a9ee8c4
JP
191 my $ip = v2004.148.0.1;
192 my $host;
193 eval { $host = gethostbyaddr($ip,Socket::AF_INET) };
e83d50c9 194 ok($@ =~ /Wide character/,"Non-bytes leak to gethostbyaddr");
7a9ee8c4 195}
fd36d4b8
JH
196
197# Chapter 28, pp671
e83d50c9
JP
198ok(v5.6.0 lt v5.7.0, "v5.6.0 lt v5.7.0");
199
200# part of 20000323.059
201is(v200, chr(200), "v200 eq chr(200)" );
202is(v200, +v200, "v200 eq +v200" );
203is(v200, eval( "v200"), 'v200 eq "v200"' );
204is(v200, eval("+v200"), 'v200 eq eval("+v200")' );
205
206# Tests for string/numeric value of $] itself
207my ($revision,$version,$subversion) = split '\.', sprintf("%vd",$^V);
208
209my $v = sprintf("%d.%.3d%.3d",$revision,$version,$subversion);
210
211ok( $v eq "$]", "\$^V eq \$] (string)");
212
213$v = $revision + $version/1000 + $subversion/1000000;
214
215ok( $v == $], "\$^V == \$] (numeric)" );
216
217# [ID 20010902.001] check if v-strings handle full UV range or not
218if ( $Config{'uvsize'} >= 4 ) {
219 is( sprintf("%vd", v2147483647.2147483648), '2147483647.2147483648', 'v-string > IV_MAX[32-bit]' );
220 is( sprintf("%vd", v3141592653), '3141592653', 'IV_MAX < v-string < UV_MAX[32-bit]');
221 is( sprintf("%vd", v4294967295), '4294967295', 'v-string == UV_MAX[32-bit] - 1');
7a9ee8c4 222}
e83d50c9
JP
223
224if ( $Config{'uvsize'} >= 8 ) {
225 is( sprintf("%vd", v9223372036854775807.9223372036854775808), '9223372036854775807.9223372036854775808', 'v-string > IV_MAX[64-bit]' );
226 is( sprintf("%vd", v17446744073709551615), '17446744073709551615', 'IV_MAX < v-string < UV_MAX[64-bit]');
227 is( sprintf("%vd", v18446744073709551615), '18446744073709551615', 'v-string == UV_MAX[64-bit] - 1');
7a9ee8c4 228}