Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Differences CPAN distribution.

Report information
The Basics
Id: 39991
Status: resolved
Priority: 0/
Queue: Test-Differences

People
Owner: Nobody in particular
Requestors: rjbs [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] allow user to pick Text::Diff style
The attached patch allows the user to specify an alternate diff style for Text::Diff. I'm really hoping this can be integrated to allow me to use unified diffs. This is distinct from http://rt.cpan.org/Public/Bug/Display.html?id=39435 but may still be useful for people who want something already provided by Text::Diff. -- rjbs
Subject: style.diff
diff --git a/Changes b/Changes index bb08160..5afcb04 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Changes file for Test::Differences +0.48_02 Sun Oct 12 12:04:21 EDT 2008 + - Add "style" option for alternate diff styles (RJBS) + 0.48_01 Wed Jul 30 10:42:52 GMT 2008 - Fixed bug when comparing AoH with non-scalar values. Reported (with fix) by Mark Zealey diff --git a/Differences.pm b/Differences.pm index 6621405..ca555a7 100644 --- a/Differences.pm +++ b/Differences.pm @@ -105,14 +105,18 @@ YMMV. =head1 OPTIONS -There is currently only one option: "context". This allows you to -control the amount of context shown: +There are currently only two options: "context" and "style" - eq_or_diff $got, $expected, $name, { context => 50000}; +"context" this allows you to control the amount of context shown: + + eq_or_diff $got, $expected, $name, { context => 50000 }; will show you lots and lots of context. Normally, eq_or_diff() uses some heuristics to determine whether to show 3 lines of context (like -a normal unified diff) or 25 lines (for +a normal unified diff) or 25 lines. + +"style" allows you to select a output format (for which see +L<Text::Diff|Text::Diff>). The default is Table. =head1 Deploying Test::Differences @@ -200,7 +204,7 @@ level of automation. =cut -$VERSION = 0.48_01; +$VERSION = 0.48_02; use Exporter; @@ -328,6 +332,8 @@ sub eq_or_diff { $options = pop if @_ > 2 && ref $_[-1]; ( $vals[0], $vals[1], $name ) = @_; + $options ||= {}; + my $data_type; $data_type = $options->{data_type} if $options; $data_type ||= "text" unless ref $vals[0] || ref $vals[1]; @@ -378,7 +384,7 @@ sub eq_or_diff { $diff = diff @vals, { CONTEXT => $context, - STYLE => "Table", + STYLE => $options->{style} || "Table", FILENAME_A => "Got", FILENAME_B => "Expected", OFFSET_A => $data_type eq "text" ? 1 : 0,
Per our conversation, I'm rejecting this, though your solution was better. The current one does solved the problem and has been in the wild for several years. Cheers, Ovid