Skip to content

Commit c0a2d46

Browse files
committed
print error messages if tests fail
1 parent a48d38b commit c0a2d46

12 files changed

+229
-285
lines changed

tests/TestSuite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern "C" {
4343
#endif
4444
#define ASSERT_OR_PRINT(_statement, _err) \
4545
do { \
46-
if (!_statement) { \
46+
if (! (_statement)) { \
4747
fprintf(stderr, "FAIL:%s:%d %s()\n %s\n %s\n\n", \
4848
__FILE__, __LINE__, __FUNCTION__, \
4949
#_statement, _err.message); \

tests/test-bulk.c

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ test_bulk (void)
331331
bson_t del;
332332
bson_t up;
333333
bson_t doc = BSON_INITIALIZER;
334-
bool r;
335334

336335
client = test_framework_client_new ();
337336
assert (client);
@@ -360,8 +359,8 @@ test_bulk (void)
360359
mongoc_bulk_operation_remove (bulk, &del);
361360
bson_destroy (&del);
362361

363-
r = mongoc_bulk_operation_execute (bulk, &reply, &error);
364-
assert (r);
362+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
363+
error);
365364

366365
ASSERT_MATCH (&reply, "{'nInserted': 4,"
367366
" 'nMatched': 4,"
@@ -373,8 +372,7 @@ test_bulk (void)
373372

374373
bson_destroy (&reply);
375374

376-
r = mongoc_collection_drop (collection, &error);
377-
assert (r);
375+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
378376

379377
mongoc_bulk_operation_destroy (bulk);
380378
mongoc_collection_destroy (collection);
@@ -393,7 +391,6 @@ test_insert (bool ordered)
393391
bson_t reply;
394392
bson_t doc = BSON_INITIALIZER;
395393
bson_t query = BSON_INITIALIZER;
396-
bool r;
397394
mongoc_cursor_t *cursor;
398395
const bson_t *inserted_doc;
399396

@@ -411,8 +408,8 @@ test_insert (bool ordered)
411408
mongoc_bulk_operation_insert (bulk, &doc);
412409
mongoc_bulk_operation_insert (bulk, &doc);
413410

414-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
415-
assert (r);
411+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
412+
error);
416413

417414
ASSERT_MATCH (&reply, "{'nInserted': 2,"
418415
" 'nMatched': 0,"
@@ -432,8 +429,7 @@ test_insert (bool ordered)
432429
assert (oid_created_on_client (inserted_doc));
433430
}
434431

435-
r = mongoc_collection_drop (collection, &error);
436-
assert (r);
432+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
437433

438434
mongoc_cursor_destroy (cursor);
439435
bson_destroy (&query);
@@ -520,7 +516,6 @@ test_upsert (bool ordered)
520516
bson_t reply;
521517
bson_t *sel;
522518
bson_t *doc;
523-
bool r;
524519

525520
client = test_framework_client_new ();
526521
assert (client);
@@ -537,8 +532,8 @@ test_upsert (bool ordered)
537532

538533
mongoc_bulk_operation_update (bulk, sel, doc, true);
539534

540-
r = mongoc_bulk_operation_execute (bulk, &reply, &error);
541-
assert (r);
535+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
536+
error);
542537

543538
ASSERT_MATCH (&reply, "{'nInserted': 0,"
544539
" 'nMatched': 0,"
@@ -561,8 +556,8 @@ test_upsert (bool ordered)
561556
doc = tmp_bson ("{'$set': {'hello': 'there'}}");
562557

563558
mongoc_bulk_operation_update (bulk, sel, doc, false);
564-
r = mongoc_bulk_operation_execute (bulk, &reply, &error);
565-
assert (r);
559+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
560+
error);
566561

567562
ASSERT_MATCH (&reply, "{'nInserted': 0,"
568563
" 'nMatched': 0,"
@@ -574,8 +569,7 @@ test_upsert (bool ordered)
574569
check_n_modified (has_write_cmds, &reply, 0);
575570
ASSERT_COUNT (1, collection); /* doc remains from previous operation */
576571

577-
r = mongoc_collection_drop (collection, &error);
578-
assert (r);
572+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
579573

580574
bson_destroy (&reply);
581575
mongoc_bulk_operation_destroy (bulk);
@@ -728,8 +722,7 @@ test_upserted_index (bool ordered)
728722
check_n_modified (has_write_cmds, &reply, 34);
729723
ASSERT_COUNT (18, collection);
730724

731-
r = mongoc_collection_drop (collection, &error);
732-
assert (r);
725+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
733726

734727
bson_destroy (&reply);
735728
mongoc_bulk_operation_destroy (bulk);
@@ -788,8 +781,8 @@ test_update_one (bool ordered)
788781
sel = tmp_bson ("{}");
789782
doc = tmp_bson ("{'$set': {'hello': 'there'}}");
790783
mongoc_bulk_operation_update_one (bulk, sel, doc, true);
791-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
792-
assert (r);
784+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
785+
error);
793786

794787
ASSERT_MATCH (&reply, "{'nInserted': 0,"
795788
" 'nMatched': 1,"
@@ -801,8 +794,7 @@ test_update_one (bool ordered)
801794
check_n_modified (has_write_cmds, &reply, 1);
802795
ASSERT_COUNT (2, collection);
803796

804-
r = mongoc_collection_drop (collection, &error);
805-
assert (r);
797+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
806798

807799
bson_destroy (&reply);
808800
mongoc_bulk_operation_destroy (bulk);
@@ -861,8 +853,8 @@ test_replace_one (bool ordered)
861853
sel = tmp_bson ("{}");
862854
doc = tmp_bson ("{'hello': 'there'}");
863855
mongoc_bulk_operation_replace_one (bulk, sel, doc, true);
864-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
865-
assert (r);
856+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
857+
error);
866858

867859
ASSERT_MATCH (&reply, "{'nInserted': 0,"
868860
" 'nMatched': 1,"
@@ -874,8 +866,7 @@ test_replace_one (bool ordered)
874866
check_n_modified (has_write_cmds, &reply, 1);
875867
ASSERT_COUNT (2, collection);
876868

877-
r = mongoc_collection_drop (collection, &error);
878-
assert (r);
869+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error), error);
879870

880871
bson_destroy (&reply);
881872
mongoc_bulk_operation_destroy (bulk);
@@ -915,8 +906,8 @@ test_upsert_large ()
915906
bson_append_document_end (&doc, &child);
916907

917908
mongoc_bulk_operation_update (bulk, sel, &doc, true);
918-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
919-
assert (r);
909+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
910+
error);
920911

921912
ASSERT_MATCH (&reply, "{'nInserted': 0,"
922913
" 'nMatched': 0,"
@@ -968,7 +959,6 @@ test_update (bool ordered)
968959
bson_t *sel;
969960
bson_t *bad_update_doc = tmp_bson ("{'foo': 'bar'}");
970961
bson_t *update_doc;
971-
bool r;
972962

973963
client = test_framework_client_new ();
974964
assert (client);
@@ -993,8 +983,8 @@ test_update (bool ordered)
993983

994984
update_doc = tmp_bson ("{'$set': {'foo': 'bar'}}");
995985
mongoc_bulk_operation_update (bulk, sel, update_doc, false);
996-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
997-
assert (r);
986+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
987+
error);
998988

999989
ASSERT_MATCH (&reply, "{'nInserted': 0,"
1000990
" 'nMatched': 2,"
@@ -1007,8 +997,8 @@ test_update (bool ordered)
1007997
check_n_modified (has_write_cmds, &reply, 1);
1008998
ASSERT_COUNT (3, collection);
1009999

1010-
r = mongoc_collection_drop (collection, &error);
1011-
assert (r);
1000+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error),
1001+
error);
10121002

10131003
mongoc_bulk_operation_destroy (bulk);
10141004
bson_destroy (&reply);
@@ -1066,8 +1056,8 @@ test_index_offset (void)
10661056
mongoc_bulk_operation_remove_one (bulk, sel);
10671057
mongoc_bulk_operation_update (bulk, sel, doc, true);
10681058

1069-
r = mongoc_bulk_operation_execute (bulk, &reply, &error);
1070-
assert (r);
1059+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
1060+
error);
10711061

10721062
ASSERT_MATCH (&reply, "{'nInserted': 0,"
10731063
" 'nMatched': 0,"
@@ -1081,8 +1071,8 @@ test_index_offset (void)
10811071

10821072
bson_destroy (&reply);
10831073

1084-
r = mongoc_collection_drop (collection, &error);
1085-
assert (r);
1074+
ASSERT_OR_PRINT (mongoc_collection_drop (collection, &error),
1075+
error);
10861076

10871077
mongoc_bulk_operation_destroy (bulk);
10881078
mongoc_collection_destroy (collection);
@@ -1099,7 +1089,6 @@ test_single_ordered_bulk ()
10991089
mongoc_bulk_operation_t *bulk;
11001090
bson_t reply;
11011091
bson_error_t error;
1102-
bool r;
11031092

11041093
client = test_framework_client_new ();
11051094
assert (client);
@@ -1123,8 +1112,8 @@ test_single_ordered_bulk ()
11231112
tmp_bson ("{'a': 3}"));
11241113
mongoc_bulk_operation_remove (bulk,
11251114
tmp_bson ("{'a': 3}"));
1126-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1127-
assert (r);
1115+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1116+
error);
11281117

11291118
ASSERT_MATCH (&reply, "{'nInserted': 2,"
11301119
" 'nMatched': 1,"
@@ -1440,7 +1429,6 @@ test_single_unordered_bulk ()
14401429
mongoc_bulk_operation_t *bulk;
14411430
bson_t reply;
14421431
bson_error_t error;
1443-
bool r;
14441432

14451433
client = test_framework_client_new ();
14461434
assert (client);
@@ -1462,8 +1450,8 @@ test_single_unordered_bulk ()
14621450
tmp_bson ("{'a': 3}"));
14631451
mongoc_bulk_operation_remove (bulk,
14641452
tmp_bson ("{'a': 3}"));
1465-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1466-
assert (r);
1453+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1454+
error);
14671455

14681456
ASSERT_MATCH (&reply, "{'nInserted': 2,"
14691457
" 'nMatched': 1,"
@@ -1793,8 +1781,8 @@ test_large_inserts_ordered ()
17931781
mongoc_bulk_operation_insert (bulk, big_doc);
17941782
}
17951783

1796-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1797-
assert (r);
1784+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1785+
error);
17981786
assert_n_inserted (6, &reply);
17991787
ASSERT_COUNT (6, collection);
18001788

@@ -1874,8 +1862,8 @@ test_large_inserts_unordered ()
18741862
mongoc_bulk_operation_insert (bulk, big_doc);
18751863
}
18761864

1877-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1878-
assert (r);
1865+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1866+
error);
18791867
assert_n_inserted (6, &reply);
18801868
ASSERT_COUNT (6, collection);
18811869

@@ -1895,7 +1883,6 @@ _test_numerous (bool ordered)
18951883
mongoc_bulk_operation_t *bulk;
18961884
bson_t reply;
18971885
bson_error_t error;
1898-
bool r;
18991886
int n_docs = 4100; /* exceeds max write batch size of 1000 */
19001887
bson_t doc;
19011888
bson_iter_t iter;
@@ -1919,8 +1906,8 @@ _test_numerous (bool ordered)
19191906
mongoc_bulk_operation_insert (bulk, &doc);
19201907
}
19211908

1922-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1923-
assert (r);
1909+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1910+
error);
19241911

19251912
assert_n_inserted (n_docs, &reply);
19261913
ASSERT_COUNT (n_docs, collection);
@@ -1935,8 +1922,8 @@ _test_numerous (bool ordered)
19351922
mongoc_bulk_operation_remove_one (bulk, &doc);
19361923
}
19371924

1938-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1939-
assert (r);
1925+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1926+
error);
19401927

19411928
assert_n_removed (n_docs / 2, &reply);
19421929
ASSERT_COUNT (n_docs / 2, collection);
@@ -1951,8 +1938,8 @@ _test_numerous (bool ordered)
19511938
mongoc_bulk_operation_remove (bulk, &doc);
19521939
}
19531940

1954-
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
1955-
assert (r);
1941+
ASSERT_OR_PRINT ((bool)mongoc_bulk_operation_execute (bulk, &reply, &error),
1942+
error);
19561943

19571944
assert_n_removed (n_docs / 2, &reply);
19581945
ASSERT_COUNT (0, collection);
@@ -2061,7 +2048,6 @@ test_bulk_edge_case_372 (bool ordered)
20612048
bson_t *selector;
20622049
bson_t *update;
20632050
bson_t reply;
2064-
bool r;
20652051

20662052
client = test_framework_client_new ();
20672053
assert (client);
@@ -2093,13 +2079,12 @@ test_bulk_edge_case_372 (bool ordered)
20932079
mongoc_bulk_operation_replace_one (bulk, selector, update, true);
20942080
}
20952081

2096-
r = mongoc_bulk_operation_execute (bulk, &reply, &error);
2097-
if (!r) fprintf (stderr, "%s\n", error.message);
2098-
assert (r);
20992082

21002083
#if 0
21012084
printf ("%s\n", bson_as_json (&reply, NULL));
21022085
#endif
2086+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
2087+
error);
21032088

21042089
ASSERT_MATCH (&reply, "{'nInserted': 0,"
21052090
" 'nMatched': 0,"
@@ -2187,8 +2172,8 @@ test_bulk_new (void)
21872172
assert (error.code = MONGOC_ERROR_COMMAND_INVALID_ARG);
21882173

21892174
mongoc_bulk_operation_insert (bulk, &empty);
2190-
r = mongoc_bulk_operation_execute (bulk, NULL, &error);
2191-
assert (r);
2175+
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, NULL, &error),
2176+
error);
21922177

21932178
mongoc_bulk_operation_destroy (bulk);
21942179

0 commit comments

Comments
 (0)