sponsorship mark in pod
[scpubgit/File-Tree-Snapshot.git] / t / basic.t
CommitLineData
1d4ef65e 1use strictures 1;
2use Test::More;
3
4use File::Tree::Snapshot;
5use File::Path qw( rmtree );
6use FindBin;
7
8my $tree_path = "$FindBin::Bin/test-tree";
9
10my $tree = File::Tree::Snapshot->new(
11 storage_path => $tree_path,
12);
13
14ok not($tree->exists), 'tree doesnt exist yet';
15ok $tree->create, 'tree creation successful';
16ok $tree->exists, 'tree does now exit';
17
18do {
19 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file');
20 print $fh "baz";
21 close $fh;
22};
23
24my ($file) = $tree->find_files('txt', 'foo');
25ok -e $file, 'written file exists';
26
27ok $tree->commit, 'commit';
28ok $tree->reset, 'reset';
29ok -e $file, 'file still exists';
30
31do {
32 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file again');
33 print $fh "qux";
34 close $fh;
35};
36
37do {
38 ok(my $fh = $tree->open('>', 'foo/baz.txt', mkpath => 1), 'open other file');
39 print $fh "qux";
40 close $fh;
41};
42
43ok $tree->reset, 'reset before commit';
44ok -e $tree->file('foo/bar.txt'), 'original file still exists';
45ok not(-e $tree->file('foo/baz.txt')), 'new file no longer exists';
46
47do {
48 my $fh = $tree->open('<', 'foo/bar.txt');
49 my $body = do { local $/; <$fh> };
50 is $body, 'baz', 'reset to original content';
51};
52
53rmtree $tree_path;
54
55done_testing;