summaryrefslogtreecommitdiff
path: root/t/original.t
blob: aa2a98f7879b307da5634584834871276dbe4ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl -I.

# try to honor possible tempdirs
$tmp = "file_$$";

$short = <<END;
small
file
END

$long = <<END;
This is a much longer bit of contents
to store in a file.
END

print "1..7\n";

use File::Slurp;

&write_file($tmp, $long);
if (&read_file($tmp) eq $long) {print "ok 1\n";} else {print "not ok 1\n";}

@x = &read_file($tmp);
@y = grep( $_ ne '', split(/(.*?\n)/, $long));
while (@x && @y) {
	last unless $x[0] eq $y[0];
	shift @x;
	shift @y;
}
if (@x == @y && (@x ? $x[0] eq $y[0] : 1)) { print "ok 2\n";} else {print "not ok 2\n"}

&append_file($tmp, $short);
if (&read_file($tmp) eq "$long$short") {print "ok 3\n";} else {print "not ok 3\n";}

$iold = (stat($tmp))[1];
&overwrite_file($tmp, $short);
$inew = (stat($tmp))[1];

if (&read_file($tmp) eq $short) {print "ok 4\n";} else {print "not ok 4\n";}

if ($inew == $iold) {print "ok 5\n";} else {print "not ok 5\n";}

unlink($tmp);

&overwrite_file($tmp, $long);
if (&read_file($tmp) eq $long) {print "ok 6\n";} else {print "not ok 6\n";}

unlink($tmp);

&append_file($tmp, $short);
if (&read_file($tmp) eq $short) {print "ok 7\n";} else {print "not ok 7\n";}

unlink($tmp);