Message ID | 20201110120135.42025-1-zhiyou.jx@alibaba-inc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3,1/2] t5411: refactor make_user_friendly_and_stable_output | expand |
Jiang Xin <worldhello.net@gmail.com> writes: > diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh > index 521a347710..b7cca2d8fb 100644 > --- a/t/t5411/common-functions.sh > +++ b/t/t5411/common-functions.sh > @@ -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" \ > @@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () { > -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ > -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ > -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ > - -e "/^error: / d" > + -e "/^error: / d" | \ > + if test $# -eq 0 > + then > + cat > + else > + sed ${1+"$@"} > + fi > } I may have suggested it, but looking at this implementation I'd have to say it is not worth the extra process here. The only reason why I made the suggestion was that way we can make the single "sed" invocation to do what we want. If you need custom output for just two tests in 5411-0000, define the custom one that wraps make_user_friendly_and_stable_output in that single script like so: filter_out_remote_messages () { make_user_friendly_and_stable_output | sed -n -e ... } and then use that ... > diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh > index 2b04b49367..b3af3f59b0 100644 > --- a/t/t5411/test-0000-standard-git-push.sh > +++ b/t/t5411/test-0000-standard-git-push.sh > @@ -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 && > + make_user_friendly_and_stable_output -n \ > + -e "/^To / { p; }" \ > + -e "/^ ! / { p; }" \ > + <out >actual && ... perhaps like filter_out_remote_messages <out >actual && here? > diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh > index 747307f8da..16ff2d5666 100644 > --- a/t/t5411/test-0001-standard-git-push--porcelain.sh > +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh > @@ -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 && > + make_user_friendly_and_stable_output -n \ > + -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 &&
Junio C Hamano <gitster@pobox.com> 于2020年11月11日周三 上午4:51写道: > > Jiang Xin <worldhello.net@gmail.com> writes: > > > diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh > > index 521a347710..b7cca2d8fb 100644 > > --- a/t/t5411/common-functions.sh > > +++ b/t/t5411/common-functions.sh > > @@ -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" \ > > @@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () { > > -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ > > -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ > > -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ > > - -e "/^error: / d" > > + -e "/^error: / d" | \ > > + if test $# -eq 0 > > + then > > + cat > > + else > > + sed ${1+"$@"} > > + fi > > } > > I may have suggested it, but looking at this implementation I'd have > to say it is not worth the extra process here. The only reason why > I made the suggestion was that way we can make the single "sed" > invocation to do what we want. > > If you need custom output for just two tests in 5411-0000, define > the custom one that wraps make_user_friendly_and_stable_output in > that single script like so: > > filter_out_remote_messages () { > make_user_friendly_and_stable_output | > sed -n -e ... > } > > and then use that ... Will add new helper function `filter_out_user_friendly_and_stable_output` like this, and use it for 5411-0000, 5411-0001, 5411-0013 and 5411-0014.
diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh index 521a347710..b7cca2d8fb 100644 --- a/t/t5411/common-functions.sh +++ b/t/t5411/common-functions.sh @@ -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" \ @@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () { -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \ -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \ -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ - -e "/^error: / d" + -e "/^error: / d" | \ + if test $# -eq 0 + then + cat + else + sed ${1+"$@"} + fi } diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh index 2b04b49367..b3af3f59b0 100644 --- a/t/t5411/test-0000-standard-git-push.sh +++ b/t/t5411/test-0000-standard-git-push.sh @@ -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 && + make_user_friendly_and_stable_output -n \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && cat >expect <<-EOF && To <URL/of/upstream.git> ! [rejected] main -> main (non-fast-forward) diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh index 747307f8da..16ff2d5666 100644 --- a/t/t5411/test-0001-standard-git-push--porcelain.sh +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh @@ -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 && + make_user_friendly_and_stable_output -n \ + -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 &&
Common function `make_user_friendly_and_stable_output()` can take additional arguments to format messages for special cases. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> --- t/t5411/common-functions.sh | 10 ++++++++-- t/t5411/test-0000-standard-git-push.sh | 9 ++++----- t/t5411/test-0001-standard-git-push--porcelain.sh | 15 +++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-)