Skip to content

Commit 24a83d5

Browse files
committed
added additional tests
testing gfortran 8-12 now in the CI
1 parent 4abf706 commit 24a83d5

File tree

5 files changed

+115
-4
lines changed

5 files changed

+115
-4
lines changed

.github/workflows/CI.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: [ubuntu-latest]
13-
gcc_v: [10] # Version of GFortran we want to use.
13+
gcc_v: [8,9,10,11,12] # gfortran versions to test
1414
python-version: [3.9]
1515
env:
1616
FC: gfortran-${{ matrix.gcc_v }}
@@ -23,11 +23,13 @@ jobs:
2323
submodules: recursive
2424

2525
- name: Install Python
26+
if: contains( matrix.gcc_v, 10 )
2627
uses: actions/setup-python@v4 # Use pip to install latest CMake, & FORD/Jin2For, etc.
2728
with:
2829
python-version: ${{ matrix.python-version }}
2930

3031
- name: Setup Graphviz
32+
if: contains( matrix.gcc_v, 10 )
3133
uses: ts-graphviz/setup-graphviz@v1
3234

3335
- name: Setup Fortran Package Manager
@@ -36,14 +38,13 @@ jobs:
3638
github-token: ${{ secrets.GITHUB_TOKEN }}
3739

3840
- name: Install Python dependencies
39-
if: contains( matrix.os, 'ubuntu')
41+
if: contains( matrix.gcc_v, 10 )
4042
run: |
4143
python -m pip install --upgrade pip
4244
pip install ford numpy matplotlib
4345
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
4446
4547
- name: Install GFortran Linux
46-
if: contains( matrix.os, 'ubuntu')
4748
run: |
4849
sudo apt-get install lcov
4950
sudo update-alternatives \
@@ -58,6 +59,7 @@ jobs:
5859
run: fpm test --profile debug --flag -coverage
5960

6061
- name: Create coverage report
62+
if: contains( matrix.gcc_v, 10 )
6163
run: |
6264
mkdir -p ${{ env.COV_DIR }}
6365
lcov --capture --initial --base-directory . --directory build/gfortran_*/ --output-file ${{ env.COV_DIR }}/coverage.base
@@ -67,15 +69,17 @@ jobs:
6769
COV_DIR: build/coverage
6870

6971
- name: Upload coverage report
72+
if: contains( matrix.gcc_v, 10 )
7073
uses: codecov/codecov-action@v3
7174
with:
7275
files: build/coverage/coverage.info
7376

7477
- name: Build documentation
78+
if: contains( matrix.gcc_v, 10 )
7579
run: ford ./fortran-csv-module.md
7680

7781
- name: Deploy Documentation
78-
if: github.ref == 'refs/heads/master'
82+
if: contains( matrix.gcc_v, 10 ) && github.ref == 'refs/heads/master'
7983
uses: JamesIves/[email protected]
8084
with:
8185
branch: gh-pages # The branch the action should deploy to.

files/test2.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"header1", "header2"
2+
"text1", -2.73
3+
"text2", 0.24

fpm.toml

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ name = "csv_test"
1717
source-dir = "src/tests"
1818
main = "csv_test.f90"
1919

20+
[[test]]
21+
name = "csv_test2"
22+
source-dir = "src/tests"
23+
main = "csv_test2.f90"
24+
25+
[[test]]
26+
name = "csv_test3"
27+
source-dir = "src/tests"
28+
main = "csv_test3.f90"
29+
2030
[install]
2131
library = true
2232

src/tests/csv_test2.f90

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
!*****************************************************************************************
4+
!> author: Jacob Williams
5+
! license: BSD
6+
!
7+
! Test of reading and writing CSV files.
8+
9+
program csv_test2
10+
11+
use csv_module
12+
use iso_fortran_env, only: wp => real64, sp => real32
13+
14+
implicit none
15+
16+
type(csv_file) :: file
17+
logical :: status_ok
18+
19+
call file%read('files/test2.csv',header_row=1,status_ok=status_ok)
20+
write(*,*) 'status_ok = ', status_ok
21+
22+
end program csv_test2

src/tests/csv_test3.f90

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
program csv_test3
2+
3+
use csv_module
4+
use iso_fortran_env, only: wp => real64
5+
6+
implicit none
7+
8+
type(csv_file) :: f
9+
logical :: status_ok
10+
character(len=30),dimension(:),allocatable :: header, col1
11+
integer :: i
12+
character(len=100) :: tmp_str
13+
14+
! set optional inputs:
15+
call f%initialize(verbose = .true.)
16+
17+
! open the file
18+
call f%open('test.csv',n_cols=4,status_ok=status_ok)
19+
20+
! add header
21+
call f%add(['x','y','z','t'])
22+
call f%next_row()
23+
24+
! add some data:
25+
call f%add([1.0_wp,2.0_wp,3.0_wp],real_fmt='(F5.3)')
26+
call f%add(.true.)
27+
call f%next_row()
28+
call f%add([2.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
29+
call f%add(.false.)
30+
call f%next_row()
31+
call f%add([3.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
32+
call f%add(.false.)
33+
call f%next_row()
34+
call f%add([4.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
35+
call f%add(.false.)
36+
call f%next_row()
37+
call f%add([5.0_wp,5.0_wp,6.0_wp],real_fmt='(F5.3)')
38+
call f%add(.false.)
39+
call f%next_row()
40+
41+
! finished
42+
call f%close(status_ok)
43+
if (.not. status_ok) error stop 'error closing file'
44+
45+
! read the file
46+
call f%read('test.csv',header_row=1,status_ok=status_ok)
47+
if (.not. status_ok) error stop 'error reading file'
48+
49+
! get the header and type info
50+
call f%get_header(header,status_ok)
51+
52+
print "(*(g0))", "HEADER:"
53+
do i = 1, size(header)
54+
print "(*(g0))", ">"//trim(header(i))//"<"
55+
end do
56+
if (.not. all(header == ['x','y','z','t'])) error stop 'error reading header'
57+
58+
call f%get(1,col1,status_ok)
59+
print "(*(g0))", "col1:"
60+
do i = 1, size(col1)
61+
print "(*(g0))", ">",trim(col1(i)),"<"
62+
end do
63+
64+
do i = 1, 5
65+
write(tmp_str,'(F5.3)') real(i,wp)
66+
if (col1(i) /= tmp_str) error stop 'error converting cell to string:'//tmp_str
67+
end do
68+
69+
! destroy the file
70+
call f%destroy()
71+
72+
end program csv_test3

0 commit comments

Comments
 (0)