fixing typo in SQL
[cxgn-corelibs.git] / t / File / find_rule_versionedfile.t
blobebb53bdb08d5b174cff4682794e805b2c1b4e2a0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use English;
6 use Test::More tests => 6;
7 use File::Temp qw/:seekable/;
8 use File::Spec::Functions;
10 use CXGN::Publish;
12 use Data::Dumper;
14 use Test::Exception;
16 BEGIN {
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');
29 $tempfile->sync;
31 my @publish_ops;
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');
44 $tempfile->sync;
46 $publisher->publish( @publish_ops[0..4] );
47 #system find => $tempdir;
49 ### now test the find rules on the test repo
51 dies_ok {
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 ) );
57 is_deeply(\@set1,
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 ) );
70 is_deeply(\@set2,
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 ) );
79 is_deeply(\@set3,
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 ) );
91 is_deeply(\@set4,
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
103 sub normalize {
104 for( @_ ) { #remove the tempdir from the filenames
105 s/$tempdir\/?//;
106 s/\.\d+$/.<timestamp>/;
109 return sort @_;