Skip to content

Commit c28c996

Browse files
committed
test-tokenizer-0: improve output, show how many tests failed
1 parent 95f84d5 commit c28c996

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

tests/test-tokenizer-0.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int main(int argc, char **argv) {
175175
atexit([]() { console::cleanup(); });
176176
#endif
177177

178-
bool success = true;
178+
int n_failed = 0;
179179

180180
const auto k_tests = [&]() -> llama_tests {
181181
if (!fname_text.empty()) {
@@ -214,22 +214,27 @@ int main(int argc, char **argv) {
214214
}
215215

216216
if (!correct) {
217-
fprintf(stderr, "%s : failed test: '%s'\n", __func__, test_kv.first.c_str());
218-
fprintf(stderr, "%s : detokenized to: '%s' instead of '%s'\n", __func__,
219-
llama_detokenize_bpe(ctx, res).c_str(),
220-
llama_detokenize_bpe(ctx, test_kv.second).c_str());
221-
fprintf(stderr, "%s : expected tokens: ", __func__);
217+
fprintf(stderr, "failed test: '%s'\n", test_kv.first.c_str());
218+
auto detok = llama_detokenize_bpe(ctx, res).c_str();
219+
auto expected = llama_detokenize_bpe(ctx, test_kv.second).c_str();
220+
fprintf(stderr, "detokenized to: '%s'\n", detok);
221+
if(detok != expected) {
222+
fprintf(stderr, "but we wanted: '%s'\n", expected);
223+
} else {
224+
fprintf(stderr, "(which matches the expected output)\n", expected);
225+
}
226+
fprintf(stderr, "expected tokens: \n");
222227
for (const auto & t : test_kv.second) {
223-
fprintf(stderr, "%6d '%s', ", t, llama_token_to_piece(ctx, t).c_str());
228+
fprintf(stderr, "%6d '%s'\n", t, llama_token_to_piece(ctx, t).c_str());
224229
}
225230
fprintf(stderr, "\n");
226-
fprintf(stderr, "%s : got tokens: ", __func__);
231+
fprintf(stderr, "got tokens: \n");
227232
for (const auto & t : res) {
228-
fprintf(stderr, "%6d '%s', ", t, llama_token_to_piece(ctx, t).c_str());
233+
fprintf(stderr, "%6d '%s'\n", t, llama_token_to_piece(ctx, t).c_str());
229234
}
230-
fprintf(stderr, "\n");
235+
fprintf(stderr, "\n====================\n");
231236

232-
success = false;
237+
n_failed ++;
233238
}
234239
}
235240

@@ -286,7 +291,11 @@ int main(int argc, char **argv) {
286291
llama_backend_free();
287292

288293
printf("\n");
289-
printf("Tests %s\n", success ? "passed" : "failed");
294+
if(n_failed) {
295+
printf("%d tests failed\n", n_failed);
296+
} else {
297+
printf("Tests passed\n");
298+
}
290299

291-
return success ? 0 : 3;
300+
return !n_failed ? 0 : 3;
292301
}

0 commit comments

Comments
 (0)