This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test-Simple syncup from Schwern.
[perl5.git] / lib / Attribute / Handlers / test.pl
CommitLineData
dc6b6eef
JH
1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4######################### We start with some black magic to print on failure.
5
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9}
10
11# Change 1..1 below to 1..last_test_to_print .
12# (It may become useful if the test is moved to ./t subdirectory.)
13
14END {print "not ok 1\n" unless $loaded;}
15use v5.6.0;
16use Attribute::Handlers;
17$loaded = 1;
18
19######################### End of black magic.
20
21# Insert your test code below (better if it prints "ok 13"
22# (correspondingly "not ok 13") depending on the success of chunk 13
23# of the test code):
24
25sub ok { $::count++; push @::results, [$_[1], $_[0]?"":"not "]; }
26
27END { print "1..$::count\n";
28 print map "$_->[1]ok $_->[0]\n", sort {$a->[0]<=>$b->[0]} @::results }
29
30package Test;
31use warnings;
32no warnings 'redefine';
33
34sub UNIVERSAL::Okay :ATTR { ::ok @{$_[4]} }
35
36sub Dokay :ATTR(SCALAR) { ::ok @{$_[4]} }
37sub Dokay :ATTR(HASH) { ::ok @{$_[4]} }
38sub Dokay :ATTR(ARRAY) { ::ok @{$_[4]} }
39sub Dokay :ATTR(CODE) { ::ok @{$_[4]} }
40
41sub Vokay :ATTR(VAR) { ::ok @{$_[4]} }
42
43sub Aokay :ATTR(ANY) { ::ok @{$_[4]} }
44
45package main;
46use warnings;
47
48my $x1 :Okay(1,1);
49my @x1 :Okay(1=>2);
50my %x1 :Okay(1,3);
51sub x1 :Okay(1,4) {}
52
53my Test $x2 :Dokay(1,5);
54
55package Test;
56my $x3 :Dokay(1,6);
57my Test $x4 :Dokay(1,7);
58sub x3 :Dokay(1,8) {}
59
60my $y1 :Okay(1,9);
61my @y1 :Okay(1,10);
62my %y1 :Okay(1,11);
63sub y1 :Okay(1,12) {}
64
65my $y2 :Vokay(1,13);
66my @y2 :Vokay(1,14);
67my %y2 :Vokay(1,15);
68# BEGIN {eval 'sub y2 :Vokay(0,16) {}; 1' or
69::ok(1,16);
70# }
71
72my $z :Aokay(1,17);
73my @z :Aokay(1,18);
74my %z :Aokay(1,19);
75sub z :Aokay(1,20) {};
76
77package DerTest;
78use base 'Test';
79use warnings;
80
81my $x5 :Dokay(1,21);
82my Test $x6 :Dokay(1,22);
83sub x5 :Dokay(1,23);
84
85my $y3 :Okay(1,24);
86my @y3 :Okay(1,25);
87my %y3 :Okay(1,26);
88sub y3 :Okay(1,27) {}
89
90package Unrelated;
91
92BEGIN { eval 'my $x7 :Dokay(0,28)' or ::ok(1,28); }
93my Test $x8 :Dokay(1,29);
94eval 'sub x7 :Dokay(0,30) {}' or ::ok(1,30);
95
96
97package Tie::Loud;
98
99sub TIESCALAR { ::ok(1,31); bless {}, $_[0] }
100sub FETCH { ::ok(1,32); return 1 }
101sub STORE { ::ok(1,33); return 1 }
102
103package Tie::Noisy;
104
105sub TIEARRAY { ::ok(1,$_[1]); bless {}, $_[0] }
106sub FETCH { ::ok(1,35); return 1 }
107sub STORE { ::ok(1,36); return 1 }
108sub FETCHSIZE { 100 }
109
110package Tie::Rowdy;
111
112sub TIEHASH { ::ok(1,$_[1]); bless {}, $_[0] }
113sub FETCH { ::ok(1,38); return 1 }
114sub STORE { ::ok(1,39); return 1 }
115
116package main;
117
118use Attribute::Handlers autotie => { Other::Loud => Tie::Loud,
119 Noisy => Tie::Noisy,
120 UNIVERSAL::Rowdy => Tie::Rowdy,
121 };
122
123my Other $loud : Loud;
124$loud++;
125
126my @noisy : Noisy(34);
127$noisy[0]++;
128
129my %rowdy : Rowdy(37);
130$rowdy{key}++;