Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test stripsigns #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
14 changes: 14 additions & 0 deletions test/header_clean.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ 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 "+/- symbols are stripped (complex-hunks on git show)" {
output=$( load_fixture "complex-hunks" | $diff_so_fancy)
lines=$( printf "%s" "$output")
run printf "%s" "$lines"
refute_line --index 29 "+ return 1;"
}

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