4 use File::Tree::Snapshot;
5 use File::Path qw( rmtree );
8 my $tree_path = "$FindBin::Bin/test-tree";
10 my $tree = File::Tree::Snapshot->new(
11 storage_path => $tree_path,
14 ok not($tree->exists), 'tree doesnt exist yet';
15 ok $tree->create, 'tree creation successful';
16 ok $tree->exists, 'tree does now exit';
19 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file');
24 my ($file) = $tree->find_files('txt', 'foo');
25 ok -e $file, 'written file exists';
27 ok $tree->commit, 'commit';
28 ok $tree->reset, 'reset';
29 ok -e $file, 'file still exists';
32 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file again');
38 ok(my $fh = $tree->open('>', 'foo/baz.txt', mkpath => 1), 'open other file');
43 ok $tree->reset, 'reset before commit';
44 ok -e $tree->file('foo/bar.txt'), 'original file still exists';
45 ok not(-e $tree->file('foo/baz.txt')), 'new file no longer exists';
48 my $fh = $tree->open('<', 'foo/bar.txt');
49 my $body = do { local $/; <$fh> };
50 is $body, 'baz', 'reset to original content';