6 use Test
::More tests
=> 6;
7 use File
::Temp qw
/:seekable/;
8 use File
::Spec
::Functions
;
17 use_ok
( 'File::Find::Rule::VersionedFile' )
18 or BAIL_OUT
('could not include the module being tested');
22 my $tempdir = File
::Temp
->newdir;
24 ## construct a test repos
25 my $publisher = CXGN
::Publish
->new;
26 $publisher->make_dirs(1);
27 my $tempfile = File
::Temp
->new;
28 $tempfile->print('foofoooo');
32 foreach my $dir1 (qw
| ABC DEF
| ) {
33 foreach my $dir2 (qw
| GHI JKL
|) {
34 foreach my $name ( 'foghat', 'tobykeith' ) { #< because you know i love toby keith
35 foreach my $ext ('txt','doc') {
36 push @publish_ops, [ cp
=> "$tempfile", catfile
($tempdir,$dir1,$dir2,"$name.$ext")],
41 $publisher->publish( @publish_ops );
43 $tempfile->print('fiddlefaddlefoodle');
46 $publisher->publish( @publish_ops[0..4] );
47 #system find => $tempdir;
49 ### now test the find rules on the test repo
52 File
::Find
::Rule
->file->unversioned_name(qr/tobykeith\.doc/);
53 } 'dies with no publish object';
55 sub ffr
{ File
::Find
::Rule
->file->unversioned_name( $publisher, qr/tobykeith\.doc/) };
56 my @set1 = normalize
( ffr
()->in( $tempdir ) );
59 'ABC/GHI/old/tobykeith.v1.doc.<timestamp>',
60 'ABC/GHI/tobykeith.v2.doc',
61 'ABC/JKL/tobykeith.v1.doc',
62 'DEF/GHI/tobykeith.v1.doc',
63 'DEF/JKL/tobykeith.v1.doc'
65 'got correct results for set 1',
67 or diag Dumper \
@set1;
69 my @set2 = normalize
( ffr
()->version_is_obsolete($publisher,1)->in( $tempdir ) );
72 'ABC/GHI/old/tobykeith.v1.doc.<timestamp>',
74 'got correct results for set 2',
76 or diag Dumper \
@set2;
78 my @set3 = normalize
( ffr
()->version_is_obsolete($publisher,0)->in( $tempdir ) );
81 'ABC/GHI/tobykeith.v2.doc',
82 'ABC/JKL/tobykeith.v1.doc',
83 'DEF/GHI/tobykeith.v1.doc',
84 'DEF/JKL/tobykeith.v1.doc'
86 'got correct results for set 3',
88 or diag Dumper \
@set3;
90 my @set4 = normalize
( ffr
()->unversioned_dir($publisher,qr/GHI$/)->in( $tempdir ) );
93 'ABC/GHI/old/tobykeith.v1.doc.<timestamp>',
94 'ABC/GHI/tobykeith.v2.doc',
95 'DEF/GHI/tobykeith.v1.doc',
97 'got correct results for set 4',
99 or diag Dumper \
@set4;
102 # normalizes a list of versioned filename so we can test them reliably
104 for( @_ ) { #remove the tempdir from the filenames
106 s/\.\d+$/.<timestamp>/;