| ... | ... |
@@ -6,17 +6,16 @@ |
| 6 | 6 |
|
| 7 | 7 |
int testsrun = 0, testsfailed = 0, assertionsrun = 0; |
| 8 | 8 |
|
| 9 |
-#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);return -1;}
|
|
| 9 |
+#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);testsfailed++;return;}
|
|
| 10 | 10 |
|
| 11 | 11 |
#define assert_streq(a, b) assert(!strcmp(a, b)) |
| 12 | 12 |
|
| 13 |
-void runtest(int (*test)()){
|
|
| 13 |
+void runtest(void (*test)()){
|
|
| 14 | 14 |
testsrun++; |
| 15 |
- if(test()) |
|
| 16 |
- testsfailed++; |
|
| 15 |
+ test(); |
|
| 17 | 16 |
} |
| 18 | 17 |
|
| 19 |
-int test_match(){
|
|
| 18 |
+void test_match(){
|
|
| 20 | 19 |
assert(has_match("a", "a"));
|
| 21 | 20 |
assert(has_match("a", "ab"));
|
| 22 | 21 |
assert(has_match("a", "ba"));
|
| ... | ... |
@@ -30,11 +29,9 @@ int test_match(){
|
| 30 | 29 |
/* match when query is empty */ |
| 31 | 30 |
assert(has_match("", ""));
|
| 32 | 31 |
assert(has_match("", "a"));
|
| 33 |
- |
|
| 34 |
- return 0; |
|
| 35 | 32 |
} |
| 36 | 33 |
|
| 37 |
-int test_scoring(){
|
|
| 34 |
+void test_scoring(){
|
|
| 38 | 35 |
/* App/Models/Order is better than App/MOdels/zRder */ |
| 39 | 36 |
assert(match("amor", "app/models/order") > match("amor", "app/models/zrder"));
|
| 40 | 37 |
|
| ... | ... |
@@ -59,21 +56,17 @@ int test_scoring(){
|
| 59 | 56 |
/* Prefer shorter matches */ |
| 60 | 57 |
assert(match("abc", " a b c ") > match("abc", " a b c "));
|
| 61 | 58 |
assert(match("abc", " a b c ") > match("abc", " a b c "));
|
| 62 |
- |
|
| 63 |
- return 0; |
|
| 64 | 59 |
} |
| 65 | 60 |
|
| 66 |
-int test_positions_1(){
|
|
| 61 |
+void test_positions_1(){
|
|
| 67 | 62 |
size_t positions[3]; |
| 68 | 63 |
match_positions("amo", "app/models/foo", positions);
|
| 69 | 64 |
assert(positions[0] == 0); |
| 70 | 65 |
assert(positions[1] == 4); |
| 71 | 66 |
assert(positions[2] == 5); |
| 72 |
- |
|
| 73 |
- return 0; |
|
| 74 | 67 |
} |
| 75 | 68 |
|
| 76 |
-int test_positions_2(){
|
|
| 69 |
+void test_positions_2(){
|
|
| 77 | 70 |
/* |
| 78 | 71 |
* We should prefer matching the 'o' in order, since it's the beginning |
| 79 | 72 |
* of a word. |
| ... | ... |
@@ -83,39 +76,31 @@ int test_positions_2(){
|
| 83 | 76 |
assert(positions[0] == 0); |
| 84 | 77 |
assert(positions[1] == 4); |
| 85 | 78 |
assert(positions[2] == 11); |
| 86 |
- |
|
| 87 |
- return 0; |
|
| 88 | 79 |
} |
| 89 | 80 |
|
| 90 |
-int test_positions_3(){
|
|
| 81 |
+void test_positions_3(){
|
|
| 91 | 82 |
size_t positions[2]; |
| 92 | 83 |
match_positions("as", "tags", positions);
|
| 93 | 84 |
assert(positions[0] == 1); |
| 94 | 85 |
assert(positions[1] == 3); |
| 95 |
- |
|
| 96 |
- return 0; |
|
| 97 | 86 |
} |
| 98 | 87 |
|
| 99 |
-int test_positions_4(){
|
|
| 88 |
+void test_positions_4(){
|
|
| 100 | 89 |
size_t positions[2]; |
| 101 | 90 |
match_positions("as", "examples.txt", positions);
|
| 102 | 91 |
assert(positions[0] == 2); |
| 103 | 92 |
assert(positions[1] == 7); |
| 104 |
- |
|
| 105 |
- return 0; |
|
| 106 | 93 |
} |
| 107 | 94 |
|
| 108 |
-int test_positions_exact(){
|
|
| 95 |
+void test_positions_exact(){
|
|
| 109 | 96 |
size_t positions[3]; |
| 110 | 97 |
match_positions("foo", "foo", positions);
|
| 111 | 98 |
assert(positions[0] == 0); |
| 112 | 99 |
assert(positions[1] == 1); |
| 113 | 100 |
assert(positions[2] == 2); |
| 114 |
- |
|
| 115 |
- return 0; |
|
| 116 | 101 |
} |
| 117 | 102 |
|
| 118 |
-int test_choices_empty(){
|
|
| 103 |
+void test_choices_empty(){
|
|
| 119 | 104 |
choices_t choices; |
| 120 | 105 |
choices_init(&choices); |
| 121 | 106 |
assert(choices.size == 0); |
| ... | ... |
@@ -129,10 +114,9 @@ int test_choices_empty(){
|
| 129 | 114 |
assert(choices.selection == 0); |
| 130 | 115 |
|
| 131 | 116 |
choices_free(&choices); |
| 132 |
- return 0; |
|
| 133 | 117 |
} |
| 134 | 118 |
|
| 135 |
-int test_choices_1(){
|
|
| 119 |
+void test_choices_1(){
|
|
| 136 | 120 |
choices_t choices; |
| 137 | 121 |
choices_init(&choices); |
| 138 | 122 |
choices_add(&choices, "tags"); |
| ... | ... |
@@ -155,10 +139,9 @@ int test_choices_1(){
|
| 155 | 139 |
assert(choices_get(&choices, 1) == NULL); |
| 156 | 140 |
|
| 157 | 141 |
choices_free(&choices); |
| 158 |
- return 0; |
|
| 159 | 142 |
} |
| 160 | 143 |
|
| 161 |
-int test_choices_2(){
|
|
| 144 |
+void test_choices_2(){
|
|
| 162 | 145 |
choices_t choices; |
| 163 | 146 |
choices_init(&choices); |
| 164 | 147 |
choices_add(&choices, "tags"); |
| ... | ... |
@@ -206,10 +189,9 @@ int test_choices_2(){
|
| 206 | 189 |
assert_streq(choices_get(&choices, 1), "tags"); |
| 207 | 190 |
|
| 208 | 191 |
choices_free(&choices); |
| 209 |
- return 0; |
|
| 210 | 192 |
} |
| 211 | 193 |
|
| 212 |
-int test_choices_without_search(){
|
|
| 194 |
+void test_choices_without_search(){
|
|
| 213 | 195 |
/* Before a search is run, it should return no results */ |
| 214 | 196 |
|
| 215 | 197 |
choices_t choices; |
| ... | ... |
@@ -228,7 +210,6 @@ int test_choices_without_search(){
|
| 228 | 210 |
assert(choices_get(&choices, 0) == NULL); |
| 229 | 211 |
|
| 230 | 212 |
choices_free(&choices); |
| 231 |
- return 0; |
|
| 232 | 213 |
} |
| 233 | 214 |
|
| 234 | 215 |
void summary(){
|