diff --git a/demo/test/main.F90 b/demo/test/main.F90 index 43792108..14265742 100644 --- a/demo/test/main.F90 +++ b/demo/test/main.F90 @@ -5,21 +5,33 @@ program main use netCDF_file_test_m, only : netCDF_file_test_t + use iso_fortran_env, only : int64, real64 + use julienne_m, only : command_line_t implicit none - real t_start, t_finish - + integer(int64) t_start, t_finish, clock_rate + type(netCDF_file_test_t) netCDF_file_test integer :: passes=0, tests=0 - call cpu_time(t_start) - block - type(netCDF_file_test_t) netCDF_file_test - call netCDF_file_test%report(passes, tests) - end block - call cpu_time(t_finish) + print_usage_if_help_requested: & + block + type(command_line_t) command_line + character(len=*), parameter :: usage = & + new_line('') // new_line('') // & + 'Usage: fpm test -- [--help] | [--contains ]' // & + new_line('') // new_line('') // & + 'where square brackets ([]) denote optional arguments, a pipe (|) separates alternative arguments,' // new_line('') // & + 'angular brackets (<>) denote a user-provided value, and passing a substring limits execution to' // new_line('') // & + 'the tests with test subjects or test descriptions containing the user-specified substring.' // new_line('') + if (command_line%argument_present([character(len=len("--help"))::"--help","-h"])) stop usage + end block print_usage_if_help_requested + + call system_clock(t_start, clock_rate) + call netCDF_file_test%report(passes, tests) + call system_clock(t_finish) print * - print *,"Test suite execution time: ",t_finish - t_start + print *,"Test suite execution time: ", real(t_finish - t_start, real64)/real(clock_rate, real64) print * print '(*(a,:,g0))',"_________ In total, ",passes," of ",tests, " tests pass. _________" #if defined(MULTI_IMAGE_SUPPORT) diff --git a/demo/test/netCDF_file_test_m.F90 b/demo/test/netCDF_file_test_m.F90 index db6555f8..9eddc165 100644 --- a/demo/test/netCDF_file_test_m.F90 +++ b/demo/test/netCDF_file_test_m.F90 @@ -8,7 +8,7 @@ module NetCDF_file_test_m ! External dependencies use assert_m - use julienne_m, only : string_t, test_t, test_result_t + use julienne_m, only : test_t, test_result_t, test_description_t, test_description_substring, string_t use netcdf, only : & nf90_create, nf90_def_dim, nf90_def_var, nf90_enddef, nf90_put_var, nf90_inquire_dimension, & ! functions nf90_close, nf90_open, nf90_inq_varid, nf90_get_var, nf90_inquire_variable, & @@ -41,24 +41,22 @@ pure function subject() result(specimen) function results() result(test_results) type(test_result_t), allocatable :: test_results(:) + type(test_description_t), allocatable :: test_descriptions(:) character(len=*), parameter :: longest_description = & "writing and then reading gives input matching the output for a 1D double precision array" + test_descriptions = & + [ test_description_t("writing and then reading gives input matching the output for a 2D integer array", write_then_read_2D_integer), & + test_description_t("writing and then reading gives input matching the output for a 1D double precision array", write_then_read_1D_double) & + ] associate( & - descriptions => & - [ character(len=len(longest_description)) :: & - "writing and then reading gives input matching the output for a 2D integer array", & - "writing and then reading gives input matching the output for a 1D double precision array" & - ], & - outcomes => & - [ write_then_read_2D_integer(), & - write_then_read_1D_double() & - ] & + substring_in_subject => index(subject(), test_description_substring) /= 0, & + substring_in_description => test_descriptions%contains_text(string_t(test_description_substring)) & ) - call_assert(size(descriptions) == size(outcomes)) - test_results = test_result_t(descriptions, outcomes) + test_descriptions = pack(test_descriptions, substring_in_subject .or. substring_in_description) end associate + test_results = test_descriptions%run() end function @@ -118,7 +116,7 @@ subroutine output_1D_double(file_name, data_out) end subroutine function write_then_read_2D_integer() result(test_passes) - logical, allocatable :: test_passes(:) + logical test_passes integer i, j integer, parameter :: ny = 12, nx = 6 integer, parameter :: data_written(*,*) = reshape([((i*j, i=1,nx), j=1,ny)], [ny,nx]) @@ -131,12 +129,12 @@ function write_then_read_2D_integer() result(test_passes) call NetCDF_file%input("data", data_read) end associate - test_passes = [all(data_written == data_read)] + test_passes = all(data_written == data_read) end function function write_then_read_1D_double() result(test_passes) - logical, allocatable :: test_passes(:) + logical test_passes integer i integer, parameter :: nx = 6 double precision, parameter :: data_written(*) = dble([(i, i=1,nx)]), tolerance = 1.E-15 @@ -149,7 +147,7 @@ function write_then_read_1D_double() result(test_passes) call NetCDF_file%input("data", data_read) end associate - test_passes = [all(abs(data_written - data_read)