ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/io_common
(Generate patch)

Comparing AnyEvent/t/io_common (file contents):
Revision 1.1 by root, Wed Mar 28 22:28:48 2012 UTC vs.
Revision 1.9 by root, Fri Apr 13 15:24:57 2012 UTC

1#! perl 1#! perl
2 2
3$| = 1; 3$| = 1;
4 4
5# not tested: symlink, readlink, link, utime, chown, chmod
6
5BEGIN { 7BEGIN {
6 print "1..24\n"; 8 print "1..37\n";
7 print "ok 1 # MODEL=$AnyEvent::IO::MODEL\n"; 9 print "ok 1 # MODEL=$AnyEvent::IO::MODEL\n";
8} 10}
9use AnyEvent; 11use AnyEvent;
10use AnyEvent::IO qw(:DEFAULT :flags); 12use AnyEvent::IO qw(:DEFAULT :flags);
11BEGIN { 13BEGIN {
13} 15}
14 16
15our $t = 3; 17our $t = 3;
16 18
17sub t { 19sub t {
18 my $cv = AE::cv;
19 my $ok = shift; 20 my $ok = shift;
20 my $f = "ae_" . shift; 21 my $f = "aio_" . shift;
21 $f->(@_, my $cv = AE::cv); 22 $f->(@_, my $cv = AE::cv);
22 my @res = $cv->recv; 23 my @res = $cv->recv;
23 24
24 print !@res != !$ok ? "not " : "", "ok ", $t++, " # $f (@_) = (@res)\n"; 25 print !@res != !$ok ? "not " : "", "ok ", $t++, " # $f (@_) = (@res)\n";
25 26
26 wantarray ? @res : $res[0] 27 wantarray ? @res : $res[0]
27} 28}
28 29
29our $TMP = "/tmp"; 30use File::Spec;
31
32our $TMP = File::Spec->tmpdir;
30our $DIR = "$TMP/ae_io_testdir_$$~"; 33our $DIR = "$TMP/ae_io_testdir_$$~";
31 34
32t 1, mkdir => $DIR, 0777 35t 1, mkdir => $DIR, 0777
33 or do { print "Bail out! Cannot mkdir $DIR, skipping test.\n"; exit 0 }; 36 or do { print "Bail out! Cannot mkdir $DIR, skipping test.\n"; exit 0 };
34t 0, mkdir => $DIR, 0777; 37t 0, mkdir => $DIR, 0777;
39my $fh = t 1, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666; 42my $fh = t 1, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
40 t 0, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666; 43 t 0, open => "$DIR/test", O_CREAT | O_EXCL | O_WRONLY, 0666;
41 44
42t 0, rmdir => $DIR; 45t 0, rmdir => $DIR;
43 46
44t 1, write => $fh, "test1"; 47t 1, write => $fh, "tes--";
45t 1, write => $fh, "test2"; 48t 1, write => $fh, "test2";
46t 1, write => $fh, ""; 49t 1, write => $fh, "";
50
51t 1, seek => $fh, 3, 0;
52t 1, write => $fh, "t1";
53
54#t 1, truncate => $fh, 5+5; # not available on windows
47 55
48t 1, stat => $fh; 56t 1, stat => $fh;
49print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n"; 57print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n";
50 58
51t 1, close => $fh; 59t 1, close => $fh;
52 60
53t 1, stat => "$DIR/test"; 61t 1, stat => "$DIR/test";
54print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size\n"; 62print -s _ != 10 ? "not " : "", "ok ", $t++, " # stat size (", -s _,")\n";
55 63
56t 1, lstat => "$DIR/test"; 64t 1, lstat => "$DIR/test";
57print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n"; 65print -s _ != 10 ? "not " : "", "ok ", $t++, " # lstat size\n";
58 66
59t 1, rename => "$DIR/test", "$DIR/test2"; 67t 1, rename => "$DIR/test", "$DIR/test2";
60 68
61############################################################################# 69#############################################################################
70# test dir
71
72t 0, readdir => "$DIR/nonexistent";
73my $res = t 1, readdir => $DIR;
74print @$res != 1 ? "not " : "", "ok ", $t++, " # res count\n";
75print $res->[0] ne "test2" ? "not " : "", "ok ", $t++, " # res data (@$res)\n";
76
77#############################################################################
62# test file 78# test file
63 79
64my $fh = t 1, open => "$DIR/test2", O_RDONLY, 0; 80$fh = t 1, open => "$DIR/test2", O_RDONLY, 0;
65 81
66print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n"; 82print +(t 1, read => $fh, 6) ne "test1t" ? "not " : "", "ok ", $t++, " # read 6\n";
67print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n"; 83print +(t 1, read => $fh, 7) ne "est2" ? "not " : "", "ok ", $t++, " # read 7\n";
68print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n"; 84print +(t 1, read => $fh, 8) ne "" ? "not " : "", "ok ", $t++, " # read 8\n";
69 85

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines