trailer: add tests for commands in config file

And add a few other tests for some special cases. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Oct 13, 2014 at 20:16 UTC b9384ff34e18890c6b5aab91669094f0a3b411ae
1 file changed +125
t/t7513-interpret-trailers.sh
+125
@@ -735,4 +735,129 @@ test_expect_success 'default "where" is now "after"' '
735 test_cmp expected actual
736 '
737
738 +test_expect_success 'with simple command' '
739 + git config trailer.sign.key "Signed-off-by: " &&
740 + git config trailer.sign.where "after" &&
741 + git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
742 + git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
743 + cat complex_message_body >expected &&
744 + sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
745 + Fixes: Z
746 + Acked-by= Z
747 + Reviewed-by:
748 + Signed-off-by: Z
749 + Signed-off-by: A U Thor <author@example.com>
750 + EOF
751 + git interpret-trailers --trailer "review:" --trailer "fix=22" \
752 + <complex_message >actual &&
753 + test_cmp expected actual
754 +'
755 +
756 +test_expect_success 'with command using commiter information' '
757 + git config trailer.sign.ifExists "addIfDifferent" &&
758 + git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
759 + cat complex_message_body >expected &&
760 + sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
761 + Fixes: Z
762 + Acked-by= Z
763 + Reviewed-by:
764 + Signed-off-by: Z
765 + Signed-off-by: C O Mitter <committer@example.com>
766 + EOF
767 + git interpret-trailers --trailer "review:" --trailer "fix=22" \
768 + <complex_message >actual &&
769 + test_cmp expected actual
770 +'
771 +
772 +test_expect_success 'with command using author information' '
773 + git config trailer.sign.key "Signed-off-by: " &&
774 + git config trailer.sign.where "after" &&
775 + git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
776 + git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
777 + cat complex_message_body >expected &&
778 + sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
779 + Fixes: Z
780 + Acked-by= Z
781 + Reviewed-by:
782 + Signed-off-by: Z
783 + Signed-off-by: A U Thor <author@example.com>
784 + EOF
785 + git interpret-trailers --trailer "review:" --trailer "fix=22" \
786 + <complex_message >actual &&
787 + test_cmp expected actual
788 +'
789 +
790 +test_expect_success 'setup a commit' '
791 + echo "Content of the first commit." > a.txt &&
792 + git add a.txt &&
793 + git commit -m "Add file a.txt"
794 +'
795 +
796 +test_expect_success 'with command using $ARG' '
797 + git config trailer.fix.ifExists "replace" &&
798 + git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
799 + FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
800 + cat complex_message_body >expected &&
801 + sed -e "s/ Z\$/ /" >>expected <<-EOF &&
802 + Fixes: $FIXED
803 + Acked-by= Z
804 + Reviewed-by:
805 + Signed-off-by: Z
806 + Signed-off-by: A U Thor <author@example.com>
807 + EOF
808 + git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
809 + <complex_message >actual &&
810 + test_cmp expected actual
811 +'
812 +
813 +test_expect_success 'with failing command using $ARG' '
814 + git config trailer.fix.ifExists "replace" &&
815 + git config trailer.fix.command "false \$ARG" &&
816 + cat complex_message_body >expected &&
817 + sed -e "s/ Z\$/ /" >>expected <<-EOF &&
818 + Fixes: Z
819 + Acked-by= Z
820 + Reviewed-by:
821 + Signed-off-by: Z
822 + Signed-off-by: A U Thor <author@example.com>
823 + EOF
824 + git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
825 + <complex_message >actual &&
826 + test_cmp expected actual
827 +'
828 +
829 +test_expect_success 'with empty tokens' '
830 + git config --unset trailer.fix.command &&
831 + cat >expected <<-EOF &&
832 +
833 + Signed-off-by: A U Thor <author@example.com>
834 + EOF
835 + git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
836 + EOF
837 + test_cmp expected actual
838 +'
839 +
840 +test_expect_success 'with command but no key' '
841 + git config --unset trailer.sign.key &&
842 + cat >expected <<-EOF &&
843 +
844 + sign: A U Thor <author@example.com>
845 + EOF
846 + git interpret-trailers >actual <<-EOF &&
847 + EOF
848 + test_cmp expected actual
849 +'
850 +
851 +test_expect_success 'with no command and no key' '
852 + git config --unset trailer.review.key &&
853 + cat >expected <<-EOF &&
854 +
855 + review: Junio
856 + sign: A U Thor <author@example.com>
857 + EOF
858 + git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
859 + EOF
860 + test_cmp expected actual
861 +'
862 +
863 test_done