git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] test-lib: teach test_seq the -f option

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 24, 2025, 06:22 UTC
Message-ID
<CAPig+cQNWVd7M5pe0te9os3NRrjfBSSaUZjUXKX8RUdTk50SFw@mail.gmail.com>
In-Reply-To
<20250623105625.GB654412@coredump.intra.peff.net>
On Mon, Jun 23, 2025 at 6:56 AM Jeff King <peff@peff.net> wrote:
Show 23 quoted lines
> The "seq" tool has a "-f" option to produce printf-style formatted
> lines. Let's teach our test_seq helper the same trick. This lets us get
> rid of some shell loops in test snippets (which are particularly verbose
> in our test suite because we have to "|| return 1" to keep the &&-chain
> going).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> diff --git a/t/t0612-reftable-jgit-compatibility.sh b/t/t0612-reftable-jgit-compatibility.sh
> @@ -112,14 +112,11 @@ test_expect_success 'JGit can read multi-level index' '
> -               awk "
> -                   BEGIN {
> -                       print \"start\";
> -                       for (i = 0; i < 10000; i++)
> -                           printf \"create refs/heads/branch-%d HEAD\n\", i;
> -                       print \"commit\";
> -                   }
> -               " >input &&
> +               {
> +                       echo start &&
> +                       test_seq -f "create refs/heads/branch-%d HEAD" 10000 &&
> +                       echo commit
> +               } >input &&

I had suggested[1] an effectively equivalent change to Patrick for a couple tests in the nearby t0610, but he rejected[2] the idea due to the pure-shell version being significantly slower than the `awk` version.

Pondering his response today, I wondered if it would make sense to replace our pure-shell `test_seq` with an implementation via `awk`, however, if most of our sequence vend only a small set of numbers, then the startup cost of `awk` would probably swamp any savings, especially on Windows where process startup is extremely slow. Taking that into account, I further wondered if we could see an overall win by taking a hybrid approach in which we employ the pure-shell version if vending a small set of numbers, but fall over to an `awk` version if vending a lot of numbers, especially as in the test above or the tests in t0610. Anyhow, food for thought, or not, if you're not hungry for thought food.

[1]: https://lore.kernel.org/git/CAPig+cSC3zdur1fCsa7RMNZDcgUK4pUGKb22tpgdANxR6OxNMA@mail.gmail.com/ [2]: https://lore.kernel.org/git/Z-FUNgmY9hTsnzds@pks.im/

Previous: Todd ZullingerNext: Jeff King
Message 13 of 14 in “test_seq format option”
  1. 0/2 test_seq format optionJeff King, Jun 23, 2025
  2. 1/2 t7422: replace confusing printf with echoJeff King, Jun 23, 2025
  3. Eric SunshineJun 23, 2025
  4. Jeff KingJun 24, 2025
  5. 2/2 test-lib: teach test_seq the -f optionJeff King, Jun 23, 2025
  6. Junio C HamanoJun 23, 2025
  7. Justin ToblerJun 23, 2025
  8. 3/2 test-lib: document test_seq's "-f" optionJeff King, Jun 24, 2025
  9. Justin ToblerJun 25, 2025
  10. Todd ZullingerJun 23, 2025
  11. Jeff KingJun 24, 2025
  12. Todd ZullingerJun 24, 2025
  13. Eric SunshineJun 24, 2025
  14. Jeff KingJun 24, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.