Skip to content

Commit de920fa

Browse files
committed
added some additional checking for potential errors in the test cases (doesn't currently change the output).
1 parent 45c3116 commit de920fa

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/json_example.f90

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ program json_test
6262
character(len=*),parameter :: filename5 = 'test5.json' !
6363

6464
!initialize the module:
65+
!call json_initialize(verbose=.true.)
6566
call json_initialize()
6667

6768
!run the tests:
@@ -94,6 +95,8 @@ subroutine test_6()
9495
character(len=*),dimension(2),parameter :: files = ['invalid.json ',&
9596
'invalid2.json']
9697

98+
call json_initialize()
99+
97100
write(*,'(A)') ''
98101
write(*,'(A)') '================================='
99102
write(*,'(A)') ' EXAMPLE 6 : invalid JSON files'
@@ -136,6 +139,8 @@ subroutine test_5()
136139
type(json_file) :: json
137140
logical :: found
138141

142+
call json_initialize()
143+
139144
write(*,'(A)') ''
140145
write(*,'(A)') '================================='
141146
write(*,'(A)') ' EXAMPLE 5'
@@ -193,6 +198,8 @@ subroutine memory_leak_test()
193198

194199
integer :: i
195200

201+
call json_initialize()
202+
196203
write(*,'(A)') ''
197204
write(*,'(A)') '================================='
198205
write(*,'(A)') ' MEMORY LEAK TEST'
@@ -234,6 +241,8 @@ subroutine test_4()
234241
character(len=10) :: istr
235242
character(len=:),allocatable :: string
236243

244+
call json_initialize()
245+
237246
write(*,'(A)') ''
238247
write(*,'(A)') '================================='
239248
write(*,'(A)') ' EXAMPLE 4'
@@ -302,6 +311,8 @@ subroutine test_2()
302311

303312
integer :: iunit
304313

314+
call json_initialize()
315+
305316
write(*,'(A)') ''
306317
write(*,'(A)') '================================='
307318
write(*,'(A)') ' EXAMPLE 2'
@@ -424,6 +435,8 @@ subroutine test_3()
424435
character(len=10) :: str
425436
real(wp),dimension(:),allocatable :: rvec
426437

438+
call json_initialize()
439+
427440
write(*,'(A)') ''
428441
write(*,'(A)') '================================='
429442
write(*,'(A)') ' EXAMPLE 3'
@@ -515,6 +528,8 @@ subroutine test_1()
515528
logical :: found
516529
type(json_value),pointer :: p
517530

531+
call json_initialize()
532+
518533
write(*,'(A)') ''
519534
write(*,'(A)') '================================='
520535
write(*,'(A)') ' EXAMPLE 1'
@@ -632,29 +647,35 @@ subroutine test_1()
632647

633648
call json%get('files', p) !in the middle of a list
634649
call json_remove(p)
635-
650+
if (json_failed()) call print_error_message()
651+
636652
call json%get('data(1).array', p) !at the end of a list
637653
call json_remove(p)
638-
654+
if (json_failed()) call print_error_message()
655+
639656
call json%get('data(2).number', p) !at the beginning of a list
640657
call json_remove(p)
658+
if (json_failed()) call print_error_message()
641659

642660
write(*,'(A)') ''
643661
write(*,'(A)') 'printing the modified structure...'
644662
call json%print_file()
663+
if (json_failed()) call print_error_message()
645664

646665
write(*,'(A)') ''
647666
write(*,'(A)') ' Test replacing data from the json structure:'
648667

649668
call json%get('data(1)', p)
650669
call json_update(p,'name','Cuthbert',found)
670+
if (json_failed()) call print_error_message()
651671

652672
!call json%get('data(2)', p)
653673
!call json_update(p,'real',[1.0_wp, 2.0_wp, 3.0_wp],found) !don't have one like this yet...
654674

655675
write(*,'(A)') ''
656676
write(*,'(A)') 'printing the modified structure...'
657677
call json%print_file()
678+
if (json_failed()) call print_error_message()
658679

659680
end if
660681

@@ -676,7 +697,7 @@ subroutine print_error_message()
676697

677698
character(len=:),allocatable :: error_msg
678699
logical :: status_ok
679-
700+
680701
!get error message:
681702
call json_check_for_errors(status_ok, error_msg)
682703

0 commit comments

Comments
 (0)