Skip to content

Commit

Permalink
Fix for issue #33
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskermode committed Sep 20, 2023
1 parent 4a7f9c1 commit 9cb6d49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function read_frame_dicts(fp::Ptr{Cvoid}; verbose=false)
eof = true
throw(EOFError())
end

(nat[] == 0) && error("ExtXYZ frame contains zero atoms. Behaviour is undefined!")
if verbose
cprint_dict(info[])
cprint_dict(arrays[])
Expand Down Expand Up @@ -287,7 +287,7 @@ function read_frame(fp::Ptr{Cvoid}; verbose=false)
return dict
end

read_frame(file::Union{String,IOStream}, index; kwargs...) = read_frames(file, index; kwargs...)[1]
read_frame(file::Union{String,IOStream}, index; kwargs...) = only(read_frames(file, index; kwargs...))
read_frame(file::Union{String,IOStream}; kwargs...) = read_frame(file, 1; kwargs...)

"""
Expand Down
24 changes: 24 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ Si 13.00000000 14.00000000 $(frame+1).00000000 0
@testset "missingfile" begin
@test_throws ErrorException("file bla.extxyz cannot be opened for reading") read_frame("bla.extxyz")
end

@testset "emptyfile" begin
s="""
"""
open(infile, "w") do io
print(io, s)
end
@test_throws ArgumentError("Collection is empty, must contain exactly 1 element") read_frame(infile)
end

@testset "zeroatoms" begin
s="""0
"""
open(infile, "w") do io
print(io, s)
end
ExtXYZ.cfopen(infile) do fp
@test_throws ErrorException("ExtXYZ frame contains zero atoms. Behaviour is undefined!") read_frame(fp)
end
end
finally
rm(infile, force=true)
rm(outfile, force=true)
Expand Down

0 comments on commit 9cb6d49

Please sign in to comment.