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

[PATCH 1/2] t-prio-queue: shorten array index message

From
René Scharfe <l.s.r@web.de>
Date
Mar 16, 2024, 20:45 UTC
Message-ID
<197f5ac9-7257-4caa-aa9e-041016c787f7@web.de>

If we get an unexpected result, the prio-queue unit test reports it like this:

 # check "result[j++] == show(get)" failed at t/unit-tests/t-prio-queue.c:43
 #    left: 5
 #   right: 1
 # failed at result[] index 0

That last line repeats "failed" and "result" from the first line. Shorten it to resemble a similar one in t-ctype and also remove the incrementation from the first line to avoid possible distractions from the message of which comparison went wrong where:

 # check "result[j] == show(get)" failed at t/unit-tests/t-prio-queue.c:43
 #    left: 5
 #   right: 1
 #       j: 0
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/unit-tests/t-prio-queue.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c
index d78b002f9e..616d0fc86f 100644
--- a/t/unit-tests/t-prio-queue.c
+++ b/t/unit-tests/t-prio-queue.c
@@ -31,16 +31,18 @@ static void test_prio_queue(int *input, int *result, size_t input_size)
 			get = prio_queue_get(&pq);
 			if (!check(peek == get))
 				return;
-			if(!check_int(result[j++], ==, show(get)))
-				test_msg("failed at result[] index %d", j-1);
+			if (!check_int(result[j], ==, show(get)))
+				test_msg("      j: %d", j);
+			j++;
 			break;
 		case DUMP:
 			while ((peek = prio_queue_peek(&pq))) {
 				get = prio_queue_get(&pq);
 				if (!check(peek == get))
 					return;
-				if(!check_int(result[j++], ==, show(get)))
-					test_msg("failed at result[] index %d", j-1);
+				if (!check_int(result[j], ==, show(get)))
+					test_msg("      j: %d", j);
+				j++;
 			}
 			break;
 		case STACK:
--
2.44.0
Next: René Scharfe
Message 1 of 3 in “t-prio-queue: shorten array index message”
  1. 1/2 t-prio-queue: shorten array index messageRené Scharfe, Mar 16, 2024
  2. 2/2 t-prio-queue: check result array boundsRené Scharfe, Mar 16, 2024
  3. Junio C HamanoMar 18, 2024

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.