xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Env/t/env.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate$| = 1;
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateBEGIN {
6*0Sstevel@tonic-gate    chdir 't' if -d 't';
7*0Sstevel@tonic-gate    @INC = '../lib';
8*0Sstevel@tonic-gate}
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateif ($^O eq 'VMS') {
11*0Sstevel@tonic-gate    print "1..11\n";
12*0Sstevel@tonic-gate    foreach (1..11) { print "ok $_ # skipped for VMS\n"; }
13*0Sstevel@tonic-gate    exit 0;
14*0Sstevel@tonic-gate}
15*0Sstevel@tonic-gate
16*0Sstevel@tonic-gateuse Env  qw(@FOO);
17*0Sstevel@tonic-gateuse vars qw(@BAR);
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gatesub array_equal
20*0Sstevel@tonic-gate{
21*0Sstevel@tonic-gate    my ($a, $b) = @_;
22*0Sstevel@tonic-gate    return 0 unless scalar(@$a) == scalar(@$b);
23*0Sstevel@tonic-gate    for my $i (0..scalar(@$a) - 1) {
24*0Sstevel@tonic-gate	return 0 unless $a->[$i] eq $b->[$i];
25*0Sstevel@tonic-gate    }
26*0Sstevel@tonic-gate    return 1;
27*0Sstevel@tonic-gate}
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gatesub test
30*0Sstevel@tonic-gate{
31*0Sstevel@tonic-gate    my ($desc, $code) = @_;
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate    &$code;
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate    print "# $desc...\n";
36*0Sstevel@tonic-gate    print "#    FOO = (", join(", ", @FOO), ")\n";
37*0Sstevel@tonic-gate    print "#    BAR = (", join(", ", @BAR), ")\n";
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate    if (defined $check) { print "not " unless &$check; }
40*0Sstevel@tonic-gate    else { print "not " unless array_equal(\@FOO, \@BAR); }
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate    print "ok ", ++$i, "\n";
43*0Sstevel@tonic-gate}
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gateprint "1..11\n";
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gatetest "Assignment", sub {
48*0Sstevel@tonic-gate    @FOO = qw(a B c);
49*0Sstevel@tonic-gate    @BAR = qw(a B c);
50*0Sstevel@tonic-gate};
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gatetest "Storing", sub {
53*0Sstevel@tonic-gate    $FOO[1] = 'b';
54*0Sstevel@tonic-gate    $BAR[1] = 'b';
55*0Sstevel@tonic-gate};
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gatetest "Truncation", sub {
58*0Sstevel@tonic-gate    $#FOO = 0;
59*0Sstevel@tonic-gate    $#BAR = 0;
60*0Sstevel@tonic-gate};
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gatetest "Push", sub {
63*0Sstevel@tonic-gate    push @FOO, 'b', 'c';
64*0Sstevel@tonic-gate    push @BAR, 'b', 'c';
65*0Sstevel@tonic-gate};
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gatetest "Pop", sub {
68*0Sstevel@tonic-gate    pop @FOO;
69*0Sstevel@tonic-gate    pop @BAR;
70*0Sstevel@tonic-gate};
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gatetest "Shift", sub {
73*0Sstevel@tonic-gate    shift @FOO;
74*0Sstevel@tonic-gate    shift @BAR;
75*0Sstevel@tonic-gate};
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gatetest "Push", sub {
78*0Sstevel@tonic-gate    push @FOO, 'c';
79*0Sstevel@tonic-gate    push @BAR, 'c';
80*0Sstevel@tonic-gate};
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gatetest "Unshift", sub {
83*0Sstevel@tonic-gate    unshift @FOO, 'a';
84*0Sstevel@tonic-gate    unshift @BAR, 'a';
85*0Sstevel@tonic-gate};
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gatetest "Reverse", sub {
88*0Sstevel@tonic-gate    @FOO = reverse @FOO;
89*0Sstevel@tonic-gate    @BAR = reverse @BAR;
90*0Sstevel@tonic-gate};
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gatetest "Sort", sub {
93*0Sstevel@tonic-gate    @FOO = sort @FOO;
94*0Sstevel@tonic-gate    @BAR = sort @BAR;
95*0Sstevel@tonic-gate};
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gatetest "Splice", sub {
98*0Sstevel@tonic-gate    splice @FOO, 1, 1, 'B';
99*0Sstevel@tonic-gate    splice @BAR, 1, 1, 'B';
100*0Sstevel@tonic-gate};
101