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

Re: [PATCH] test-ctype: check EOF

From
Junio C Hamano <gitster@pobox.com>
Date
May 1, 2023, 15:23 UTC
Message-ID
<xmqqedo0849m.fsf@gitster.g>
In-Reply-To
<cbc7feb9-7e15-77e2-b3e9-1fa194b4d4fb@web.de>
René Scharfe <l.s.r@web.de> writes:
> The character classifiers are supposed to handle EOF, a negative integer
> value.  It isn't part of any character class.  Extend the ctype tests to
> cover it.
The goal makes sense.
Show 22 quoted lines
> -static void report_error(const char *class, int ch)
> +static void test(int ch, const char *class, int expect, int actual)
>  {
> +	if (actual == expect)
> +		return;
>  	printf("%s classifies char %d (0x%02x) wrongly\n", class, ch, ch);
>  	rc = 1;
>  }
> @@ -24,9 +26,9 @@ static int is_in(const char *s, int ch)
>  #define TEST_CLASS(t,s) {			\
>  	int i;					\
>  	for (i = 0; i < 256; i++) {		\
> -		if (is_in(s, i) != t(i))	\
> -			report_error(#t, i);	\
> +		test(i, #t, is_in(s, i), t(i));	\
>  	}					\
> +	test(EOF, #t, 0, t(EOF));		\
>  }
>
>  #define DIGIT "0123456789"
> --
> 2.40.1

I am a bit torn on the conversion from report_error() to test(), as the only "test"-y thing the updated function does is to compare two of its parameters. It still is mostly about reporting an error when something goes wrong. In other words, the added change could have been just

	if (t(EOF) != 0)
		report_error(#t, EOF);
after the loop, I think.

The only thing that I am not entirely happy with the end result is the name of the function, and not how the caller and the callee divides their work, so it is so miniscule a thing that it won't be worth our collective time to bikeshed it further.

Let's take it as-is.  Thanks.
Previous: René ScharfeNext: René Scharfe
Message 2 of 3 in “test-ctype: check EOF”
  1. test-ctype: check EOFRené Scharfe, Apr 30, 2023
  2. Junio C HamanoMay 1, 2023
  3. René ScharfeMay 1, 2023

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.