Skip to content

Commit

Permalink
Merge pull request #125 from so-fancy/test-uninitvalue
Browse files Browse the repository at this point in the history
test for complex hunk headers
  • Loading branch information
paulirish committed Mar 9, 2016
2 parents 353cb07 + 3b279ed commit 000387f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/fixtures/complex-hunks.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
commit 74804e377d4a54d1173d4393827d4e4b27e4d5d0
diff --cc libs/header_clean/header_clean.pl
index e8bcd92,5970580..ae279d0
--- a/libs/header_clean/header_clean.pl
+++ b/libs/header_clean/header_clean.pl
@@@ -105,13 -104,21 +104,23 @@@ for (my $i = 0; $i <= $#input; $i++) 
}
}

+ # Courtesy of github.com/git/git/blob/ab5d01a/git-add--interactive.perl#L798-L805
+ sub parse_hunk_header {
+ my ($line) = @_;
+ my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
+ $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
+ $o_cnt = 1 unless defined $o_cnt;
+ $n_cnt = 1 unless defined $n_cnt;
+ return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
+ }
+ 
sub strip_empty_first_line {
 - my $foo = shift(); # Array passed in by reference
 + my $array = shift(); # Array passed in by reference

# If the first line is just whitespace remove it
 - if (defined($foo->[0]) && $foo->[0] =~ /^\s*$/) {
 - shift($foo);
 + if (defined($array->[0]) && $array->[0] =~ /^\s*$/) {
 + shift(@$array); # Throw away the first line
}
 +
 + return 1;
}
7 changes: 7 additions & 0 deletions test/header_clean.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ output=$( load_fixture "file-moves" | $diff_so_fancy )
assert_output --partial '@ diff-so-fancy:3 @'
}

@test "Hunk formatting: @@@ -A,B -C,D +E,F @@@" {
# stderr forced into output
output=$( load_fixture "complex-hunks" | $diff_so_fancy 2>&1 )
assert_output --partial '@ header_clean.pl:107 @'
refute_output --partial 'Use of uninitialized value'
}

@test "mnemonicprefix handling" {
output=$( load_fixture "mnemonicprefix" | $diff_so_fancy )
assert_output --partial 'modified: test/header_clean.bats'
Expand Down

0 comments on commit 000387f

Please sign in to comment.