(command.CommandList children: [ (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:test_description) op: assign_op.Equal rhs: {(SQ <'diff function context'>)} spids: [4] ) ] ) (C {<.>} {<./test-lib.sh>}) (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:dir) op: assign_op.Equal rhs: {(DQ ($ Id.VSub_DollarName '$TEST_DIRECTORY') </t4051>)} spids: [15] ) ] ) (command.ShFunction name: commit_and_tag body: (command.BraceGroup children: [ (command.AndOr ops: [Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp Id.Op_DAmp] children: [ (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:tag) op: assign_op.Equal rhs: {($ Id.VSub_Number '$1')} spids: [30] ) ] ) (C {<shift>}) (C {<git>} {<add>} {(DQ ($ Id.VSub_At '$@'))}) (C {<test_tick>}) (C {<git>} {<commit>} {<-m>} {(DQ ($ Id.VSub_DollarName '$tag'))}) (C {<git>} {<tag>} {(DQ ($ Id.VSub_DollarName '$tag'))}) ] ) ] ) ) (command.ShFunction name: first_context_line body: (command.BraceGroup children: [ (C {<awk>} {(SQ <'\n'> <'\t\tfound {print; exit}\n'> <'\t\t/^@@/ {found = 1}\n'> <'\t'>)}) ] ) ) (command.ShFunction name: last_context_line body: (command.BraceGroup children: [ (C {<sed>} {<-ne>} {(word_part.EscapedLiteral token:<Id.Lit_EscapedChar '\\$'>) <p>}) ] ) ) (command.ShFunction name: check_diff body: (command.BraceGroup children: [ (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:name) op: assign_op.Equal rhs: {($ Id.VSub_Number '$1')} spids: [127] ) ] ) (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:desc) op: assign_op.Equal rhs: {($ Id.VSub_Number '$2')} spids: [131] ) ] ) (command.ShAssignment pairs: [ (assign_pair lhs: (sh_lhs_expr.Name name:options) op: assign_op.Equal rhs: {(DQ <'-W '> ($ Id.VSub_Number '$3'))} spids: [135] ) ] ) (C {<test_expect_success>} {(DQ ($ Id.VSub_DollarName '$desc'))} {(SQ <'\n'> <'\t\tgit diff $options "$name^" "$name" >"$name.diff"\n'> <'\t'>)} ) (C {<test_expect_success>} {(SQ <' diff applies'>)} { (SQ <'\n'> <'\t\ttest_when_finished "git reset --hard" &&\n'> <'\t\tgit checkout --detach "$name^" &&\n'> <'\t\tgit apply --index "$name.diff" &&\n'> <'\t\tgit diff --exit-code "$name"\n'> <'\t'> ) } ) ] ) ) (C {<test_expect_success>} {(SQ <setup>)} { (SQ <'\n'> <'\tcat "$dir/includes.c" "$dir/dummy.c" "$dir/dummy.c" "$dir/hello.c" \\\n'> <'\t\t"$dir/dummy.c" "$dir/dummy.c" >file.c &&\n'> <'\tcommit_and_tag initial file.c &&\n'> <'\n'> <'\tgrep -v "delete me from hello" <file.c >file.c.new &&\n'> <'\tmv file.c.new file.c &&\n'> <'\tcommit_and_tag changed_hello file.c &&\n'> <'\n'> <'\tgrep -v "delete me from includes" <file.c >file.c.new &&\n'> <'\tmv file.c.new file.c &&\n'> <'\tcommit_and_tag changed_includes file.c &&\n'> <'\n'> <'\tcat "$dir/appended1.c" >>file.c &&\n'> <'\tcommit_and_tag appended file.c &&\n'> <'\n'> <'\tcat "$dir/appended2.c" >>file.c &&\n'> <'\tcommit_and_tag extended file.c &&\n'> <'\n'> <'\tgrep -v "Begin of second part" <file.c >file.c.new &&\n'> <'\tmv file.c.new file.c &&\n'> <'\tcommit_and_tag long_common_tail file.c &&\n'> <'\n'> <'\tgit checkout initial &&\n'> <'\tcat "$dir/hello.c" "$dir/dummy.c" >file.c &&\n'> <'\tcommit_and_tag hello_dummy file.c &&\n'> <'\n'> <'\t# overlap function context of 1st change and -u context of 2nd change\n'> <'\tgrep -v "delete me from hello" <"$dir/hello.c" >file.c &&\n'> <'\tsed 2p <"$dir/dummy.c" >>file.c &&\n'> <'\tcommit_and_tag changed_hello_dummy file.c &&\n'> <'\n'> <'\tgit checkout initial &&\n'> <'\tgrep -v "delete me from hello" <file.c >file.c.new &&\n'> <'\tmv file.c.new file.c &&\n'> <'\tcat "$dir/appended1.c" >>file.c &&\n'> <'\tcommit_and_tag changed_hello_appended file.c\n'> ) } ) (C {<check_diff>} {<changed_hello>} {(SQ <'changed function'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} {(SQ <'\n'> <'\tgrep "^ .*Begin of hello" changed_hello.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context includes end'>)} {(SQ <'\n'> <'\tgrep "^ .*End of hello" changed_hello.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" changed_hello.diff) -le 1\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include preceding empty lines'>)} {(SQ <'\n'> <'\ttest "$(first_context_line <changed_hello.diff)" != " "\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include trailing empty lines'>)} {(SQ <'\n'> <'\ttest "$(last_context_line <changed_hello.diff)" != " "\n'>)} ) (C {<check_diff>} {<changed_includes>} {(SQ <'changed includes'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} {(SQ <'\n'> <'\tgrep "^ .*Begin.h" changed_includes.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context includes end'>)} {(SQ <'\n'> <'\tgrep "^ .*End.h" changed_includes.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" changed_includes.diff) -le 1\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include trailing empty lines'>)} {(SQ <'\n'> <'\ttest "$(last_context_line <changed_includes.diff)" != " "\n'>)} ) (C {<check_diff>} {<appended>} {(SQ <'appended function'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} {(SQ <'\n'> <'\tgrep "^[+].*Begin of first part" appended.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context includes end'>)} {(SQ <'\n'> <'\tgrep "^[+].*End of first part" appended.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" appended.diff) -le 1\n'>)} ) (C {<check_diff>} {<extended>} {(SQ <'appended function part'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} {(SQ <'\n'> <'\tgrep "^ .*Begin of first part" extended.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context includes end'>)} {(SQ <'\n'> <'\tgrep "^[+].*End of second part" extended.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" extended.diff) -le 2\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include preceding empty lines'>)} {(SQ <'\n'> <'\ttest "$(first_context_line <extended.diff)" != " "\n'>)} ) (C {<check_diff>} {<long_common_tail>} {(SQ <'change with long common tail and no context'>)} {<-U0>}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} {(SQ <'\n'> <'\tgrep "^ .*Begin of first part" long_common_tail.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context includes end'>)} {(SQ <'\n'> <'\tgrep "^ .*End of second part" long_common_tail.diff\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" long_common_tail.diff) -le 2\n'>)} ) (C {<test_expect_success>} {(SQ <' context does not include preceding empty lines'>)} {(SQ <'\n'> <'\ttest "$(first_context_line <long_common_tail.diff.diff)" != " "\n'>)} ) (C {<check_diff>} {<changed_hello_appended>} {(SQ <'changed function plus appended function'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} { (SQ <'\n'> <'\tgrep "^ .*Begin of hello" changed_hello_appended.diff &&\n'> <'\tgrep "^[+].*Begin of first part" changed_hello_appended.diff\n'> ) } ) (C {<test_expect_success>} {(SQ <' context includes end'>)} { (SQ <'\n'> <'\tgrep "^ .*End of hello" changed_hello_appended.diff &&\n'> <'\tgrep "^[+].*End of first part" changed_hello_appended.diff\n'> ) } ) (C {<test_expect_success>} {(SQ <' context does not include other functions'>)} {(SQ <'\n'> <'\ttest $(grep -c "^[ +-].*Begin" changed_hello_appended.diff) -le 2\n'>)} ) (C {<check_diff>} {<changed_hello_dummy>} {(SQ <'changed two consecutive functions'>)}) (C {<test_expect_success>} {(SQ <' context includes begin'>)} { (SQ <'\n'> <'\tgrep "^ .*Begin of hello" changed_hello_dummy.diff &&\n'> <'\tgrep "^ .*Begin of dummy" changed_hello_dummy.diff\n'> ) } ) (C {<test_expect_success>} {(SQ <' context includes end'>)} { (SQ <'\n'> <'\tgrep "^ .*End of hello" changed_hello_dummy.diff &&\n'> <'\tgrep "^ .*End of dummy" changed_hello_dummy.diff\n'> ) } ) (C {<test_expect_success>} {(SQ <' overlapping hunks are merged'>)} {(SQ <'\n'> <'\ttest $(grep -c "^@@" changed_hello_dummy.diff) -eq 1\n'>)} ) (C {<test_done>}) ] )