#!/usr/bin/perl use strict; use warnings; use File::Find::Rule; use Path::Tiny qw/ path /; use Test::More; use Test::Differences; # log of all tests Test::More->builder->output( 'test_results.txt' ); # Get all the files we want to compare my $rule = File::Find::Rule->new; $rule->file->name('*.Recip.blast.top'); my @files = $rule->in( 'Recip' ); foreach my $rcp_file ( @files ) { # make a new path for the original (lab results) file and # strip the unwanted string from the end of the filename ( my $org_file = $rcp_file ) =~ s/^Recip/Lab/; $org_file =~ s/.Recip.blast.top//; # designate an individual test failure log ( my $err_log = "test_failure.$org_file.txt" ) =~ s/Lab\///; Test::More->builder->failure_output( $err_log ); # Get the content of the two files, extract the wanted strings # to be compared, and store in arrays my @rcp_lines = path( $rcp_file )->lines({ chomp => 1 }); @rcp_lines = map { join(' ', (split '\|')[1,5]) } @rcp_lines; my @org_lines = path( $org_file )->lines({ chomp => 1 }); @org_lines = map { join(' ', (split '\|')[5,1]) } @org_lines; # run the tests eq_or_diff( \@rcp_lines, \@org_lines, $org_file); } done_testing; __END__ #### $ cat Recip/do.re.mi.fa.so.la.ti.1.Recip.blast.top gi|110123922|gb|EC817325.1|EC817325 gi|110095377|gb|EC788780.1|EC788780 gi|110123921|gb|EC817324.1|EC817324 gi|110105430|gb|EC798833.1|EC798833 6 gi|110123920|gb|EC817323.1|EC817323 gi|110106464|gb|EC799867.1|EC799867 #### $ cat Recip/do.re.mi.fa.so.la.ti.2.Recip.blast.top gi|110123922|gb|EC817325.1|EC817325 gi|110095377|gb|EC788780.1|EC788780 gi|110123921|gb|EC817324.1|EC817324 gi|110105430|gb|EC798833.1|EC798833 6 gi|110123920|gb|EC817323.1|EC817323 gi|110106464|gb|EC799867.1|EC799867 #### $ cat Lab/do.re.mi.fa.so.la.ti.1 gi|110095377|gb|EC788780.1|EC788780 gi|110123922|gb|EC817325.1|EC817325 gi|110105430|gb|EC798833.1|EC798833 6 gi|110123921|gb|EC817324.1|EC817324 gi|110106464|gb|EC799867.1|EC799867 gi|110123920|gb|EC817323.1|EC817323 #### $ cat Lab/do.re.mi.fa.so.la.ti.2 gi|110095377|gb|EC788780.1|EC788780 gi|110123922|gb|EC817325.1|EC817325 gi|210105430|gb|EC798833.1|EC798833 6 gi|110123921|gb|EC817324.1|EC817324 gi|110106464|gb|EC799867.1|EC799867 gi|110123920|gb|EC817323.1|EC817323 #### $ perl 1141288.pl $ #### $ cat test_results.txt ok 1 - Lab/do.re.mi.fa.so.la.ti.1 not ok 2 - Lab/do.re.mi.fa.so.la.ti.2 1..2 #### $ cat test_failure.do.re.mi.fa.so.la.ti.2.txt # Failed test 'Lab/do.re.mi.fa.so.la.ti.2' # at 1141288.pl line 40. # +----+--------------------------+--------------------------+ # | Elt|Got |Expected | # +----+--------------------------+--------------------------+ # | 0|[ |[ | # | 1| '110123922 110095377', | '110123922 110095377', | # * 2| '110123921 110105430', | '110123921 210105430', * # | 3| '110123920 110106464' | '110123920 110106464' | # | 4|] |] | # +----+--------------------------+--------------------------+ # Looks like you failed 1 test of 2.