Re: [PATCH 1/2] test-lib: allow test snippets as here-docs
- From
Jeff King <peff@peff.net>
- Date
- Jul 6, 2024, 05:23 UTC
- Message-ID
- <20240706052317.GA698153@coredump.intra.peff.net>
- In-Reply-To
- <CAPig+cQna9nDzr9it2=VN-4_hUctG+t4=97s5h9KqmNHS=cuuw@mail.gmail.com>
On Tue, Jul 02, 2024 at 05:59:46PM -0400, Eric Sunshine wrote:
Show 9 quoted lines
> > diff --git a/t/Makefile b/t/Makefile > > @@ -106,18 +106,28 @@ clean: clean-except-prove-cache > > + for i in $$(grep -L "'" $(CHAINLINTTESTS_SRC)); do \ > > + echo "test_expect_success '$$i' - <<\\\\EOT" && \ > > + sed -e '/^# LINT: /d' $$i && \ > > + echo "EOT"; \ > > + done >>'$(CHAINLINTTMP_SQ)'/tests && \ > > Unfortunately, `grep -L` is not POSIX.
Yeah, this was just for illustration. Even if it were portable, I don't think it's a good direction. :)
Show 17 quoted lines
> > 1. Move the test_expect_success wrapping lines into each
> > chainlint/*.test file. It's a little bit of extra boilerplate, but
> > it makes them a bit easier to reason about on their own.
>
> Yes. This is exactly what I had in mind for moving forward. It's just
> a one-time noise-patch cost but gives us much more flexibility in
> terms of testing.
>
> It also makes spot-testing the chainlint self-test files much simpler.
> We would be able to do this:
>
> ./chainlint.pl chainlint/block.test
>
> rather than much more painful:
>
> { echo "test_expect_success foo '" && cat chainlint/block.test &&
> echo "'"; } >dummy && ./chainlint.pl dummy; rm dummyOh, nice. Having just written new chainlint tests, this made checking them _way_ easier.
Show 6 quoted lines
> > 2. Add a few new tests that use here-docs with a few variations
> > ("<<EOT", "<<\EOT", probably a here-doc inside the test here-doc).
> >
> > Does that sound OK to you?
>
> Absolutely. I'm very much in favor of these changes.Great! I have patches which I'll send out in a moment.
-Peff