make testsuite somewhat location independent
[p5sagit/p5-mst-13.2.git] / t / pragma / constant.t
index fdd08b8..15ce319 100755 (executable)
@@ -2,7 +2,7 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib' if -d '../lib';
+    unshift @INC, '../lib' if -d '../lib';
 }
 
 BEGIN {$^W |= 1}               # Insist upon warnings
@@ -14,7 +14,7 @@ END { print @warnings }
 
 ######################### We start with some black magic to print on failure.
 
-BEGIN { $| = 1; print "1..39\n"; }
+BEGIN { $| = 1; print "1..46\n"; }
 END {print "not ok 1\n" unless $loaded;}
 use constant;
 $loaded = 1;
@@ -81,7 +81,7 @@ test 18, (COUNTLIST)[1] == 4;
 use constant ABC       => 'ABC';
 test 19, "abc${\( ABC )}abc" eq "abcABCabc";
 
-use constant DEF       => 'D', "\x45", chr 70;
+use constant DEF       => 'D', 'E', chr ord 'F';
 test 20, "d e f @{[ DEF ]} d e f" eq "d e f D E F d e f";
 
 use constant SINGLE    => "'";
@@ -104,9 +104,9 @@ use constant TRAILING       => '12 cats';
 }
 test 25, TRAILING eq '12 cats';
 
-use constant LEADING   => " \t\n1234";
+use constant LEADING   => " \t1234";
 test 26, LEADING == 1234;
-test 27, LEADING eq " \t\n1234";
+test 27, LEADING eq " \t1234";
 
 use constant ZERO1     => 0;
 use constant ZERO2     => 0.0;
@@ -139,3 +139,19 @@ test 37, @warnings &&
 
 test 38, @warnings == 0, "unexpected warning";
 test 39, $^W & 1, "Who disabled the warnings?";
+
+use constant CSCALAR   => \"ok 40\n";
+use constant CHASH     => { foo => "ok 41\n" };
+use constant CARRAY    => [ undef, "ok 42\n" ];
+use constant CPHASH    => [ { foo => 1 }, "ok 43\n" ];
+use constant CCODE     => sub { "ok $_[0]\n" };
+
+print ${+CSCALAR};
+print CHASH->{foo};
+print CARRAY->[1];
+print CPHASH->{foo};
+eval q{ CPHASH->{bar} };
+test 44, scalar($@ =~ /^No such array/);
+print CCODE->(45);
+eval q{ CCODE->{foo} };
+test 46, scalar($@ =~ /^Constant is not a HASH/);