From: Tara L Andrews Date: Tue, 21 Feb 2012 00:19:46 +0000 (+0100) Subject: don't run SVG tests unless dot is installed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2Fstemmatology.git;a=commitdiff_plain;h=bfcbcecb79f1f863779fef01bcf8e81c0bdbe7b1 don't run SVG tests unless dot is installed --- diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 3a9b056..82588d7 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -2,6 +2,7 @@ package Text::Tradition::Collation; use Encode qw( decode_utf8 ); use File::Temp; +use File::Which; use Graph; use IPC::Run qw( run binary ); use Text::CSV_XS; @@ -467,12 +468,14 @@ sub reading_witnesses { =head2 as_svg( \%options ) Returns an SVG string that represents the graph, via as_dot and graphviz. -See as_dot for a list of options. +See as_dot for a list of options. Must have GraphViz (dot) installed to run. =cut sub as_svg { my( $self, $opts ) = @_; + throw( "Need GraphViz installed to output SVG" ) + unless File::Which::which( 'dot' ); my $want_subgraph = exists $opts->{'from'} || exists $opts->{'to'}; if( !$self->has_cached_svg || $opts->{'recalc'} || $want_subgraph ) { my @cmd = qw/dot -Tsvg/; @@ -1262,14 +1265,13 @@ my $t = Text::Tradition->new( my $c = $t->collation; # Make an svg -my $svg = $c->as_svg; -is( substr( $svg, 0, 5 ), 'has_cached_svg, "SVG was cached" ); -is( $c->as_svg, $svg, "Cached SVG returned upon second call" ); +my $table = $c->alignment_table; +ok( $c->has_cached_table, "Alignment table was cached" ); +is( $c->alignment_table, $table, "Cached table returned upon second call" ); $c->calculate_ranks; -is( $c->as_svg, $svg, "Cached SVG retained with no rank change" ); +is( $c->alignment_table, $table, "Cached table retained with no rank change" ); $c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } ); -isnt( $c->as_svg, $svg, "SVG changed after relationship add" ); +isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" ); =end testing @@ -1336,11 +1338,11 @@ sub calculate_ranks { throw( "Ranks not calculated after $last - do you have a cycle in the graph?" ); } } - # Do we need to invalidate the cached SVG? - if( $self->has_cached_svg ) { + # Do we need to invalidate the cached data? + if( $self->has_cached_svg || $self->has_cached_table ) { foreach my $r ( $self->readings ) { next if $existing_ranks{$r} == $r->rank; - $self->wipe_svg; + $self->_clear_cache; last; } } diff --git a/t/graph.t b/t/graph.t index cae5507..f580465 100644 --- a/t/graph.t +++ b/t/graph.t @@ -3,10 +3,14 @@ use strict; use warnings; use Test::More; use lib 'lib'; +use File::Which; use Text::Tradition; use XML::LibXML; use XML::LibXML::XPathContext; +plan skip_all => 'Need Graphviz installed to test graphs' + unless File::Which::which( 'dot' ); + my $datafile = 't/data/Collatex-16.xml'; my $tradition = Text::Tradition->new( diff --git a/t/text_tradition_collation.t b/t/text_tradition_collation.t index f9d07fb..59e019c 100644 --- a/t/text_tradition_collation.t +++ b/t/text_tradition_collation.t @@ -57,14 +57,13 @@ my $t = Text::Tradition->new( my $c = $t->collation; # Make an svg -my $svg = $c->as_svg; -is( substr( $svg, 0, 5 ), 'has_cached_svg, "SVG was cached" ); -is( $c->as_svg, $svg, "Cached SVG returned upon second call" ); +my $table = $c->alignment_table; +ok( $c->has_cached_table, "Alignment table was cached" ); +is( $c->alignment_table, $table, "Cached table returned upon second call" ); $c->calculate_ranks; -is( $c->as_svg, $svg, "Cached SVG retained with no rank change" ); +is( $c->alignment_table, $table, "Cached table retained with no rank change" ); $c->add_relationship( 'n9', 'n23', { 'type' => 'spelling' } ); -isnt( $c->as_svg, $svg, "SVG changed after relationship add" ); +isnt( $c->alignment_table, $table, "Alignment table changed after relationship add" ); }