Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up test_reference into ~3 smaller functions #80

Open
oxinabox opened this issue Feb 20, 2021 · 0 comments
Open

Split up test_reference into ~3 smaller functions #80

oxinabox opened this issue Feb 20, 2021 · 0 comments

Comments

@oxinabox
Copy link
Member

oxinabox commented Feb 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant