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';
17 ok(-e "$tree_path/.gitignore", 'created .gitignore');
20 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file');
25 my ($file) = $tree->find_files('txt', 'foo');
26 ok -e $file, 'written file exists';
28 ok $tree->commit, 'commit';
29 ok $tree->reset, 'reset';
30 ok -e $file, 'file still exists';
33 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file again');
39 ok(my $fh = $tree->open('>', 'foo/baz.txt', mkpath => 1), 'open other file');
44 ok $tree->reset, 'reset before commit';
45 ok -e $tree->file('foo/bar.txt'), 'original file still exists';
46 ok not(-e $tree->file('foo/baz.txt')), 'new file no longer exists';
49 my $fh = $tree->open('<', 'foo/bar.txt');
50 my $body = do { local $/; <$fh> };
51 is $body, 'baz', 'reset to original content';