]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5411: new helper filter_out_user_friendly_and_stable_output
authorJiang Xin <worldhello.net@gmail.com>
Wed, 11 Nov 2020 11:32:00 +0000 (19:32 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Nov 2020 20:46:55 +0000 (12:46 -0800)
New helper `filter_out_user_friendly_and_stable_output` will call
common helpr function `make_user_friendly_and_stable_output` and use
additional arguments to filter out messages for specific test cases.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5411/common-functions.sh
t/t5411/test-0000-standard-git-push.sh
t/t5411/test-0001-standard-git-push--porcelain.sh

index 521a3477108b9be56ed31f272b46ddcbca1db271..344d13f61a55cb57615bd56a1ada6e22b955829c 100644 (file)
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
        sed \
                -e "s/  *\$//" \
-               -e "s/   */ /g" \
+               -e "s/  */ /g" \
                -e "s/'/\"/g" \
                -e "s/  /    /g" \
                -e "s/$A/<COMMIT-A>/g" \
@@ -54,3 +54,8 @@ make_user_friendly_and_stable_output () {
                -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
                -e "/^error: / d"
 }
+
+filter_out_user_friendly_and_stable_output () {
+       make_user_friendly_and_stable_output |
+               sed -n ${1+"$@"}
+}
index 2b04b4936743590796f687c893c70ce0253a6e08..47b058af7ede47e7c8c3bdc2a5238c24e9edbec4 100644 (file)
@@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
                main \
                $B:refs/heads/next \
                >out 2>&1 &&
-       make_user_friendly_and_stable_output <out |
-               sed -n \
-                       -e "/^To / { s/   */ /g; p; }" \
-                       -e "/^ ! / { s/   */ /g; p; }" \
-                       >actual &&
+       filter_out_user_friendly_and_stable_output \
+               -e "/^To / { p; }" \
+               -e "/^ ! / { p; }" \
+               <out >actual &&
        cat >expect <<-EOF &&
        To <URL/of/upstream.git>
         ! [rejected] main -> main (non-fast-forward)
index 747307f8da746f14a7ea83863331948ad2967610..bbead12bbb48f5701d041e24954113795e2b90a2 100644 (file)
@@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
                main \
                $B:refs/heads/next \
                >out 2>&1 &&
-       make_user_friendly_and_stable_output <out |
-               sed -n \
-                       -e "s/^# GETTEXT POISON #//" \
-                       -e "/^To / { s/   */ /g; p; }" \
-                       -e "/^! / { s/   */ /g; p; }" \
-                       >actual &&
+       filter_out_user_friendly_and_stable_output \
+               -e "s/^# GETTEXT POISON #//" \
+               -e "/^To / { p; }" \
+               -e "/^! / { p; }" \
+               <out >actual &&
        cat >expect <<-EOF &&
        To <URL/of/upstream.git>
-       ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
-       ! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed)
+       !    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
+       !    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
        EOF
        test_cmp expect actual &&
        git -C "$upstream" show-ref >out &&