Thread (47 messages) 47 messages, 4 authors, 2021-12-11

Re: [PATCH 09/19] tests: use test_write_lines() to generate line-oriented output

From: Jeff King <hidden>
Date: 2021-12-10 09:22:46

On Thu, Dec 09, 2021 at 12:11:05AM -0500, Eric Sunshine wrote:
Take advantage of test_write_lines() to generate line-oriented output
rather than using for-loops or a series of `echo` commands. Not only is
test_write_lines() a natural fit for such a task, but there is less
opportunity for a broken &&-chain.
Makes sense. A few of these append like this:
-	for w in Some extra lines here; do echo $w; done >>one &&
+	test_write_lines Some extra lines here >>one &&
which made me wonder if the original really wanted to append, or if they
meant:

  for w in Some extra lines here; do echo $w >>one; done

in the first place. In which case you could write ">one". But in the
cases I peeked at, they really are appending to a file that already
existed. And at any rate, your conversions are all faithful to the
original, which is the right thing to do to avoid introducing bugs.
 test_expect_success 'color new trailing blank lines' '
-	{ echo a; echo b; echo; echo; } >x &&
+	test_write_lines a b "" "" >x &&
 	git add x &&
-	{ echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
+	test_write_lines a "" "" "" c "" "" "" "" >x &&
Some of these I think might be more readable as here-docs. But I think
keeping to the minimal change here makes sense (and I admit I do not
overly care much either way; it was just on my mind from the last
patch).

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help