Greatly simplify test-suite driver programs - #86
Closed
rouson wants to merge 34 commits into
Closed
Conversation
This commit introduces the test_harness_t and test_fixture_t derived types and uses them to refactor and simplify the test-suite driver program: test/main.F90.
This commit reduces the amount of code that end users must write by moving the reporting of the final tally of test passes, test count, and skipped tests to the test_harness_t's "report" type-bound procedure.
This commit the code that checks whether the test suite is running in GitHub CI and checks whether the user requested to run the command_line_t tests. The code is moved from the test-suite driver to the actual test, which further simplifies the test-suite main program.
This commit adds a binary operator that produces a test_diagnosis_t result when applied to a logical operand.
Caveat: The newly refactored test/main.f90 program causes an ICE with gfortran 13.4.
rouson
force-pushed
the
test-harness-feature
branch
from
August 10, 2025 18:36
56e126f to
7ed8437
Compare
…e into test-harness-feature
rouson
force-pushed
the
test-harness-feature
branch
from
August 11, 2025 02:37
bfa2155 to
06ca107
Compare
move pointer declarations & definitions outside a block construct
also delete redundant example
Also switch file to lower-case .f90 extension because the preprocessor is no longer needed.
This was referenced Aug 11, 2025
bonachea
requested changes
Aug 11, 2025
bonachea
left a comment
Member
There was a problem hiding this comment.
Looks like a nice improvemen!
I made a few suggestions based on a quick skim.
Comment on lines
+20
to
+40
| subroutine stop_if_compiler_too_old | ||
| character(len=:), allocatable :: compiler_identity | ||
| integer major, minor | ||
| compiler_identity = compiler_version() | ||
| if (index(compiler_identity, "GCC")==1) then | ||
| associate( final_dot => index(compiler_identity ,"." ,back=.true.)) | ||
| associate( penultimate_dot => index(compiler_identity(:final_dot-1) ,"." ,back=.true.)) | ||
| associate(space_before_version => index(compiler_identity(:penultimate_dot-1) ," " ,back=.true.)) | ||
| associate( & | ||
| major_string => compiler_identity(space_before_version+1 : penultimate_dot-1) & | ||
| ,minor_string => compiler_identity( penultimate_dot+1 : final_dot-1) & | ||
| ) | ||
| read(major_string, '(i2)') major | ||
| read(minor_string, '(i1)') minor | ||
| if ((major < 14) .or. (major==14 .and. minor<3)) stop "'"// compiler_identity //"' too old: GCC >= 14.3.0 required" | ||
| end associate | ||
| end associate | ||
| end associate | ||
| end associate | ||
| end if | ||
| end subroutine |
Member
There was a problem hiding this comment.
This can be written far more concisely using the preprocessor.
You will also need to rename the file back to .F90.
Suggested change
| subroutine stop_if_compiler_too_old | |
| character(len=:), allocatable :: compiler_identity | |
| integer major, minor | |
| compiler_identity = compiler_version() | |
| if (index(compiler_identity, "GCC")==1) then | |
| associate( final_dot => index(compiler_identity ,"." ,back=.true.)) | |
| associate( penultimate_dot => index(compiler_identity(:final_dot-1) ,"." ,back=.true.)) | |
| associate(space_before_version => index(compiler_identity(:penultimate_dot-1) ," " ,back=.true.)) | |
| associate( & | |
| major_string => compiler_identity(space_before_version+1 : penultimate_dot-1) & | |
| ,minor_string => compiler_identity( penultimate_dot+1 : final_dot-1) & | |
| ) | |
| read(major_string, '(i2)') major | |
| read(minor_string, '(i1)') minor | |
| if ((major < 14) .or. (major==14 .and. minor<3)) stop "'"// compiler_identity //"' too old: GCC >= 14.3.0 required" | |
| end associate | |
| end associate | |
| end associate | |
| end associate | |
| end if | |
| end subroutine | |
| #if __GNUC__ && ( __GNUC__ < 14 || (__GNUC__ == 14 && __GNUC_MINOR__ < 3) ) | |
| stop "GFortran " // __VERSION__ // " too old: GCC >= 14.3.0 required" | |
| #endif |
| program main | ||
| !! Julienne unit tests driver | ||
|
|
||
| #if defined(__GCC__) && (GCC_VERSION < 140300) |
Member
There was a problem hiding this comment.
I believe it's actually __GNUC__ not __GCC__
Suggested change
| #if defined(__GCC__) && (GCC_VERSION < 140300) | |
| #if defined(__GNUC__) && (GCC_VERSION < 140300) |
|
|
||
| program main | ||
| !! Julienne unit tests driver | ||
| #if ! defined(__GCC__) || (GCC_VERSION >= 140300) |
Member
There was a problem hiding this comment.
Suggested change
| #if ! defined(__GCC__) || (GCC_VERSION >= 140300) | |
| #if ! defined(__GNUC__) || (GCC_VERSION >= 140300) |
Comment on lines
+7
to
+11
| #ifdef __GNUC__ | ||
| #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) | ||
| #else | ||
| #define GCC_VERSION 0 | ||
| #endif |
Member
There was a problem hiding this comment.
Minor nitpick:
For the "not Gfortran" case, you might instead consider leaving GCC_VERSION undefined:
Suggested change
| #ifdef __GNUC__ | |
| #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) | |
| #else | |
| #define GCC_VERSION 0 | |
| #endif | |
| #ifdef __GNUC__ | |
| # define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) | |
| #else | |
| # undef GCC_VERSION | |
| #endif |
Then later your tests become more readable and slightly less error-prone:
#if ! defined(GCC_VERSION) || (GCC_VERSION >= 140300)
Contributor
Author
|
This PR is superseded by PR #91. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR
test/main.f90, to a form that will facilitate automating the driver creation.command_line_test_musing idioms based on a new.expect.unary operator..expect.to the table of idioms in the README.md.demo/subdirectory to demonstrate the new driver structure.a. Conditionally gutting the new driver when the preprocessor detects GCC versions below 14.3.0 and
b. Retaining the old driver in
test/legacy-main.F90but conditionally gutting it with GCC 14.3.0 or later versions.New Features
operator(.expect.)that maps alogicalexpression to atest_diagnosis_tobject.a. A
test_harness_tderived type with atest_fixture_tallocatable array component.b. A
test_fixture_tderived type with a polymorphictest_tcomponent.Driver simplifications
test_harness_t's type-boundreport_resultssubroutine.report_resultssubroutine.a. Use statements and declarations,
b. One array constructor containing structure constructors and user-defined structure constructor invocations,
c. A single call to
report_resultson the test harness.