-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Facilitate expected error unit tests #1771
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8ad4af
Separate shr_sys_abort and its dependencies into a new module
billsacks a577759
Use a pfunit-based shr_abort in unit tests
billsacks e6643ad
Use fake shr_abort_mod from fake shr_sys_mod
billsacks 9ddfdf5
Add a unit test of the pfunit version of shr_abort_abort
billsacks 9eb4db9
Response to review: Add some comments
billsacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This directory contains mock/stub modules that are just built as part of select | ||
unit tests of the share code. This directory should *NOT* generally be added by | ||
unit tests of other components. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Local pFUnit files. | ||
set(pf_sources | ||
test_shr_abort.pf) | ||
|
||
# Sources to test. | ||
set(sources_needed | ||
shr_kind_mod.F90 | ||
shr_abort_mod.abortthrows.F90) | ||
extract_sources("${sources_needed}" "${share_sources}" test_sources) | ||
|
||
# Do source preprocessing and add the executable. | ||
create_pFUnit_test(shr_abort_mod shr_abort_mod_exe "${pf_sources}" | ||
"${test_sources}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This directory tests the version of shr_abort_mod that is used in unit tests. It | ||
does NOT test the production version of shr_abort_mod. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module test_shr_abort | ||
|
||
! Tests of shr_abort_mod: version used in unit tests that throws a pfunit exception | ||
! rather than aborting | ||
|
||
use pfunit_mod | ||
use shr_abort_mod | ||
use shr_kind_mod , only : r8 => shr_kind_r8 | ||
|
||
implicit none | ||
|
||
@TestCase | ||
type, extends(TestCase) :: TestShrAbort | ||
contains | ||
procedure :: setUp | ||
procedure :: tearDown | ||
end type TestShrAbort | ||
|
||
real(r8), parameter :: tol = 1.e-13_r8 | ||
|
||
contains | ||
|
||
subroutine setUp(this) | ||
class(TestShrAbort), intent(inout) :: this | ||
end subroutine setUp | ||
|
||
subroutine tearDown(this) | ||
class(TestShrAbort), intent(inout) :: this | ||
end subroutine tearDown | ||
|
||
@Test | ||
subroutine test_abort(this) | ||
class(TestShrAbort), intent(inout) :: this | ||
|
||
call shr_abort_abort('Test message') | ||
@assertExceptionRaised('ABORTED: Test message') | ||
end subroutine test_abort | ||
|
||
end module test_shr_abort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
This directory contains stubs that may be useful for the unit test builds for a | ||
number of components. | ||
This directory contains stubs and other unit test-specific implementations that | ||
may be useful for the unit test builds for a number of components. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
list(APPEND share_sources | ||
shr_abort_mod.abortthrows.F90) | ||
|
||
sourcelist_to_parent(share_sources) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This directory contains some fake modules that should generally be used in place | ||
of their real counterparts by ALL unit tests. So this directory generally should | ||
be added by unit tests of other components. |
63 changes: 63 additions & 0 deletions
63
src/share/unit_test_stubs/util/shr_abort_mod.abortthrows.F90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module shr_abort_mod | ||
|
||
! This is a replacement for shr_abort_mod that throws a pfunit exception rather than | ||
! aborting | ||
|
||
use shr_kind_mod, only : shr_kind_in | ||
use pfunit_mod, only : throw | ||
|
||
implicit none | ||
private | ||
|
||
public :: shr_abort_abort ! Replacement for shr_abort_abort that throws a pfunit exception rather than aborting | ||
|
||
public :: shr_abort_backtrace ! Just to satisfy the public interface of shr_abort_abort | ||
|
||
contains | ||
|
||
subroutine shr_abort_abort(string,rc) | ||
! Replacement for shr_abort_abort that throws a pfunit exception rather than aborting | ||
! | ||
! This can be used to test expected errors (i.e., failure testing). | ||
! | ||
! If this occurs within a pFUnit-based test: | ||
! | ||
! - If you have code like: | ||
! | ||
! @assertExceptionRaised(expected_message) | ||
! | ||
! then your test will pass if the actual message in the 'throw' call (including the | ||
! 'ABORTED: ' prefix) matches expected_message; it will fail if the actual message | ||
! doesn't match the expected message | ||
! | ||
! - If you don't have | ||
! | ||
! @assertExceptionRaised | ||
! | ||
! or | ||
! | ||
! call assertExceptionRaised | ||
! | ||
! then this will result in the given pFUnit test failing. | ||
|
||
!----- arguments ----- | ||
character(len=*) , intent(in), optional :: string ! error message string | ||
integer(shr_kind_in), intent(in), optional :: rc ! error code | ||
|
||
!----- locals ----- | ||
integer(shr_kind_in) :: my_rc | ||
|
||
! Prevent compiler spam about unused variables. | ||
if (.false.) my_rc = rc | ||
|
||
call throw("ABORTED: "//trim(string)) | ||
end subroutine shr_abort_abort | ||
|
||
subroutine shr_abort_backtrace() | ||
! Just to satisfy the public interface of shr_abort_abort | ||
! | ||
! Does nothing | ||
|
||
end subroutine shr_abort_backtrace | ||
|
||
end module shr_abort_mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should make it clear that client code should continue to use shr_sys_abort and not call shr_abort_abort directly.