Skip to content

Commit b552d9f

Browse files
committed
C++: fix testing framework
Signed-off-by: Matija Amidzic <[email protected]>
1 parent 9213101 commit b552d9f

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

swig/cpp/tests/microtest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ namespace mt {
182182
fprintf(file, " %s%s:%d%s\n",
183183
red(), e.getFilepath(), e.getLine(), def());
184184
++num_failed;
185+
} catch (std::exception& e) {
186+
++num_failed;
185187
}
186188
}
187189

swig/cpp/tests/test_libyang.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST(test_ly_ctx_new)
4949
ASSERT_EQ(2, list.size());
5050
} catch( const std::exception& e ) {
5151
mt::printFailed(e.what(), stdout);
52-
return;
52+
throw;
5353
}
5454
}
5555

@@ -79,7 +79,7 @@ TEST(test_ly_ctx_get_searchdirs)
7979
ASSERT_EQ(yang_folder, list.at(0));
8080
} catch( const std::exception& e ) {
8181
mt::printFailed(e.what(), stdout);
82-
return;
82+
throw;
8383
}
8484
}
8585

@@ -107,7 +107,7 @@ TEST(test_ly_ctx_set_searchdir)
107107
ASSERT_EQ(new_yang_folder, list.at(0));
108108
} catch( const std::exception& e ) {
109109
mt::printFailed(e.what(), stdout);
110-
return;
110+
throw;
111111
}
112112
}
113113

@@ -140,7 +140,7 @@ TEST(test_ly_ctx_info)
140140
ASSERT_EQ(LYD_VAL_OK, info->validity());
141141
} catch( const std::exception& e ) {
142142
mt::printFailed(e.what(), stdout);
143-
return;
143+
throw;
144144
}
145145
}
146146

@@ -198,7 +198,7 @@ TEST(test_ly_ctx_load_get_module)
198198
ASSERT_STREQ(revision, module->rev()->date());
199199
} catch( const std::exception& e ) {
200200
mt::printFailed(e.what(), stdout);
201-
return;
201+
throw;
202202
}
203203
}
204204

@@ -228,7 +228,7 @@ TEST(test_ly_ctx_get_module_older)
228228
ASSERT_STREQ(revision_older, module_older->rev()->date());
229229
} catch( const std::exception& e ) {
230230
mt::printFailed(e.what(), stdout);
231-
return;
231+
throw;
232232
}
233233
}
234234

@@ -251,7 +251,7 @@ TEST(test_ly_ctx_get_module_by_ns)
251251
ASSERT_STREQ(module_name, module->name());
252252
} catch( const std::exception& e ) {
253253
mt::printFailed(e.what(), stdout);
254-
return;
254+
throw;
255255
}
256256
}
257257

@@ -278,7 +278,7 @@ TEST(test_ly_ctx_clean)
278278
ASSERT_NULL(module);
279279
} catch( const std::exception& e ) {
280280
mt::printFailed(e.what(), stdout);
281-
return;
281+
throw;
282282
}
283283
}
284284

@@ -303,7 +303,7 @@ TEST(test_ly_ctx_parse_module_path)
303303
ASSERT_STREQ(module_name2, module->name());
304304
} catch( const std::exception& e ) {
305305
mt::printFailed(e.what(), stdout);
306-
return;
306+
throw;
307307
}
308308
}
309309

@@ -340,7 +340,7 @@ TEST(test_ly_ctx_get_submodule)
340340
ASSERT_STREQ(sub_name, submodule->name());
341341
} catch( const std::exception& e ) {
342342
mt::printFailed(e.what(), stdout);
343-
return;
343+
throw;
344344
}
345345
}
346346

@@ -365,7 +365,7 @@ TEST(test_ly_ctx_get_submodule2)
365365
ASSERT_STREQ(sub_name, submodule->name());
366366
} catch( const std::exception& e ) {
367367
mt::printFailed(e.what(), stdout);
368-
return;
368+
throw;
369369
}
370370
}
371371

@@ -391,7 +391,7 @@ TEST(test_ly_ctx_find_path)
391391
std::make_shared<libyang::Set>();
392392
} catch( const std::exception& e ) {
393393
mt::printFailed(e.what(), stdout);
394-
return;
394+
throw;
395395
}
396396
}
397397

swig/cpp/tests/test_tree_data.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ TEST(test_ly_ctx_parse_data_mem)
150150
ASSERT_STREQ("x", root->schema()->name());
151151
} catch( const std::exception& e ) {
152152
mt::printFailed(e.what(), stdout);
153-
return;
153+
throw;
154154
}
155155
}
156156

@@ -173,7 +173,7 @@ TEST(test_ly_ctx_parse_data_fd)
173173
fclose(f);
174174
} catch( const std::exception& e ) {
175175
mt::printFailed(e.what(), stdout);
176-
return;
176+
throw;
177177
}
178178
}
179179

@@ -197,7 +197,7 @@ TEST(test_ly_ctx_parse_data_path)
197197
ASSERT_STREQ(schema_name, root->schema()->name());
198198
} catch( const std::exception& e ) {
199199
mt::printFailed(e.what(), stdout);
200-
return;
200+
throw;
201201
}
202202
}
203203

@@ -237,7 +237,7 @@ TEST(test_ly_data_node)
237237
ASSERT_NOTNULL(dup_node);
238238
} catch( const std::exception& e ) {
239239
mt::printFailed(e.what(), stdout);
240-
return;
240+
throw;
241241
}
242242
}
243243

@@ -285,7 +285,7 @@ TEST(test_ly_data_node_new_path)
285285
ASSERT_STREQ("value", node->child()->next()->next()->schema()->name());
286286
} catch (const std::exception& e) {
287287
mt::printFailed(e.what(), stdout);
288-
return;
288+
throw;
289289
}
290290
}
291291

@@ -307,7 +307,7 @@ TEST(test_ly_data_node_insert)
307307
ASSERT_STREQ("number32", root->child()->prev()->schema()->name());
308308
} catch (const std::exception& e) {
309309
mt::printFailed(e.what(), stdout);
310-
return;
310+
throw;
311311
}
312312
}
313313

@@ -332,7 +332,7 @@ TEST(test_ly_data_node_insert_sibling)
332332
ASSERT_STREQ("y", root->prev()->schema()->name());
333333
} catch (const std::exception& e) {
334334
mt::printFailed(e.what(), stdout);
335-
return;
335+
throw;
336336
}
337337
}
338338

@@ -357,7 +357,7 @@ TEST(test_ly_data_node_insert_before)
357357
ASSERT_STREQ("y", root->prev()->schema()->name());
358358
} catch (const std::exception& e) {
359359
mt::printFailed(e.what(), stdout);
360-
return;
360+
throw;
361361
}
362362
}
363363

@@ -382,7 +382,7 @@ TEST(test_ly_data_node_insert_after)
382382
ASSERT_STREQ("y", root->next()->schema()->name());
383383
} catch (const std::exception& e) {
384384
mt::printFailed(e.what(), stdout);
385-
return;
385+
throw;
386386
}
387387
}
388388

@@ -434,7 +434,7 @@ TEST(test_ly_data_node_schema_sort)
434434
ASSERT_STREQ("number64", root->child()->next()->next()->next()->schema()->name());
435435
} catch (const std::exception& e) {
436436
mt::printFailed(e.what(), stdout);
437-
return;
437+
throw;
438438
}
439439
}
440440

@@ -457,7 +457,7 @@ TEST(test_ly_data_node_find_path)
457457
ASSERT_EQ(1, set->number());
458458
} catch (const std::exception& e) {
459459
mt::printFailed(e.what(), stdout);
460-
return;
460+
throw;
461461
}
462462
}
463463

@@ -506,7 +506,7 @@ TEST(test_ly_data_node_validate)
506506
ASSERT_EQ(0, rc);
507507
} catch (const std::exception& e) {
508508
mt::printFailed(e.what(), stdout);
509-
return;
509+
throw;
510510
}
511511
}
512512

@@ -536,7 +536,7 @@ TEST(test_ly_data_node_unlink)
536536
ASSERT_STRNEQ("number32", node->prev()->schema()->name());
537537
} catch( const std::exception& e ) {
538538
mt::printFailed(e.what(), stdout);
539-
return;
539+
throw;
540540
}
541541
}
542542

@@ -556,7 +556,7 @@ TEST(test_ly_data_node_print_mem_xml)
556556
ASSERT_STREQ(result_xml, result);
557557
} catch (const std::exception& e) {
558558
mt::printFailed(e.what(), stdout);
559-
return;
559+
throw;
560560
}
561561
}
562562

@@ -576,7 +576,7 @@ TEST(test_ly_data_node_print_mem_xml_format)
576576
ASSERT_STREQ(result_xml_format, result);
577577
} catch (const std::exception& e) {
578578
mt::printFailed(e.what(), stdout);
579-
return;
579+
throw;
580580
}
581581
}
582582

@@ -596,7 +596,7 @@ TEST(test_ly_data_node_print_mem_json)
596596
ASSERT_STREQ(result_json, result);
597597
} catch (const std::exception& e) {
598598
mt::printFailed(e.what(), stdout);
599-
return;
599+
throw;
600600
}
601601
}
602602

swig/cpp/tests/test_tree_schema.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ TEST(test_ly_ctx_parse_module_mem)
301301
ASSERT_STREQ("b", module->name());
302302
} catch (const std::exception& e) {
303303
mt::printFailed(e.what(), stdout);
304-
return;
304+
throw;
305305
}
306306
}
307307

@@ -345,7 +345,7 @@ TEST(test_ly_ctx_parse_module_fd)
345345
fclose(f);
346346
} catch (const std::exception& e) {
347347
mt::printFailed(e.what(), stdout);
348-
return;
348+
throw;
349349
}
350350
}
351351

@@ -387,7 +387,7 @@ TEST(test_ly_ctx_parse_module_path)
387387
ASSERT_STREQ("b", module->name());
388388
} catch (const std::exception& e) {
389389
mt::printFailed(e.what(), stdout);
390-
return;
390+
throw;
391391
}
392392
}
393393

@@ -422,7 +422,7 @@ TEST(test_ly_module_print_mem_tree)
422422
ASSERT_STREQ(result_tree, result);
423423
} catch (const std::exception& e) {
424424
mt::printFailed(e.what(), stdout);
425-
return;
425+
throw;
426426
}
427427
}
428428

@@ -440,7 +440,7 @@ TEST(test_ly_module_print_mem_yang)
440440
ASSERT_STREQ(result_yang, result);
441441
} catch (const std::exception& e) {
442442
mt::printFailed(e.what(), stdout);
443-
return;
443+
throw;
444444
}
445445
}
446446

@@ -458,7 +458,7 @@ TEST(test_ly_module_print_mem_yin)
458458
ASSERT_STREQ(result_yin, result);
459459
} catch (const std::exception& e) {
460460
mt::printFailed(e.what(), stdout);
461-
return;
461+
throw;
462462
}
463463
}
464464

@@ -485,7 +485,7 @@ TEST(test_ly_schema_node_find_path)
485485
ASSERT_EQ(7, set->number());
486486
} catch (const std::exception& e) {
487487
mt::printFailed(e.what(), stdout);
488-
return;
488+
throw;
489489
}
490490
}
491491

@@ -511,7 +511,7 @@ TEST(test_ly_schema_node_path)
511511
ASSERT_STREQ(path_template, path);
512512
} catch (const std::exception& e) {
513513
mt::printFailed(e.what(), stdout);
514-
return;
514+
throw;
515515
}
516516
}
517517

0 commit comments

Comments
 (0)