added Changes file
[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';
19119660 17ok(-e "$tree_path/.gitignore", 'created .gitignore');
1d4ef65e 18
19do {
20 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file');
21 print $fh "baz";
22 close $fh;
23};
24
25my ($file) = $tree->find_files('txt', 'foo');
26ok -e $file, 'written file exists';
27
28ok $tree->commit, 'commit';
29ok $tree->reset, 'reset';
30ok -e $file, 'file still exists';
31
32do {
33 ok(my $fh = $tree->open('>', 'foo/bar.txt', mkpath => 1), 'open file again');
34 print $fh "qux";
35 close $fh;
36};
37
38do {
39 ok(my $fh = $tree->open('>', 'foo/baz.txt', mkpath => 1), 'open other file');
40 print $fh "qux";
41 close $fh;
42};
43
44ok $tree->reset, 'reset before commit';
45ok -e $tree->file('foo/bar.txt'), 'original file still exists';
46ok not(-e $tree->file('foo/baz.txt')), 'new file no longer exists';
47
48do {
49 my $fh = $tree->open('<', 'foo/bar.txt');
50 my $body = do { local $/; <$fh> };
51 is $body, 'baz', 'reset to original content';
52};
53
54rmtree $tree_path;
55
56done_testing;