summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--tests/piece-table-delete.c13
-rw-r--r--tests/piece-table-insert.c11
-rw-r--r--tests/piece-table-internals.c22
4 files changed, 29 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index b900387..5edae85 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,14 @@ clean:
$(TEST_FILES): $(TARGET) $(TEST_SOURCES) $(HEADERS)
@printf "Running %-40s%s " '`$@`'
@$(CC) $(CFLAGS) -o $@ $(addsuffix .c, $@) $(OBJ)
- @if ./$@ ; then printf "PASS\n";else printf "FAIL: exit value: %d\n" $$?; fi
+ @result=$$(./$@ 2>&1); \
+ ret=$$?; \
+ printf "Exit value: %s\n%s" "$$ret" "$$result" >$@.log; \
+ if test $$ret -eq 0 ; then \
+ printf "\e[0;32mPASS\e[0m\n";\
+ else\
+ printf "\e[0;31mFAIL\e[0m\n";\
+ fi
check: test
test: $(TEST_FILES)
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 <assert.h>
#include <stdio.h>
#include <string.h>
#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 <assert.h>
#include <string.h>
#include <stdlib.h>
#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 <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -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;
}