aa2a98f7879b307da5634584834871276dbe4ed9
[urisagit/Perl-Docs.git] / t / original.t
1 #!/usr/bin/perl -I.
2
3 # try to honor possible tempdirs
4 $tmp = "file_$$";
5
6 $short = <<END;
7 small
8 file
9 END
10
11 $long = <<END;
12 This is a much longer bit of contents
13 to store in a file.
14 END
15
16 print "1..7\n";
17
18 use File::Slurp;
19
20 &write_file($tmp, $long);
21 if (&read_file($tmp) eq $long) {print "ok 1\n";} else {print "not ok 1\n";}
22
23 @x = &read_file($tmp);
24 @y = grep( $_ ne '', split(/(.*?\n)/, $long));
25 while (@x && @y) {
26         last unless $x[0] eq $y[0];
27         shift @x;
28         shift @y;
29 }
30 if (@x == @y && (@x ? $x[0] eq $y[0] : 1)) { print "ok 2\n";} else {print "not ok 2\n"}
31
32 &append_file($tmp, $short);
33 if (&read_file($tmp) eq "$long$short") {print "ok 3\n";} else {print "not ok 3\n";}
34
35 $iold = (stat($tmp))[1];
36 &overwrite_file($tmp, $short);
37 $inew = (stat($tmp))[1];
38
39 if (&read_file($tmp) eq $short) {print "ok 4\n";} else {print "not ok 4\n";}
40
41 if ($inew == $iold) {print "ok 5\n";} else {print "not ok 5\n";}
42
43 unlink($tmp);
44
45 &overwrite_file($tmp, $long);
46 if (&read_file($tmp) eq $long) {print "ok 6\n";} else {print "not ok 6\n";}
47
48 unlink($tmp);
49
50 &append_file($tmp, $short);
51 if (&read_file($tmp) eq $short) {print "ok 7\n";} else {print "not ok 7\n";}
52
53 unlink($tmp);
54
55