|
| 1 | +! Copyright (c) 2024-2025, The Regents of the University of California and Sourcery Institute |
| 2 | +! Terms of use are as specified in LICENSE.txt |
| 3 | + |
| 4 | +#include "language-support.F90" |
| 5 | + |
| 6 | +module file_test_m |
| 7 | + !! Check data partitioning across files |
| 8 | + use julienne_m, only : & |
| 9 | + file_t & |
| 10 | + ,operator(.all.) & |
| 11 | + ,operator(.also.) & |
| 12 | + ,operator(.equalsExpected.) & |
| 13 | + ,passing_test & |
| 14 | + ,string_t & |
| 15 | + ,test_description_t & |
| 16 | + ,test_diagnosis_t & |
| 17 | + ,test_result_t & |
| 18 | + ,test_t & |
| 19 | + ,usher |
| 20 | + use assert_m, only : assert |
| 21 | + implicit none |
| 22 | + |
| 23 | + private |
| 24 | + public :: file_test_t |
| 25 | + |
| 26 | + type, extends(test_t) :: file_test_t |
| 27 | + contains |
| 28 | + procedure, nopass :: subject |
| 29 | + procedure, nopass :: results |
| 30 | + end type |
| 31 | + |
| 32 | +contains |
| 33 | + |
| 34 | + pure function subject() result(specimen) |
| 35 | + character(len=:), allocatable :: specimen |
| 36 | + specimen = "A file_t object" |
| 37 | + end function |
| 38 | + |
| 39 | + function results() result(test_results) |
| 40 | + type(test_result_t), allocatable :: test_results(:) |
| 41 | + type(test_description_t), allocatable :: test_descriptions(:) |
| 42 | + type(file_test_t) file_test |
| 43 | + |
| 44 | + test_descriptions = [ & |
| 45 | + test_description_t(string_t("reading a written file"), usher(check_write_then_read)) & |
| 46 | + ] |
| 47 | + test_results = file_test%run(test_descriptions) |
| 48 | + end function |
| 49 | + |
| 50 | + function check_write_then_read() result(test_diagnosis) |
| 51 | + !! Check that a written file can be read correctly |
| 52 | + type(test_diagnosis_t) test_diagnosis |
| 53 | + character(len=*), parameter :: file_name = "build/file_t-unit-test-data.txt" |
| 54 | + |
| 55 | + test_diagnosis = passing_test() |
| 56 | + |
| 57 | + associate(output_lines => [string_t("foo"), string_t(""), string_t("bar ")]) |
| 58 | + associate(output_file => file_t(output_lines)) |
| 59 | + call output_file%write_lines(file_name) |
| 60 | + associate(input_file => file_t(file_name)) |
| 61 | + test_diagnosis = test_diagnosis .also. (.all. (input_file%lines() .equalsExpected. output_lines)) |
| 62 | + end associate |
| 63 | + end associate |
| 64 | + end associate |
| 65 | + |
| 66 | + end function |
| 67 | + |
| 68 | +end module file_test_m |
0 commit comments