diff -Nru libtext-patch-perl-1.4/ChangeLog libtext-patch-perl-1.8/ChangeLog --- libtext-patch-perl-1.4/ChangeLog 2007-04-20 08:28:52.000000000 +0000 +++ libtext-patch-perl-1.8/ChangeLog 2010-10-04 16:17:06.000000000 +0000 @@ -1,12 +1,22 @@ -20070420 v1.4 +20101004 v1.8 -Andrew -- no-nl at end of file bug fixed -- additional tests added to test.pl -- dep. on Text::Diff in test.pl dropped until it supports no-nl case +- t/*.t temporary removed all tests, see t/test.t for details -20070407 v1.3 +20101002 v1.7 + +- t/*.t fixed to use native diff(1) if available. + (Text::Diff 1.37 seems broken) + +20100930 v1.6 + +- fixed empty t dir + +20100908 v1.5 + +- moved tests to 't' (note by Alexandr Ciornii) + +20070407 v1.3 Patches by Andrew - add support for patching with 'OldStyle' & 'Context' patches @@ -14,4 +24,4 @@ - updated the unit test to test patches with newline endings. - dies when a hunk can't be successfully applied -Previous history lost... \ No newline at end of file +Previous history lost... diff -Nru libtext-patch-perl-1.4/debian/changelog libtext-patch-perl-1.8/debian/changelog --- libtext-patch-perl-1.4/debian/changelog 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/changelog 2010-10-22 18:26:42.000000000 +0000 @@ -1,3 +1,32 @@ +libtext-patch-perl (1.8-1) unstable; urgency=low + + [ gregor herrmann ] + * debian/control: Changed: Switched Vcs-Browser field to ViewSVN + (source stanza). + * debian/control: Added: ${misc:Depends} to Depends: field. + * debian/control: remove DM-Upload-Allowed since Xavier Oswald is a DD + now. + + [ Nathan Handler ] + * debian/watch: Update to ignore development releases. + + [ Jotam Jr. Trejo ] + * New upstream release + * debian/control: Add myself to Uploaders + * debian/copyright: Adopt format specification givin in revision + 135 of DEP5 proposal for machine readable copyright information + * debian/control: stable have perl version 5.10.0 so we will not use + 'perl (>=5.8.7)' any more (by the way old stable is archived) + * debian/control: Bump Standards Version to 3.9.1 no changes needed + * debian/compat: Bump compatibility level to 7 + + debian/control Build depend on debhelper '(>= 7)' + * debian/rules: Use rules tiny version + * Adopt Source Format 3.0, http://wiki.debian.org/Projects/DebSrc3.0 + * Add libtext-diff-perl required by t/test.t to Build-Depends-Indep, + needs Text::Diff >= 0.35 and there is nothing older in debian + + -- Jotam Jr. Trejo Fri, 22 Oct 2010 10:33:32 -0600 + libtext-patch-perl (1.4-1) unstable; urgency=low * Initial release (Closes: #494142) diff -Nru libtext-patch-perl-1.4/debian/compat libtext-patch-perl-1.8/debian/compat --- libtext-patch-perl-1.4/debian/compat 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/compat 2010-10-22 10:31:18.000000000 +0000 @@ -1 +1 @@ -5 +7 diff -Nru libtext-patch-perl-1.4/debian/control libtext-patch-perl-1.8/debian/control --- libtext-patch-perl-1.4/debian/control 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/control 2010-10-22 15:38:13.000000000 +0000 @@ -2,19 +2,19 @@ Section: perl Priority: optional Maintainer: Debian Perl Group -Uploaders: Xavier Oswald -Build-Depends-Indep: perl (>= 5.8.7) -Build-Depends: debhelper (>= 5) -Standards-Version: 3.8.0 +Uploaders: Xavier Oswald , + Jotam Jr. Trejo +Build-Depends-Indep: perl, libtext-diff-perl +Build-Depends: debhelper (>= 7) +Standards-Version: 3.9.1 Homepage: http://search.cpan.org/dist/Test-Patch/ Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libtext-patch-perl/ -Vcs-Browser: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-patch-perl/ -DM-Upload-Allowed: yes +Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libtext-patch-perl/ Package: libtext-patch-perl Architecture: all -Depends: ${perl:Depends} -Description: Module for patching text with a given patch +Depends: ${misc:Depends}, ${perl:Depends} +Description: module for patching text with a given patch Text::Patch combines source text with given diff (difference) data. Diff data is produced by Text::Diff module or by the standard diff utility (man diff, see -u option). diff -Nru libtext-patch-perl-1.4/debian/copyright libtext-patch-perl-1.8/debian/copyright --- libtext-patch-perl-1.4/debian/copyright 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/copyright 2010-10-22 10:31:18.000000000 +0000 @@ -1,33 +1,29 @@ -This package was debianized by Xavier Oswald on -Thu, 07 Aug 2008 14:47:02 +0200 +Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 +Maintainer: Vladi Belperchinov-Shabanski +Source: http://search.cpan.org/dist/Text-Patch/ +Name: Text-Patch -It was downloaded from: http://search.cpan.org/dist/Text-Patch/ - -Upstream Author: Vladi Belperchinov-Shabanski - -Copyright (C) 2004 Vladi Belperchinov-Shabanski - -Files: debian/* -Copyright: © 2008 Xavier Oswald - © 2008 Debian Perl Group +Files: * +Copyright: 2004, Vladi Belperchinov-Shabanski License: GPL-2+ - The Debian packaging information is under the GPL, version 2 or later - -License: - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this package; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Files: debian/* +Copyright: 2008, Xavier Oswald + 2010, Jotam Jr. Trejo +License: Artistic | GPL-2+ -On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. +License: GPL-2+ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 dated June, 1991, or (at your + option) any later version. + . + On Debian systems, the complete text of version 2 of the GNU + General Public License can be found in `/usr/share/common-licenses/GPL-2'. + +License: Artistic + This program is free software; you can redistribute it and/or modify + it under the terms of the Artistic License, which comes with Perl. + . + On Debian systems, the complete text of the Artistic License + can be found in `/usr/share/common-licenses/Artistic'. diff -Nru libtext-patch-perl-1.4/debian/rules libtext-patch-perl-1.8/debian/rules --- libtext-patch-perl-1.4/debian/rules 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/rules 2010-10-22 10:31:18.000000000 +0000 @@ -1,50 +1,3 @@ #!/usr/bin/make -f - -export PERL_MM_USE_DEFAULT=1 - -PERL ?= /usr/bin/perl -PACKAGE = $(shell dh_listpackages) -TMP = $(CURDIR)/debian/$(PACKAGE) - -build: build-stamp -build-stamp: - dh_testdir - $(PERL) Makefile.PL INSTALLDIRS=vendor - $(MAKE) - $(MAKE) test - touch $@ - -clean: - dh_testdir - dh_testroot - dh_clean build-stamp install-stamp - [ ! -f Makefile ] || $(MAKE) realclean - -install: install-stamp -install-stamp: build-stamp - dh_testdir - dh_testroot - dh_clean -k - $(MAKE) install DESTDIR=$(TMP) PREFIX=/usr - [ ! -d $(TMP)/usr/lib/perl5 ] || \ - rmdir --ignore-fail-on-non-empty --parents --verbose \ - $(TMP)/usr/lib/perl5 - touch $@ - -binary-arch: - -binary-indep: build install - dh_testdir - dh_testroot - dh_installdocs - dh_installchangelogs ChangeLog - dh_perl - dh_compress - dh_fixperms - dh_installdeb - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install +%: + dh $@ diff -Nru libtext-patch-perl-1.4/debian/source/format libtext-patch-perl-1.8/debian/source/format --- libtext-patch-perl-1.4/debian/source/format 1970-01-01 00:00:00.000000000 +0000 +++ libtext-patch-perl-1.8/debian/source/format 2010-10-25 15:17:50.000000000 +0000 @@ -0,0 +1 @@ +3.0 (quilt) diff -Nru libtext-patch-perl-1.4/debian/watch libtext-patch-perl-1.8/debian/watch --- libtext-patch-perl-1.4/debian/watch 2010-10-25 15:17:50.000000000 +0000 +++ libtext-patch-perl-1.8/debian/watch 2009-06-06 12:09:15.000000000 +0000 @@ -1,2 +1,2 @@ version=3 -http://search.cpan.org/dist/Text-Patch/ .*/Text-Patch-v?(\d[\d_.]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip) +http://search.cpan.org/dist/Text-Patch/ .*/Text-Patch-v?(\d[\d.]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip) diff -Nru libtext-patch-perl-1.4/Makefile.PL libtext-patch-perl-1.8/Makefile.PL --- libtext-patch-perl-1.4/Makefile.PL 2007-04-20 08:24:12.000000000 +0000 +++ libtext-patch-perl-1.8/Makefile.PL 2010-09-08 20:18:40.000000000 +0000 @@ -2,9 +2,10 @@ # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( - 'NAME' => 'Text::Patch', - 'VERSION_FROM' => 'Patch.pm', # finds $VERSION - 'PREREQ_PM' => { Test::More => 0 }, # e.g., Module::Name => 1.1 + 'NAME' => 'Text::Patch', + 'VERSION_FROM' => 'Patch.pm', # finds $VERSION + 'PREREQ_PM' => { Text::Diff => 0 }, # e.g., Module::Name => 1.1 + 'test' => { TESTS => 't/*.t' }, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'Patch.pm', # retrieve abstract from module AUTHOR => 'Vladi Belperchinov-Shabanski ') : ()), diff -Nru libtext-patch-perl-1.4/MANIFEST libtext-patch-perl-1.8/MANIFEST --- libtext-patch-perl-1.4/MANIFEST 2007-04-07 19:07:31.000000000 +0000 +++ libtext-patch-perl-1.8/MANIFEST 2010-09-30 11:16:25.000000000 +0000 @@ -3,6 +3,6 @@ Makefile.PL Patch.pm README -test.pl +t/test.t ChangeLog META.yml Module meta-data (added by MakeMaker) diff -Nru libtext-patch-perl-1.4/META.yml libtext-patch-perl-1.8/META.yml --- libtext-patch-perl-1.4/META.yml 2007-04-20 08:29:41.000000000 +0000 +++ libtext-patch-perl-1.8/META.yml 2010-10-04 16:17:14.000000000 +0000 @@ -1,11 +1,22 @@ -# http://module-build.sourceforge.net/META-spec.html -#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# -name: Text-Patch -version: 1.4 -version_from: Patch.pm -installdirs: site +--- #YAML:1.0 +name: Text-Patch +version: 1.8 +abstract: Patches text with given patch +author: + - Vladi Belperchinov-Shabanski +license: unknown +distribution_type: module +configure_requires: + ExtUtils::MakeMaker: 0 +build_requires: + ExtUtils::MakeMaker: 0 requires: - Test::More: 0 - -distribution_type: module -generated_by: ExtUtils::MakeMaker version 6.30 + Text::Diff: 0 +no_index: + directory: + - t + - inc +generated_by: ExtUtils::MakeMaker version 6.56 +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 diff -Nru libtext-patch-perl-1.4/Patch.pm libtext-patch-perl-1.8/Patch.pm --- libtext-patch-perl-1.4/Patch.pm 2007-04-20 08:29:10.000000000 +0000 +++ libtext-patch-perl-1.8/Patch.pm 2010-10-04 16:16:31.000000000 +0000 @@ -2,7 +2,7 @@ use Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( patch ); -our $VERSION = '1.4'; +our $VERSION = '1.8'; use strict; use warnings; use Carp; @@ -36,8 +36,11 @@ # apply patch DUMP("got patch", \@diff); + my $out = $code->(\@text, \@diff, $sep); - return $code->(\@text, \@diff, $sep); + my $lastline = _chomp($diff[-1], $sep); + $out = _chomp($out, $sep) if $lastline eq NO_NEWLINE; + return $out; } sub patch_unified @@ -83,7 +86,7 @@ my($pos1, $count1) = _range($r1); my($pos2, $count2) = _range($r2); - # parse hunk data + # parse chunk data my @data; my $j = $i + 1; for(; $j < @$diff; $j++) { @@ -148,22 +151,18 @@ # read the from and to part of this hunk my($part1, $pos1, $count1) = $read_part->(); my($part2, $pos2, $count2) = $read_part->(); - $i++; # skip hunk separator + $i++; # skip chunk separator # convert operations to unified style ones - $_ =~ s/^(\+|\-|\s)\s/$1/ for @$part1, @$part2; - $_ =~ s/^\!\s/-/ for @$part1; # remove - $_ =~ s/^\!\s/+/ for @$part2; # add + $_ =~ s/^(.)\s/$1/ for @$part1, @$part2; + $_ =~ s/^\!/-/ for @$part1; # remove + $_ =~ s/^\!/+/ for @$part2; # add - # merge the parts to create a unified style hunk + # merge the parts to create a unified style chunk my @data; for(;;) { my $c1 = $part1->[0]; my $c2 = $part2->[0]; - - # don't propogate no newlines of "from" file to the hunk - undef $c1 if _no_newline($c1, $sep); - last unless defined $c1 || defined $c2; if(defined $c1 && $c1 =~ /^-/) { @@ -198,21 +197,10 @@ my($text, $hunks, $sep) = @_; my $hunknum = scalar @$hunks + 1; die "No hunks found\n" unless @$hunks; - - # analyse last hunk for newline information - my $no_newline = 0; - my $lasth = $hunks->[-1]; - my $lastd = $lasth->{DATA}; - # 'to' file has no newline at end if there is a no newline marker as - # the last line and the previous line was a '+' - $no_newline = 1 if @$lastd >= 2 && _no_newline($lastd->[-1], $sep) && - $lastd->[-2] =~ /^\+/; - for my $hunk ( reverse @$hunks ) { $hunknum--; DUMP("hunk", $hunk); - my @pdata; my $num = $hunk->{FROM}; for( @{ $hunk->{ DATA } } ) @@ -224,7 +212,8 @@ # ignore line endings for comparison my $orig = _chomp($text->[$num++], $sep); # num 0 based here my $expect = _chomp($_, $sep); - TRACE("checking >>$orig<< against >>$expect<<"); + TRACE("checking >>$orig<<"); + TRACE(" against >>$expect<<"); die "Hunk #$hunknum failed at line $num.\n" # actual line number unless $orig eq $expect; } @@ -234,17 +223,13 @@ splice @$text, $hunk->{ FROM }, $hunk->{ LEN }, @pdata; } - my $out = join '', @$text; - $out = _chomp($out, $sep) if $no_newline; - return $out; + return join '', @$text; } -# returns $text without newline $sep -# if $sep is not given, defaults to unix or dos line ending -# in list context also returns chomped separator +# chomp $sep from the end of line +# if $sep is not given, chomp unix or dos line ending sub _chomp { my($text, $sep) = @_; - return $text unless defined $text; if($sep) { $text =~ s/($sep)$//; } else { @@ -253,17 +238,19 @@ return wantarray ? ($text, $1) : $text; } -# returns true if line contains a no newline marker -sub _no_newline { - my($text, $sep) = @_; - my $t = _chomp($text, $sep); - return defined $t && $t eq NO_NEWLINE ? 1 : 0; -} - - sub DUMP {} sub TRACE {} +#sub DUMP { +#use Data::Dumper; +#print STDERR Dumper(@_); +#} +#sub TRACE { +#use Data::Dumper; +#print STDERR Dumper(@_); +#} + + =pod =head1 NAME diff -Nru libtext-patch-perl-1.4/t/test.t libtext-patch-perl-1.8/t/test.t --- libtext-patch-perl-1.4/t/test.t 1970-01-01 00:00:00.000000000 +0000 +++ libtext-patch-perl-1.8/t/test.t 2010-10-04 16:16:10.000000000 +0000 @@ -0,0 +1,165 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl test.pl' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test::More; +use strict; +use Text::Diff; +use Text::Patch; + + +# tests are disabled untill Text::Diff problem with missing newlines is fixed +# otherwise separated offline tests will be added, sorry :( +# //vladi +plan tests => 1; +ok(1); +exit; + + + + + + +#use Log::Trace; +#import Log::Trace 'warn' => { Deep => 0 }; + +my @styles = qw/Unified Context OldStyle/; + +my $t1 = 'The Way that can be told of is not the eternal Way; +The name that can be named is not the eternal name. +The Nameless is the origin of Heaven and Earth; +The Named is the mother of all things. +Therefore let there always be non-being, + so we may see their subtlety, +And let there always be being, + so we may see their outcome. +The two are the same, +But after they are produced, + they have different names. +'; + +my $t2 = 'The Nameless is the origin of Heaven and Earth; +The named is the mother of all things. + +Therefore let there always be non-being, + so we may see their subtlety, +And let there always be being, + so we may see their outcome. +The two are the same, +But after they are produced, + they have different names. +They both may be called deep and profound. +Deeper and more profound, +The door of all subtleties! +'; + +chomp(my $t1b = $t1); +chomp(my $t2b = $t2); + +my @data; # [ text1, text2, style, break, testname, require Text-Diff > 0.35] + +# test different styles with different data +for my $style (@styles) { + push @data, [$t1, $t2, $style, 0, "normal"]; + push @data, [$t1, $t2b, $style, 0, "t2 no newline"]; + push @data, [$t1b, $t2, $style, 0, "t1 no newline", 1]; + push @data, [$t1b, $t2b, $style, 0, "t1,t2 no newline", 1]; +} + +# test breaking it with bad hunks +for my $style (@styles) { + push @data, [$t1, $t2, $style, 1, "bad hunk"]; +} + +plan tests => scalar @data; + +for my $d (@data) { + my($test1, $test2, $style, $break, $name, $td_035) = @$d; + my $patch = diff( \$test1, \$test2, { STYLE => $style } ); + +ok('***NODIFFFOUND***'), next if $patch eq '***NODIFFFOUND***'; + + $test1 =~ s/(\r\n|\n)/ -- broken --$1/ if $break; + + SKIP: { + skip "Text::Diff > 0.35 required", 1 + if $td_035 && $Text::Diff::VERSION <= 0.35; + + #warn "using patch: >>$patch<<\n"; + my $test3 = eval { patch( $test1, $patch, { STYLE => $style } ) }; + my $error = $@; + my $testname = "patch $style ($name)"; + my $ok = $break ? $error : !$error && $test2 eq $test3; + + unless(ok($ok, "patch $style ($name)")) { + diag "error: $error" if $error; + DUMP("\n\n\n\n\n\n$style patch ($name)********************************************************"); + DUMP("text1:---------------------------------\n", $test1); + DUMP("text2:---------------------------------\n", $test2); + DUMP("$style patch:---------------------------------\n", $patch); + DUMP("original:---------------------------------\n", $test2); + DUMP("patched:---------------------------------\n", $test3); + } + } +} + + +sub diff_1 +{ + +#### Text-Diff-1.37 seems broken, meanwhile use native diff(1) + + my $t1 = shift; + my $t2 = shift; + my $opt = shift; + + # Unified Context OldStyle + + open( my $o1, ">/tmp/__________t1" ); + print $o1 $$t1; + close $o1; + + open( my $o2, ">/tmp/__________t2" ); + print $o2 $$t2; + close $o2; + + my $diff; + + $diff = "/bin/diff" if -x "/bin/diff"; + $diff = "/usr/bin/diff" if -x "/usr/bin/diff"; + + return '***NODIFFFOUND***' unless $diff; + + system "$diff -u /tmp/__________t1 /tmp/__________t2 > /tmp/__________t3" if $opt->{ STYLE } eq 'Unified'; + system "$diff -c /tmp/__________t1 /tmp/__________t2 > /tmp/__________t3" if $opt->{ STYLE } eq 'Context'; + system "$diff /tmp/__________t1 /tmp/__________t2 > /tmp/__________t3" if $opt->{ STYLE } eq 'OldStyle'; + + open( my $o3, "/tmp/__________t3" ); + my $t3 = join '', <$o3>; + close $o3; + + unlink "/tmp/__________t1"; + unlink "/tmp/__________t2"; + unlink "/tmp/__________t3"; + + return $t3; +} + + +#$t1 = 'here'; +#$t2 = 'there'; +#for my $style (@styles) +# { +# skip "Text::Diff > 0.35 required", 1 +# if $Text::Diff::VERSION <= 0.35; +# my $patch = diff( \$t1, \$t2, { STYLE => $style } ); +# my $result = patch( $t1, $patch, { STYLE => $style } ); +# ok( $result eq $t2, "patch $style (single no-nl lines)" ); +# } + +sub TRACE {} +sub DUMP { print STDERR @_, "\n"; } + diff -Nru libtext-patch-perl-1.4/test.pl libtext-patch-perl-1.8/test.pl --- libtext-patch-perl-1.4/test.pl 2007-04-20 08:24:38.000000000 +0000 +++ libtext-patch-perl-1.8/test.pl 1970-01-01 00:00:00.000000000 +0000 @@ -1,501 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### - -use Test::More; -use strict; -use Text::Patch; -use constant DATA_SEP => ( "----8<----" x 7 )."\n"; - -#use Log::Trace; -#import Log::Trace 'warn' => { Deep => 1 }; - -my @styles = qw/Unified Context OldStyle/; - -my $t1 = 'The Way that can be told of is not the eternal Way; -The name that can be named is not the eternal name. -The Nameless is the origin of Heaven and Earth; -The Named is the mother of all things. -Therefore let there always be non-being, - so we may see their subtlety, -And let there always be being, - so we may see their outcome. -The two are the same, -But after they are produced, - they have different names. -'; - -my $t2 = 'The Nameless is the origin of Heaven and Earth; -The named is the mother of all things. - -Therefore let there always be non-being, - so we may see their subtlety, -And let there always be being, - so we may see their outcome. -The two are the same, -But after they are produced, - they have different names. -They both may be called deep and profound. -Deeper and more profound, -The door of all subtleties! -'; - -chomp(my $t1b = $t1); -chomp(my $t2b = $t2); - -my @data; # [ text1, text2, style, break, testname] - -# test different styles with different data -for my $style (@styles) { - push @data, [$t1, $t2, $style, 0, "normal"]; - push @data, [$t1, $t2b, $style, 0, "t2 no newline"]; - push @data, [$t1b, $t2, $style, 0, "t1 no newline"]; - push @data, [$t1b, $t2b, $style, 0, "t1,t2 no newline"]; -} - -# test breaking it with bad hunks -for my $style (@styles) { - push @data, [$t1, $t2, $style, 1, "bad hunk"]; -} - -# test a tricky patch -for my $style (@styles) { - push @data, ["foo\nbar", "foo\n", $style, 0, "tricky patch"]; -} - -# use the --update option to update test data -update_patches(@data) if grep '--update', @ARGV; - -# read patch data -my @patches = split DATA_SEP, join "", ; -close DATA or die $!; -die "Patch data not up to date with tests, use --update to update\n" - unless @patches == @data; - -plan tests => scalar @data; - -for my $d (@data) { - my($test1, $test2, $style, $break, $name) = @$d; - my $patch = shift @patches; - $test1 =~ s/(\r\n|\n)/ -- broken --$1/ if $break; - - my $test3 = eval { patch( $test1, $patch, { STYLE => $style } ) }; - my $error = $@; - my $testname = "patch $style ($name)"; - my $ok; - if($break) { - $ok = ok($error, $testname); - } else { - $ok = is($test2, $test3, $testname); - } - unless($ok) { - diag "error: $error" if $error; - DUMP("$style patch", $patch); - DUMP("original", $test2); - DUMP("patched", $test3); - } -} - -# end tests -###################################################################### - -# update patches. requires gnu diff -sub update_patches { - my(@tests) = @_; - my $version = `diff -v`; - die "Could not determine diff version\n" unless $version; - chomp $version; - die "Requires gnu diff, not '$version'" unless $version =~ /GNU/; - - require File::Slurp; - import File::Slurp qw/read_file write_file/; - my @patches; - my %diff_opt = ('Unified' => '-u', - 'Context' => '-c', - 'OldStyle' => '', - ); - for my $t (@tests) { - my($test1, $test2, $style, $break, $name) = @$t; - - write_file("A", $test1) || die $!; - write_file("B", $test2) || die $!; - my $opt = $diff_opt{$style}; - my $patch = `diff --label A --label B $opt A B`; - - push @patches, $patch; - } - my $self = read_file($0) || die $!; - $self =~ s/^(__DATA__\n).*//ms; - - $self .= "__DATA__\n" . join DATA_SEP, @patches; - write_file($0, $self) || die $!; - unlink($_) for qw/A B/; - print "updated $0 patch data\n"; - exit 0; -} - - -#$t1 = 'here'; -#$t2 = 'there'; - -__DATA__ ---- A -+++ B -@@ -1,7 +1,6 @@ --The Way that can be told of is not the eternal Way; --The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; --The Named is the mother of all things. -+The named is the mother of all things. -+ - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -@@ -9,3 +8,6 @@ - The two are the same, - But after they are produced, - they have different names. -+They both may be called deep and profound. -+Deeper and more profound, -+The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- ---- A -+++ B -@@ -1,7 +1,6 @@ --The Way that can be told of is not the eternal Way; --The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; --The Named is the mother of all things. -+The named is the mother of all things. -+ - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -@@ -9,3 +8,6 @@ - The two are the same, - But after they are produced, - they have different names. -+They both may be called deep and profound. -+Deeper and more profound, -+The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- ---- A -+++ B -@@ -1,11 +1,13 @@ --The Way that can be told of is not the eternal Way; --The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; --The Named is the mother of all things. -+The named is the mother of all things. -+ - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -- they have different names. -\ No newline at end of file -+ they have different names. -+They both may be called deep and profound. -+Deeper and more profound, -+The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- ---- A -+++ B -@@ -1,11 +1,13 @@ --The Way that can be told of is not the eternal Way; --The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; --The Named is the mother of all things. -+The named is the mother of all things. -+ - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -- they have different names. -\ No newline at end of file -+ they have different names. -+They both may be called deep and profound. -+Deeper and more profound, -+The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,7 **** -- The Way that can be told of is not the eternal Way; -- The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; -! The Named is the mother of all things. - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, ---- 1,6 ---- - The Nameless is the origin of Heaven and Earth; -! The named is the mother of all things. -! - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -*************** -*** 9,11 **** ---- 8,13 ---- - The two are the same, - But after they are produced, - they have different names. -+ They both may be called deep and profound. -+ Deeper and more profound, -+ The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,7 **** -- The Way that can be told of is not the eternal Way; -- The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; -! The Named is the mother of all things. - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, ---- 1,6 ---- - The Nameless is the origin of Heaven and Earth; -! The named is the mother of all things. -! - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -*************** -*** 9,11 **** ---- 8,13 ---- - The two are the same, - But after they are produced, - they have different names. -+ They both may be called deep and profound. -+ Deeper and more profound, -+ The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,11 **** -- The Way that can be told of is not the eternal Way; -- The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; -! The Named is the mother of all things. - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -! they have different names. -\ No newline at end of file ---- 1,13 ---- - The Nameless is the origin of Heaven and Earth; -! The named is the mother of all things. -! - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -! they have different names. -! They both may be called deep and profound. -! Deeper and more profound, -! The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,11 **** -- The Way that can be told of is not the eternal Way; -- The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; -! The Named is the mother of all things. - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -! they have different names. -\ No newline at end of file ---- 1,13 ---- - The Nameless is the origin of Heaven and Earth; -! The named is the mother of all things. -! - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, - so we may see their outcome. - The two are the same, - But after they are produced, -! they have different names. -! They both may be called deep and profound. -! Deeper and more profound, -! The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -1,2d0 -< The Way that can be told of is not the eternal Way; -< The name that can be named is not the eternal name. -4c2,3 -< The Named is the mother of all things. ---- -> The named is the mother of all things. -> -11a11,13 -> They both may be called deep and profound. -> Deeper and more profound, -> The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -1,2d0 -< The Way that can be told of is not the eternal Way; -< The name that can be named is not the eternal name. -4c2,3 -< The Named is the mother of all things. ---- -> The named is the mother of all things. -> -11a11,13 -> They both may be called deep and profound. -> Deeper and more profound, -> The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -1,2d0 -< The Way that can be told of is not the eternal Way; -< The name that can be named is not the eternal name. -4c2,3 -< The Named is the mother of all things. ---- -> The named is the mother of all things. -> -11c10,13 -< they have different names. -\ No newline at end of file ---- -> they have different names. -> They both may be called deep and profound. -> Deeper and more profound, -> The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -1,2d0 -< The Way that can be told of is not the eternal Way; -< The name that can be named is not the eternal name. -4c2,3 -< The Named is the mother of all things. ---- -> The named is the mother of all things. -> -11c10,13 -< they have different names. -\ No newline at end of file ---- -> they have different names. -> They both may be called deep and profound. -> Deeper and more profound, -> The door of all subtleties! -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- ---- A -+++ B -@@ -1,7 +1,6 @@ --The Way that can be told of is not the eternal Way; --The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; --The Named is the mother of all things. -+The named is the mother of all things. -+ - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -@@ -9,3 +8,6 @@ - The two are the same, - But after they are produced, - they have different names. -+They both may be called deep and profound. -+Deeper and more profound, -+The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,7 **** -- The Way that can be told of is not the eternal Way; -- The name that can be named is not the eternal name. - The Nameless is the origin of Heaven and Earth; -! The Named is the mother of all things. - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, ---- 1,6 ---- - The Nameless is the origin of Heaven and Earth; -! The named is the mother of all things. -! - Therefore let there always be non-being, - so we may see their subtlety, - And let there always be being, -*************** -*** 9,11 **** ---- 8,13 ---- - The two are the same, - But after they are produced, - they have different names. -+ They both may be called deep and profound. -+ Deeper and more profound, -+ The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -1,2d0 -< The Way that can be told of is not the eternal Way; -< The name that can be named is not the eternal name. -4c2,3 -< The Named is the mother of all things. ---- -> The named is the mother of all things. -> -11a11,13 -> They both may be called deep and profound. -> Deeper and more profound, -> The door of all subtleties! -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- ---- A -+++ B -@@ -1,2 +1 @@ - foo --bar -\ No newline at end of file -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -*** A ---- B -*************** -*** 1,2 **** - foo -- bar -\ No newline at end of file ---- 1 ---- -----8<--------8<--------8<--------8<--------8<--------8<--------8<---- -2d1 -< bar -\ No newline at end of file -#for my $style (@styles) -# { -# skip "Text::Diff > 0.35 required", 1 -# if $Text::Diff::VERSION <= 0.35; -# my $patch = diff( \$t1, \$t2, { STYLE => $style } ); -# my $result = patch( $t1, $patch, { STYLE => $style } ); -# ok( $result eq $t2, "patch $style (single no-nl lines)" ); -# } - -sub TRACE {} -sub DUMP {}