Skip to content

Commit

Permalink
slight adjustment to YamlFile. Added rigours round-trip test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Aug 9, 2022
1 parent d88572d commit af78277
Show file tree
Hide file tree
Showing 7 changed files with 2,575 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ jobs:
compiler: gcc
version: 11

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: 3.9

- name: Install dependencies
run: |
sudo apt-get install valgrind
python -m pip install --upgrade pip
python -m pip install PyYAML
- name: configure cmake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
Expand All @@ -34,5 +41,6 @@ jobs:
run: |
./tests/test_yaml
valgrind --error-exitcode=1 --leak-check=full ./tests/test_yaml
python ../tests/test_roundtrip.py
./tests/example
valgrind --error-exitcode=1 --leak-check=full ./tests/example
14 changes: 9 additions & 5 deletions src/fortran_yaml_c.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ module fortran_yaml_c
public :: type_scalar
public :: type_null
public :: type_error

! parser
public :: parse

! File API
public :: YamlFile
Expand All @@ -26,6 +23,7 @@ module fortran_yaml_c
contains
procedure :: parse => YamlFile_parse
procedure :: dump => YamlFile_dump
procedure :: finalize => YamlFile_finalize
final :: YamlFile_final
end type

Expand All @@ -35,6 +33,7 @@ subroutine YamlFile_parse(self, path, err)
class(YamlFile), intent(inout) :: self
character(*), intent(in) :: path
character(:), allocatable, intent(out) :: err
if (associated(self%root)) call self%finalize()
self%root => parse(path, err)
end subroutine

Expand All @@ -46,13 +45,18 @@ subroutine YamlFile_dump(self, unit, indent)
endif
end subroutine

subroutine YamlFile_final(self)
type(YamlFile), intent(inout) :: self
subroutine YamlFile_finalize(self)
class(YamlFile), intent(inout) :: self
if (associated(self%root)) then
call self%root%finalize()
deallocate(self%root)
nullify(self%root)
endif
end subroutine

subroutine YamlFile_final(self)
type(YamlFile), intent(inout) :: self
call YamlFile_finalize(self)
end subroutine

end module
2 changes: 1 addition & 1 deletion tests/example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ subroutine main()
real(dp) :: pi
logical :: happy

call file%parse("../test.yaml", err)
call file%parse("../tests/test1.yaml", err)
if (allocated(err)) then
print*,err
stop 1
Expand Down
File renamed without changes.
Loading

0 comments on commit af78277

Please sign in to comment.