From: tla Date: Tue, 10 Jan 2012 12:15:52 +0000 (+0100) Subject: remove path hackery for pars exe X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=457b1620fd58822d243cb43d538fdf6f228585c8;p=scpubgit%2Fstemmatology.git remove path hackery for pars exe --- diff --git a/lib/Text/Tradition/Stemma.pm b/lib/Text/Tradition/Stemma.pm index 9a53812..70fd634 100644 --- a/lib/Text/Tradition/Stemma.pm +++ b/lib/Text/Tradition/Stemma.pm @@ -4,6 +4,7 @@ use Bio::Phylo::IO; use Encode qw( decode_utf8 ); use File::chdir; use File::Temp; +use File::Which; use Graph; use Graph::Reader::Dot; use IPC::Run qw/ run binary /; @@ -303,13 +304,9 @@ sub run_phylip_pars { close CMD; # And then we run the program. - ### HACKY HACKY - my $PHYLIP_PATH = '/Users/tla/Projects/phylip-3.69/exe'; - my $program = "pars"; - if( $^O eq 'darwin' ) { - $program = "$PHYLIP_PATH/$program.app/Contents/MacOS/$program"; - } else { - $program = "$PHYLIP_PATH/$program"; + my $program = File::Which::which( 'pars' ); + unless( -x $program ) { + return( undef, "Phylip pars not found in path" ); } { diff --git a/t/stemma.t b/t/stemma.t index 95b25e3..7f3bc7d 100644 --- a/t/stemma.t +++ b/t/stemma.t @@ -1,6 +1,7 @@ #!/usr/bin/perl use strict; use warnings; +use File::Which; use Test::More; use lib 'lib'; use Text::Tradition; @@ -47,16 +48,19 @@ foreach my $i ( 0 .. $#wits ) { } # Test that pars runs -my( $status, $tree ) = $stemma->run_phylip_pars(); -ok( $status, "pars ran successfully" ); -print STDERR "Error was $tree\n" unless $status; - -# Test that we get a tree -is( scalar @{$stemma->distance_trees}, 1, "Got a single tree" ); -# Test that the tree has all our witnesses -$tree = $stemma->distance_trees->[0]; -my @leaves = grep { $tree->degree( $_ ) == 1 } $tree->vertices; -is( scalar @leaves, 3, "All witnesses in the tree" ); +SKIP: { + skip "pars not installed", 3 unless File::Which::which('pars'); + my( $status, $tree ) = $stemma->run_phylip_pars(); + ok( $status, "pars ran successfully" ); + print STDERR "Error was $tree\n" unless $status; + + # Test that we get a tree + is( scalar @{$stemma->distance_trees}, 1, "Got a single tree" ); + # Test that the tree has all our witnesses + $tree = $stemma->distance_trees->[0]; + my @leaves = grep { $tree->degree( $_ ) == 1 } $tree->vertices; + is( scalar @leaves, 3, "All witnesses in the tree" ); +} # Test our dot output my $display = $stemma->as_dot(); @@ -67,4 +71,4 @@ my $editable = $stemma->editable(); ok( $editable =~ /digraph/, "Got a dot edit graph" ); ok( $editable =~ /hypothetical/, "Graph contains an edit class" ); -done_testing(); \ No newline at end of file +done_testing();