t5536: simplify checking of messages output to stderr

Commit 2071e05ed2 ("t5536: new test of refspec conflicts when fetching", 2013-10-30), introduced the verify_stderr() function which was used to verify that certain fatal/warning messages were issued by a given git command. In addition, verify_stderr() would filter a specific "fatal: The remote end hung up unexpectedly" message, which may, or may not, be present (depending on the relative timing of the git-fetch and git-upload-pack processes). The verify_stderr() function has seen several modifications, which has introduced a couple of minor problems. For example, commit 1edbaac3bb ("tests: use test_i18n* functions to suppress false positives", 2016-06-17) introduced an inappropriate test_i18ngrep call and commit f096e6e826 ("fetch: improve the error messages emitted for conflicting refspecs", 2013-10-30) included an ineffective invocation of sort at the end of a grep pipeline. Instead of fixing these minor problems in verify_stderr(), we take the simpler approach of directly searching the error file, using test_i18ngrep, for the specific message(s) we expect. (The only minor downside is that we would not notice any new messages). Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 24, 2018 at 01:22 UTC 51b74b57aec50cf59f40aa1ec85ae72f9a35b32f
1 file changed +4 -18
t/t5536-fetch-conflicts.sh
+4 -18
@@ -18,14 +18,6 @@ setup_repository () {
18 )
19 }
20
21 -verify_stderr () {
22 - cat >expected &&
23 - # We're not interested in the error
24 - # "fatal: The remote end hung up unexpectedly":
25 - test_i18ngrep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort &&
26 - test_i18ncmp expected actual
27 -}
28 -
21 test_expect_success 'setup' '
22 git commit --allow-empty -m "Initial" &&
23 git branch branch1 &&
@@ -48,9 +40,7 @@ test_expect_success 'fetch conflict: config vs. config' '
40 "+refs/heads/branch2:refs/remotes/origin/branch1" && (
41 cd ccc &&
42 test_must_fail git fetch origin 2>error &&
51 - verify_stderr <<-\EOF
52 - fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
53 - EOF
43 + test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
44 )
45 '
46
@@ -77,9 +67,7 @@ test_expect_success 'fetch conflict: arg vs. arg' '
67 test_must_fail git fetch origin \
68 refs/heads/*:refs/remotes/origin/* \
69 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
80 - verify_stderr <<-\EOF
81 - fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
82 - EOF
70 + test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
71 )
72 '
73
@@ -90,10 +78,8 @@ test_expect_success 'fetch conflict: criss-cross args' '
78 git fetch origin \
79 refs/heads/branch1:refs/remotes/origin/branch2 \
80 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
93 - verify_stderr <<-\EOF
94 - warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2
95 - warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1
96 - EOF
81 + test_i18ngrep "warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2" error &&
82 + test_i18ngrep "warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1" error
83 )
84 '
85