diff --git a/src/fileio.jl b/src/fileio.jl index af8bd5a..694ce7a 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -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[]) @@ -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...) """ diff --git a/test/dict.jl b/test/dict.jl index bc8d9a5..4653e8e 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -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)