5 @INC = '../lib' if -d '../lib';
8 BEGIN {$^W |= 1} # Insist upon warnings
9 use vars qw{ @warnings };
10 BEGIN { # ...and save 'em for later
11 $SIG{'__WARN__'} = sub { push @warnings, @_ }
13 END { print @warnings }
15 ######################### We start with some black magic to print on failure.
17 BEGIN { $| = 1; print "1..39\n"; }
18 END {print "not ok 1\n" unless $loaded;}
21 #print "# Version: $constant::VERSION\n";
24 ######################### End of black magic.
29 my($num, $bool, $diag) = @_;
34 print "not ok $num\n";
35 return unless defined $diag;
36 $diag =~ s/\Z\n?/\n/; # unchomp
37 print map "# $num : $_", split m/^/m, $diag;
40 use constant PI => 4 * atan2 1, 1;
42 test 2, substr(PI, 0, 7) eq '3.14159';
45 sub deg2rad { PI * $_[0] / 180 }
47 my $ninety = deg2rad 90;
49 test 4, $ninety > 1.5707;
50 test 5, $ninety < 1.5708;
52 use constant UNDEF1 => undef; # the right way
53 use constant UNDEF2 => ; # the weird way
54 use constant 'UNDEF3' ; # the 'short' way
55 use constant EMPTY => ( ) ; # the right way for lists
57 test 6, not defined UNDEF1;
58 test 7, not defined UNDEF2;
59 test 8, not defined UNDEF3;
62 test 10, not defined $undef[0];
70 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
71 use constant COUNTLIST => reverse 1, 2, 3, 4, 5;
72 use constant COUNTLAST => (COUNTLIST)[-1];
74 test 14, COUNTDOWN eq '54321';
77 test 16, COUNTDOWN eq join '', @cl;
78 test 17, COUNTLAST == 1;
79 test 18, (COUNTLIST)[1] == 4;
81 use constant ABC => 'ABC';
82 test 19, "abc${\( ABC )}abc" eq "abcABCabc";
84 use constant DEF => 'D', 'E', chr ord 'F';
85 test 20, "d e f @{[ DEF ]} d e f" eq "d e f D E F d e f";
87 use constant SINGLE => "'";
88 use constant DOUBLE => '"';
89 use constant BACK => '\\';
90 my $tt = BACK . SINGLE . DOUBLE ;
91 test 21, $tt eq q(\\'");
93 use constant MESS => q('"'\\"'"\\);
94 test 22, MESS eq q('"'\\"'"\\);
95 test 23, length(MESS) == 8;
97 use constant TRAILING => '12 cats';
101 BEGIN { $save_warn = $^W; $^W = 0 }
102 test 24, TRAILING == 12;
103 BEGIN { $^W = $save_warn }
105 test 25, TRAILING eq '12 cats';
107 use constant LEADING => " \t1234";
108 test 26, LEADING == 1234;
109 test 27, LEADING eq " \t1234";
111 use constant ZERO1 => 0;
112 use constant ZERO2 => 0.0;
113 use constant ZERO3 => '0.0';
114 test 28, ZERO1 eq '0';
115 test 29, ZERO2 eq '0';
116 test 30, ZERO3 eq '0.0';
120 use constant PI => 3.141;
123 test 31, (PI > 3.1415 and PI < 3.1416);
124 test 32, Other::PI == 3.141;
126 use constant E2BIG => $! = 7;
128 # This is something like "Arg list too long", but the actual message
129 # text may vary, so we can't test much better than this.
130 test 34, length(E2BIG) > 6;
131 test 35, index(E2BIG, " ") > 0;
133 test 36, @warnings == 0, join "\n", "unexpected warning", @warnings;
134 @warnings = (); # just in case
136 test 37, @warnings &&
137 ($warnings[0] =~ /Constant sub.* undefined/),
140 test 38, @warnings == 0, "unexpected warning";
141 test 39, $^W & 1, "Who disabled the warnings?";