From 32efde2646c1e3397fa8f1f592929fb20e4ca756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Aradi?= Date: Thu, 17 Oct 2024 20:54:57 +0200 Subject: [PATCH] Invoke ASSERT() in the examples --- example/mpi-fypp/test_simple_fypp.fypp | 29 ++++++++++++++++++++++- example/serial-fypp/test_simple_fypp.fypp | 15 ++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/example/mpi-fypp/test_simple_fypp.fypp b/example/mpi-fypp/test_simple_fypp.fypp index 2deb367..a6c71e5 100644 --- a/example/mpi-fypp/test_simple_fypp.fypp +++ b/example/mpi-fypp/test_simple_fypp.fypp @@ -30,6 +30,28 @@ contains ! WHEN source rank broadcasts its value call broadcast(global_comm(), buffer, sourcerank) + ! THEN each rank must contain source rank's value + @:CHECK(is_equal(buffer, sourceval), msg=msg) + + $:END_TEST() + + + $:TEST("broadcast_fail3") + integer, parameter :: sourcerank = 0, sourceval = 1, otherval = -1 + integer :: buffer + + character(:), allocatable :: msg + + ! GIVEN source rank contains a different integer value as all other ranks + if (this_rank() == sourcerank) then + buffer = sourceval + else + buffer = otherval + end if + + ! WHEN source rank broadcasts its value + call broadcast(global_comm(), buffer, sourcerank) + ! Make every third rank fail for demonstration purposes if (mod(this_rank(), 3) == 2) then buffer = sourceval + 1 @@ -37,7 +59,12 @@ contains end if ! THEN each rank must contain source rank's value - @:CHECK(is_equal(buffer, sourceval), msg=msg) + ! + ! One can also use ASSERT() instead of CHECK(). If the check condition is not fulfilled, + ! ASSERT() causes the test code to return immediately, while CHECK() only logs the failure and + ! continues. + ! + @:ASSERT(is_equal(buffer, sourceval), msg=msg) $:END_TEST() diff --git a/example/serial-fypp/test_simple_fypp.fypp b/example/serial-fypp/test_simple_fypp.fypp index 609f166..f48d79c 100644 --- a/example/serial-fypp/test_simple_fypp.fypp +++ b/example/serial-fypp/test_simple_fypp.fypp @@ -23,14 +23,21 @@ contains $:TEST("factorial_1", label="simple") - @:CHECK(factorial(1) == 1) + + ! It is possible to use ASSERT() instead of CHECK(). If the check condition is not fulfilled, + ! ASSERT() causes the test code to return immediately, while CHECK() only logs the failure and + ! continues. + ! + @:ASSERT(factorial(1) == 1) + $:END_TEST() $:TEST("factorial_2", label="simple") - ! Two failing checks, you should see info about both in the output - @:CHECK(is_equal(factorial(2), 2), msg="Test failed for demonstration purposes") - @:CHECK(factorial(2) == 2) + ! Two failing checks (due to the implementation 'bug' in factorial() in the mylib library), + ! you should see info about both in the output + @:CHECK(is_equal(factorial(2), 2), msg="Test failed because of a bug in the tested routine") + @:CHECK(factorial(2) == 2, msg="Also this test failed because of a bug in the tested routine") $:END_TEST()