subtree test: simplify preparation of expected results

This mixture of quoting, pipes, and here-docs to produce expected results in shell variables is difficult to follow. Simplify by using simpler constructs that write output to files instead. Noticed because without this patch, t/chainlint is not able to understand the script in order to validate that its subshells use an unbroken &&-chain, causing "make -C contrib/subtree test" to fail with error: bug in the test script: broken &&-chain or run-away HERE-DOC: in t7900.21. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Jul 30, 2018 at 12:07 UTC 6a8ad880f02e8399c2fcb4aec0d42fb6e4287ebb
1 file changed +30 -89
contrib/subtree/t/t7900-subtree.sh
+30 -89
@@ -540,26 +540,10 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub
540 git fetch .. subproj-br &&
541 git merge FETCH_HEAD &&
542
543 - chks="sub1
544 -sub2
545 -sub3
546 -sub4" &&
547 - chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
548 -$chks
549 -TXT
550 -) &&
551 - chkms="main-sub1
552 -main-sub2
553 -main-sub3
554 -main-sub4" &&
555 - chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
556 -$chkms
557 -TXT
558 -) &&
559 -
560 - subfiles=$(git ls-files) &&
561 - check_equal "$subfiles" "$chkms
562 -$chks"
543 + test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
544 + sub1 sub2 sub3 sub4 >expect &&
545 + git ls-files >actual &&
546 + test_cmp expect actual
547 )
548 '
549
@@ -606,25 +590,11 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t
590 git fetch .. subproj-br &&
591 git merge FETCH_HEAD &&
592
609 - chks="sub1
610 -sub2
611 -sub3
612 -sub4" &&
613 - chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
614 -$chks
615 -TXT
616 -) &&
617 - chkms="main-sub1
618 -main-sub2
619 -main-sub3
620 -main-sub4" &&
621 - chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
622 -$chkms
623 -TXT
624 -) &&
625 - allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
626 - check_equal "$allchanges" "$chkms
627 -$chks"
593 + test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
594 + sub1 sub2 sub3 sub4 >expect &&
595 + git log --name-only --pretty=format:"" >log &&
596 + sort <log | sed "/^\$/ d" >actual &&
597 + test_cmp expect actual
598 )
599 '
600
@@ -675,29 +645,16 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai
645 cd "$subtree_test_count" &&
646 git subtree pull --prefix="sub dir" ./"sub proj" master &&
647
678 - chkm="main1
679 -main2" &&
680 - chks="sub1
681 -sub2
682 -sub3
683 -sub4" &&
684 - chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
685 -$chks
686 -TXT
687 -) &&
688 - chkms="main-sub1
689 -main-sub2
690 -main-sub3
691 -main-sub4" &&
692 - chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
693 -$chkms
694 -TXT
695 -) &&
696 - mainfiles=$(git ls-files) &&
697 - check_equal "$mainfiles" "$chkm
698 -$chkms_sub
699 -$chks_sub"
700 -)
648 + test_write_lines main1 main2 >chkm &&
649 + test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
650 + sed "s,^,sub dir/," chkms >chkms_sub &&
651 + test_write_lines sub1 sub2 sub3 sub4 >chks &&
652 + sed "s,^,sub dir/," chks >chks_sub &&
653 +
654 + cat chkm chkms_sub chks_sub >expect &&
655 + git ls-files >actual &&
656 + test_cmp expect actual
657 + )
658 '
659
660 next_test
@@ -748,37 +705,21 @@ test_expect_success 'make sure each filename changed exactly once in the entire
705 cd "$subtree_test_count" &&
706 git subtree pull --prefix="sub dir" ./"sub proj" master &&
707
751 - chkm="main1
752 -main2" &&
753 - chks="sub1
754 -sub2
755 -sub3
756 -sub4" &&
757 - chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
758 -$chks
759 -TXT
760 -) &&
761 - chkms="main-sub1
762 -main-sub2
763 -main-sub3
764 -main-sub4" &&
765 - chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
766 -$chkms
767 -TXT
768 -) &&
708 + test_write_lines main1 main2 >chkm &&
709 + test_write_lines sub1 sub2 sub3 sub4 >chks &&
710 + test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
711 + sed "s,^,sub dir/," chkms >chkms_sub &&
712
713 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
714 # changes that were split into their own history. And "sub dir"/sub?? never
715 # change, since they were *only* changed in the subtree branch.
773 - allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
774 - expected=''"$(cat <<TXT | sort
775 -$chkms
776 -$chkm
777 -$chks
778 -$chkms_sub
779 -TXT
780 -)"'' &&
781 - check_equal "$allchanges" "$expected"
716 + git log --name-only --pretty=format:"" >log &&
717 + sort <log >sorted-log &&
718 + sed "/^$/ d" sorted-log >actual &&
719 +
720 + cat chkms chkm chks chkms_sub >expect-unsorted &&
721 + sort expect-unsorted >expect &&
722 + test_cmp expect actual
723 )
724 '
725