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

Re: [PATCH] p5311: handle spaces in wc(1) output

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 3, 2021, 05:14 UTC
Message-ID
<YVk8SeuDIWwsrdO0@nand.local>
In-Reply-To
<a682e2c8-fecc-906e-0ff6-93de2b311d14@web.de>
On Sat, Oct 02, 2021 at 10:33:18PM +0200, René Scharfe wrote:
> Some implementations of wc(1) align their output with leading spaces,
> even when just a single number is requested, e.g. with "wc -c".  p5311
> runs all tests successfully on such a platform, but fails to aggregate
> their results and reports:

This makes sense, and makes me think that wc's platform-specific implementations are too tricky to use when we are being picky about leading spaces.

In other words, I think that your fix is absolutely correct, but I wonder if test_size should be friendlier in what it accepts, and to chomp off any leading space. So perhaps something like the below would work without any modification to p5311.

--- 8< ---
Subject: [PATCH] t/perf/aggregate.perl: tolerate leading spaces

When using `test_size` with `wc -c`, users on certain platforms can run into issues when `wc` emits leading space characters in its output, which confuses get_times.

Callers could switch to use test_file_size instead of `wc -c` (the former never prints leading space characters, so will always work with test_size regardless of platform), but this is an easy enough spot to miss that we should teach get_times to be more tolerant of the input it accepts.

Teach get_times to do just that by stripping any leading space characters.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/perf/aggregate.perl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
index 82c0df4553..575d2000cc 100755
--- a/t/perf/aggregate.perl
+++ b/t/perf/aggregate.perl
@@ -17,8 +17,8 @@ sub get_times {
 		my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
 		return ($rt, $4, $5);
 	# size
-	} elsif ($line =~ /^\d+$/) {
-		return $&;
+	} elsif ($line =~ /^\s*(\d+)$/) {
+		return $1;
 	} else {
 		die "bad input line: $line";
 	}
--
2.33.0.96.g73915697e6
Previous: René ScharfeNext: Ævar Arnfjörð Bjarmason
Message 2 of 5 in “p5311: handle spaces in wc(1) output”
  1. p5311: handle spaces in wc(1) outputRené Scharfe, Oct 2, 2021
  2. Taylor BlauOct 3, 2021
  3. Ævar Arnfjörð BjarmasonOct 3, 2021
  4. Junio C HamanoOct 4, 2021
  5. Jeff KingOct 4, 2021

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.