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
Todd Zullinger <tmz@pobox.com>
Date
Jun 24, 2025, 13:42 UTC
Message-ID
<aFqrXMHStEJXx8e5@teonanacatl.net>
In-Reply-To
<20250624101651.GC636332@coredump.intra.peff.net>
Jeff King wrote:
Show 16 quoted lines
> On Mon, Jun 23, 2025 at 01:27:07PM -0400, Todd Zullinger wrote:
>> I don't know whether it's worth the extra code or not.  I
>> just wondered about how it would fail in the face of a minor
>> typo.  It certainly should cause any test to fail if it were
>> to output 1 instead of the intended format string, so it's
>> arguably fine as-is.
> 
> Hmm, maybe. I notice that "seq" itself does this (though it did surprise
> me). I think there it is actually doing the "%" interpolation itself (to
> avoid memory errors by feeding arbitrary strings to printf functions),
> so it's easy to do.
> 
> In our case, we can rely on the shell printf to do something sensible if
> fed garbage. And because we're not parsing ourselves, a pattern like you
> have above isn't totally accurate (e.g., consider what it would with
> "%%d"). But it probably would be enough to catch typos.

Parsing it fully felt like overkill, and a good bit more code to do it well. So that was me being lazy. :)

Show 6 quoted lines
> It would also disallow:
> 
>   test_seq -f "same line" 50
> 
> to produce repeated lines, though I don't know how valuable that would
> be. So I dunno.

I can see someone using it that way, like a cheap version of the yes command.

Show 6 quoted lines
> If people are going to use "-f%d", I think we'd be better off making it
> work than trying to complain about it. But I was hoping we could just
> keep things simple and stupid, given the limited audience.
> 
> So my inclination is to leave the sharp edges and see if anybody gets
> cut, but it's possible that I'm just being lazy.

Sounds good to me. As you say, it's not going to be exposed to "normal" users.

The worst thing it can do is allow a test to pass which shouldn't -- and that's by far the least likely way for the (not very) sharp edges to cut us.

-- 
Todd
Previous: Jeff KingNext: Eric Sunshine
Message 12 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.