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