From 9f3874d4549b648f54fb1274cd7ff4505491e6db Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 16 Aug 2025 21:55:36 +0200 Subject: Makefile: Add logs for tests and move to assert This provides a better log system that more clearly states what went wrong in the test files. --- tests/piece-table-delete.c | 13 +++++-------- tests/piece-table-insert.c | 11 +++++------ tests/piece-table-internals.c | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/piece-table-delete.c b/tests/piece-table-delete.c index af0017b..4d9f1dd 100644 --- a/tests/piece-table-delete.c +++ b/tests/piece-table-delete.c @@ -1,3 +1,4 @@ +#include #include #include #include "../src/piece-table-internals.h" @@ -10,30 +11,26 @@ main () piece_table_delete (pt, 0, 10); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "")) - return 1; + assert (0 == strcmp (tmp, "")); piece_table_destroy (pt); pt = piece_table_create_from_str ("0123456789", 10); piece_table_delete (pt, 0, 1); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "123456789")) - return 2; + assert (0 == strcmp (tmp, "123456789")); piece_table_destroy (pt); pt = piece_table_create_from_str ("0123456789", 10); piece_table_delete (pt, 9, 1); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "012345678")) - return 3; + assert (0 == strcmp (tmp, "012345678")); piece_table_destroy (pt); pt = piece_table_create_from_str ("0123456789", 10); piece_table_delete (pt, 7, 1); piece_table_delete (pt, 0, 1); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "12345689")) - return 4; + assert (0 == strcmp (tmp, "12345689")); piece_table_destroy (pt); return 0; diff --git a/tests/piece-table-insert.c b/tests/piece-table-insert.c index 2f2ef38..7604455 100644 --- a/tests/piece-table-insert.c +++ b/tests/piece-table-insert.c @@ -1,3 +1,4 @@ +#include #include #include #include "../src/piece-table-internals.h" @@ -10,19 +11,17 @@ main() piece_table_insert (pt, 10, "abcdefgh", 8); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "0123456789abcdefgh")) - return 1; + assert (0 == strcmp (tmp, "0123456789abcdefgh")); piece_table_insert (pt, 18, "abcdefgh", 8); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "0123456789abcdefghabcdefgh")) - return 2; + assert (0 == strcmp (tmp, "0123456789abcdefghabcdefgh")); piece_table_insert (pt, 4, "abcdefgh", 8); piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "0123abcdefgh456789abcdefghabcdefgh")) - return 3; + assert (0 == strcmp (tmp, "0123abcdefgh456789abcdefghabcdefgh")); piece_table_destroy (pt); + return 0; } diff --git a/tests/piece-table-internals.c b/tests/piece-table-internals.c index 1108271..6cf5014 100644 --- a/tests/piece-table-internals.c +++ b/tests/piece-table-internals.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -22,45 +23,44 @@ main () /** Inserting **/ /* Should add pieces... */ expected_count = 1; - if (count_pieces (pt) != expected_count) return 10; + assert (count_pieces (pt) == expected_count); piece_table_insert (pt, 10, "abcdefgh", 8); expected_count++; - if (count_pieces (pt) != expected_count) return 11; + assert (count_pieces (pt) == expected_count); /* ... but not always **/ piece_table_insert (pt, 18, "abcdefgh", 8); - if (count_pieces (pt) != expected_count) return 12; + assert (count_pieces (pt) == expected_count); /** Deleting **/ piece_table_delete (pt, 23, 3); - if (count_pieces (pt) != expected_count) return 20; + assert (count_pieces (pt) == expected_count); piece_table_delete (pt, 13, 4); expected_count++; - if (count_pieces (pt) != expected_count) return 21; + assert (count_pieces (pt) == expected_count); piece_table_delete (pt, 0, 10); expected_count--; - if (count_pieces (pt) != expected_count) return 22; + assert (count_pieces (pt) == expected_count); /** Result **/ piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "abchabcde")) - return 30; + assert (0 == strcmp (tmp, "abchabcde")); /** Optimize **/ piece_table_optimize (pt); expected_count = 1; - if (count_pieces (pt) != expected_count) return 40; + assert (count_pieces (pt) == expected_count); /** Result **/ piece_table_to_string (pt, tmp, 99); - if (strcmp (tmp, "abchabcde")) - return 50; + assert (0 == strcmp (tmp, "abchabcde")); piece_table_destroy (pt); + return 0; } -- cgit v1.2.3