Skip to content

Split up test_reference into ~3 smaller functions #80

@oxinabox

Description

@oxinabox

test_reference is like 50 lines long.

function test_reference(
file::File{F},
raw_actual::T,
equiv=nothing,
rendermode=nothing;
kw...) where {F <: DataFormat, T}
path = file.filename
dir, filename = splitdir(path)
actual = _convert(F, raw_actual; kw...)
# infer the default rendermode here
# since `nothing` is always passed to this method from
# test_reference(filename::AbstractString, raw_actual; kw...)
if rendermode === nothing
rendermode = default_rendermode(F, actual)
end
# preprocessing when reference file doesn't exists
if !isfile(path)
@info("Reference file for \"$filename\" does not exist. It will be created")
# TODO: move encoding out from render
render(rendermode, actual)
mkpath(dir)
savefile(file, actual)
@info("Please run the tests again for any changes to take effect")
return nothing # skip current test case
end
# file exists
reference = loadfile(typeof(actual), file)
if equiv === nothing
# generally, `reference` and `actual` are of the same type after preprocessing
equiv = default_equality(reference, actual)
end
if equiv(reference, actual)
@test true # to increase test counter if reached
else
# post-processing when test fails
println("Test for \"$filename\" failed.")
render(rendermode, reference, actual)
if !isinteractive()
error("You need to run the tests interactively with 'include(\"test/runtests.jl\")' to update reference images")
end
if !input_bool("Replace reference with actual result (path: $path)?")
@test false
else
savefile(file, actual)
@info("Please run the tests again for any changes to take effect")
end
end

And it is even longer when i put in the stuff for #79

I think we should have it more like

function test_reference(
    file::File{F},
    raw_actual::T,
    equiv=nothing,
    rendermode=nothing;
    kw...) where {F <: DataFormat, T}

    actual = ...
    rendermode = ...

    if !isfile(path)
        handle_nonexisting_reference(...)
    else
        test_against_reference(...)
    end
end

splitting the two main branchs out.
Possible workout out the equiv should be done in the main function, then all the modal stuff is done there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions