-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
Description
test_reference is like 50 lines long.
ReferenceTests.jl/src/test_reference.jl
Lines 93 to 150 in f26bec0
| 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
endsplitting 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.
Reactions are currently unavailable