-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from BerkeleyLab/diagnostic-output
Feature: produce diagnostic output for test failures
- Loading branch information
Showing
20 changed files
with
458 additions
and
83 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Julienne Unit Testing Classes | ||
----------------------------- | ||
```mermaid | ||
classDiagram | ||
test_t --> test_result_t : produces | ||
test_description_t --> test_diagnosis_t : "uses to construct test_result_t" | ||
test_result_t --> test_diagnosis_t : "accepts as constructor argument" | ||
class test_t{ | ||
<<abstract>> | ||
+ subject() character * | ||
+ results() test_result_t * | ||
+ report(passes : integer, tests : integer) | ||
} | ||
class test_result_t{ | ||
- description_ : character | ||
- diagnostics_ : character | ||
- passed : logical | ||
+ test_result_t(description : character, passed : test_diagnosis_t) test_result_t | ||
+ characterize() : character | ||
+ description_contains(character) : logical | ||
+ passed() : logical | ||
} | ||
class test_diagnosis_t{ | ||
- test_passed_ : logical | ||
- diagnostics_string_ : character | ||
+ test_diagnosis_t(test_passed : logical, diagnostics_string : character) test_diagnosis_t | ||
} | ||
class test_description_t{ | ||
- description_ : character | ||
- diagnosis_function : procecure(diagnosis_function_i), pointer | ||
+ test_description_t(description : character, diagnosis_function : procedure(diagnosis_function_i)) | ||
+ run() test_result_t | ||
+ contains_text(character) logical | ||
} |
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 @@ | ||
Example Sequence Diagram | ||
------------------------ | ||
```mermaid | ||
sequenceDiagram | ||
main->>specimen_test_t: report(passes, tests) | ||
test_t ->>command_line_t: flag_value("--contains") | ||
command_line_t ->> specimen_test_t : test_description_substring | ||
test_t ->> test_t : subject | ||
test_t ->> test_t : results | ||
test_t ->> test_description_t : construct | ||
test_t ->> test_result_t : construct | ||
test_t ->> test_result_t : characterize | ||
test_t ->> test_result_t : passed |
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,51 @@ | ||
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute | ||
! Terms of use are as specified in LICENSE.txt | ||
|
||
#include "language-support.F90" | ||
|
||
program main | ||
!! Example test main program to demonstrate the printing of diagnostic output when a test fails | ||
use julienne_m, only : command_line_t | ||
use specimen_test_m, only : specimen_test_t | ||
implicit none | ||
|
||
type(specimen_test_t) specimen_test | ||
integer :: passes=0, tests=0 | ||
|
||
call print_usage_and_stop_if_help_requested | ||
call specimen_test%report(passes, tests) | ||
call report_tally_and_error_stop_if_test_fails | ||
|
||
contains | ||
|
||
subroutine print_usage_and_stop_if_help_requested | ||
type(command_line_t) command_line | ||
if (command_line%argument_present([character(len=len("--help"))::"--help","-h"])) then | ||
print * | ||
print '(a)', 'Usage: fpm run --example main -- [--help] | [--contains <substring>]' | ||
print * | ||
print '(a)', 'where square brackets ([]) denote optional arguments, a pipe (|) separates alternative arguments,' | ||
print '(a)', 'angular brackets (<>) denote a user-provided value, and passing a substring limits execution to' | ||
print '(a)', 'the tests with test subjects or test descriptions containing the user-specified substring.' | ||
stop | ||
else | ||
print * | ||
print "(a)", "Append '-- --help' or '-- -h' to your `fpm test` command to display usage information." | ||
end if | ||
end subroutine | ||
|
||
subroutine report_tally_and_error_stop_if_test_fails | ||
|
||
#if HAVE_MULTI_IMAGE_SUPPORT | ||
if (this_image()==1) then | ||
#endif | ||
print * | ||
print '(*(a,:,g0))', "_________ In total, ",passes," of ",tests, " tests pass. _________" | ||
if (passes /= tests) error stop "Some tests failed." | ||
#if HAVE_MULTI_IMAGE_SUPPORT | ||
end if | ||
#endif | ||
|
||
end subroutine | ||
|
||
end program |
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,19 @@ | ||
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute | ||
! Terms of use are as specified in LICENSE.txt | ||
module specimen_m | ||
!! Example test specimen corresponding to the test defined in specimen_test_m.F90 | ||
implicit none | ||
|
||
type specimen_t | ||
contains | ||
procedure, nopass :: zero | ||
end type | ||
|
||
contains | ||
|
||
pure function zero() result(incorrect_value) | ||
integer incorrect_value | ||
incorrect_value = 1 | ||
end function | ||
|
||
end module |
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,80 @@ | ||
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute | ||
! Terms of use are as specified in LICENSE.txt | ||
|
||
#include "language-support.F90" | ||
|
||
module specimen_test_m | ||
!! Example unit test for the specimen_t test subject | ||
use specimen_m, only : specimen_t | ||
use julienne_m, only : & | ||
string_t, & | ||
test_t, & | ||
test_result_t, & | ||
test_description_t, & | ||
test_description_substring, & | ||
test_diagnosis_t | ||
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY | ||
use julienne_m, only : diagnosis_function_i ! work around gfortran's missing Fortran 2008 feature | ||
#endif | ||
|
||
implicit none | ||
|
||
private | ||
public :: specimen_test_t | ||
|
||
type, extends(test_t) :: specimen_test_t | ||
contains | ||
procedure, nopass :: subject | ||
procedure, nopass :: results | ||
end type | ||
|
||
contains | ||
|
||
pure function subject() result(specimen_description) | ||
character(len=:), allocatable :: specimen_description | ||
specimen_description = "A specimen_t object" | ||
end function | ||
|
||
function results() result(test_results) | ||
type(test_result_t), allocatable :: test_results(:) | ||
type(test_description_t), allocatable :: test_descriptions(:) | ||
|
||
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY | ||
test_descriptions = [ & | ||
test_description_t("the type-bound function zero() producing a result of 0", check_zero) & | ||
] | ||
#else | ||
! work around gfortran's missing Fortran 2008 feature | ||
procedure(diagnosis_function_i), pointer :: check_zero_ptr | ||
check_zero_ptr => check_zero | ||
|
||
test_descriptions = [ & | ||
test_description_t("the type-bound function zero() producing a result of 0", check_zero_ptr) & | ||
] | ||
#endif | ||
#ifndef __GFORTRAN__ | ||
associate(test_subset => pack(test_descriptions, test_descriptions%contains_text(test_description_substring) .or. index(subject(), test_description_substring)/=0)) | ||
test_results = test_subset%run() | ||
end associate | ||
#else | ||
|
||
test_descriptions = pack(test_descriptions, test_descriptions%contains_text(test_description_substring) .or. index(subject(), test_description_substring)/=0) | ||
test_results = test_descriptions%run() | ||
#endif | ||
|
||
end function | ||
|
||
function check_zero() result(test_diagnosis) | ||
type(test_diagnosis_t) test_diagnosis | ||
type(specimen_t) specimen | ||
integer, parameter :: expected_value = 0 | ||
|
||
associate(actual_value => specimen%zero()) | ||
test_diagnosis = test_diagnosis_t( & | ||
test_passed = actual_value == expected_value & | ||
,diagnostics_string = "expected value " // string_t(expected_value) //", actual value " // string_t(actual_value) & | ||
) | ||
end associate | ||
end function | ||
|
||
end module |
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
Oops, something went wrong.