Re: [PATCH 15/20] t/lib-t6000: refactor `name_from_description()` to not depend on Perl
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 20, 2025, 19:41 UTC
- Message-ID
- <CAPig+cTE1K6bt-4v9sv9ywF7wwc5Od8s5scnLsvYPFGBU5HDHg@mail.gmail.com>
- In-Reply-To
- <20250320-b4-pks-t-perlless-v1-15-b1eefe27ac55@pks.im>
On Thu, Mar 20, 2025 at 5:37 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 26 quoted lines
> The `name_from_description()` test helper uses Perl to munge a given
> description and convert it into a name. Refactor it to instead use a
> combination of sed(1) and tr(1) so that we drop PERL_TEST_HELPERS
> prerequisites in users of this library.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> diff --git a/t/lib-t6000.sh b/t/lib-t6000.sh
> @@ -109,13 +109,12 @@ check_output () {
> # All alphanums translated into -'s which are then compressed and stripped
> # from front and back.
> name_from_description () {
> - perl -pe '
> - s/[^A-Za-z0-9.]/-/g;
> - s/-+/-/g;
> - s/-$//;
> - s/^-//;
> - y/A-Z/a-z/;
> - '
> + sed \
> + -e 's/[^A-Za-z0-9.]/-/g' \
> + -e 's/--*/-/g' \
> + -e 's/-$//' \
> + -e 's/^-//' |
> + tr 'A-Z' 'a-z'
> }Can't you just use sed's `y//` function directly instead of having to separately invoke a `tr` command?