Skip Menu |

This queue is for tickets about the Text-Diff CPAN distribution.

Report information
The Basics
Id: 25571
Status: resolved
Priority: 0/
Queue: Text-Diff

People
Owner: NEILB [...] cpan.org
Requestors: asw [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.35
Fixed in: 1.44



Subject: breaks on files with no newline at end of file
attached is a diff that patches general.t to test the cases where there is no newline at the end of a file. I haven't attempted to fix the code to handle these cases yet. gnu diff outputs: "\ No newline at end of file" when there is no newline at the end of a file.
Subject: Text-Diff-newline.patch
diff -bru Text-Diff-0.35/t/general.t Text-Diff-0.35.hack/t/general.t --- Text-Diff-0.35/t/general.t 2001-12-16 12:42:15.000000000 +0000 +++ Text-Diff-0.35.hack/t/general.t 2007-03-20 17:51:51.581780000 +0000 @@ -24,10 +24,17 @@ ["", 'STYLE => "OldStyle"' ], + + # test newline endings + ["-u", '', 1], + ["-c", 'STYLE => "Context"', 1], + ["", 'STYLE => "OldStyle"', 1], ) ; my @A = map "$_\n", qw( 1 2 3 4 5d 6 7 8 9 10 11 11d 12 13 ) ; my @B = map "$_\n", qw( 1 2 3 4 5a 6 7 8 9 9a 10 11 12 13 ) ; +my @C = @B; +chomp($C[-1]); my $sep = ( "----8<----" x 7 ) . "\n" ; @@ -43,18 +50,22 @@ ## Here are the two files to feed to diff open A, ">A" or die $! ; print A @A ; close A ; open B, ">B" or die $! ; print B @B ; close B ; + open C, ">C" or die $! ; print C @C ; close C ; my $mtime_A = time ; - my $mtime_B = $mtime_A + 1 ; + my $mtime_BC = $mtime_A + 1 ; utime $mtime_A, $mtime_A, "A" or die $! ; - utime $mtime_B, $mtime_B, "B" or die $! ; + utime $mtime_BC, $mtime_BC, "B" or die $! ; + utime $mtime_BC, $mtime_BC, "C" or die $! ; my $file_options = <<END_OPTIONS ; FILENAME_A => "A", MTIME_A => $mtime_A, FILENAME_B => "B", -MTIME_B => $mtime_B, +MTIME_B => $mtime_BC, +FILENAME_C => "C", +MTIME_C => $mtime_BC, END_OPTIONS open ME, "<$0" or die $! ; @@ -65,11 +76,14 @@ print BAK $me or die $! ; close BAK or die $! ; - my @diffs = map scalar `diff $_->[0] A B`, @tests ; - - for ( @diffs ) { - s/(Sun|Mon|Tue|Wed|Thu|Fri|Sat).*/<MTIME_A>/m ; - s/(Sun|Mon|Tue|Wed|Thu|Fri|Sat).*/<MTIME_B>/m ; + my @diffs; + for my $t (@tests) { + my $file2 = $t->[2] ? 'C' : 'B'; # test newline/non-newline endings + my $mtime2 = "MTIME_$file2"; + my $diff = scalar `diff $t->[0] A $file2`; + $diff =~ s/(Sun|Mon|Tue|Wed|Thu|Fri|Sat|\d{4}-\d{2}-\d{2}\s).*/<MTIME_A>/m ; + $diff =~ s/(Sun|Mon|Tue|Wed|Thu|Fri|Sat|\d{4}-\d{2}-\d{2}\s).*/<$mtime2>/m ; + push @diffs, $diff; } $me =~ s/^(__DATA__\n).*//ms ; @@ -98,21 +112,22 @@ my @file_options = eval "(" . shift( @data ) . ")" ; die if $@ ; -my ( $mtime_A, $mtime_B ) ; +my ( $mtime_A, $mtime_BC ) ; { my %o = @file_options ; $mtime_A = $o{MTIME_A} ; - $mtime_B = $o{MTIME_B} ; + $mtime_BC = $o{MTIME_B} ; } plan tests => scalar @tests ; for ( @tests ) { - my ( $diff_opts, $Diff_opts ) = @$_ ; + my ( $diff_opts, $Diff_opts, $strip_newline ) = @$_ ; my $expect = shift @data ; $expect =~ s/<MTIME_A>/localtime $mtime_A/e ; - $expect =~ s/<MTIME_B>/localtime $mtime_B/e ; + $expect =~ s/<MTIME_B>/localtime $mtime_BC/e ; + $expect =~ s/<MTIME_C>/localtime $mtime_BC/e ; my @Diff_opts = eval "($Diff_opts)" ; die if $@ ; @@ -126,8 +141,9 @@ warn "# diff options: $diff_opts\n" ; warn "# my options: $Diff_opts\n" ; ## Merge the outputs using A::D - my @E = split /^/g, $expect ; - my @G = split /^/g, $output ; + my @E = split /^/s, $expect ; + my @G = split /^/s, $output ; + my $w = length "Expected" ; for ( @E, @G ) { s/\n/\\n/g ; @@ -183,9 +199,11 @@ __DATA__ FILENAME_A => "A", -MTIME_A => 1007983243, +MTIME_A => 1174413111, FILENAME_B => "B", -MTIME_B => 1007983244, +MTIME_B => 1174413112, +FILENAME_C => "C", +MTIME_C => 1174413112, ----8<--------8<--------8<--------8<--------8<--------8<--------8<---- --- A <MTIME_A> @@ -273,3 +291,71 @@ > 9a 12d12 < 11d +----8<--------8<--------8<--------8<--------8<--------8<--------8<---- +--- A <MTIME_A> ++++ C <MTIME_C> +@@ -2,13 +2,13 @@ + 2 + 3 + 4 +-5d ++5a + 6 + 7 + 8 + 9 ++9a + 10 + 11 +-11d + 12 +-13 ++13 +\ No newline at end of file +----8<--------8<--------8<--------8<--------8<--------8<--------8<---- +*** A <MTIME_A> +--- C <MTIME_C> +*************** +*** 2,14 **** + 2 + 3 + 4 +! 5d + 6 + 7 + 8 + 9 + 10 + 11 +- 11d + 12 +! 13 +--- 2,14 ---- + 2 + 3 + 4 +! 5a + 6 + 7 + 8 + 9 ++ 9a + 10 + 11 + 12 +! 13 +\ No newline at end of file +----8<--------8<--------8<--------8<--------8<--------8<--------8<---- +5c5 +< 5d +--- +> 5a +9a10 +> 9a +12d12 +< 11d +14c14 +< 13 +--- +> 13 +\ No newline at end of file
Subject: Re: [rt.cpan.org #25571] AutoReply: breaks on files with no newline at end of file
Date: Sun, 1 Apr 2007 23:16:54 +0100
To: bug-Text-Diff [...] rt.cpan.org
From: Andrew <sobakasu [...] gmail.com>
Attached is a patch for Text::Diff v0.35 to match the gnu diff behaviour "no newline at end of file".

Message body is not shown because sender requested not to inline it.

This was fixed in 1.44