JuliaTesting / ReferenceTests.jl

Utility package for comparing data against reference files
https://juliatesting.github.io/ReferenceTests.jl/latest/
Other
82 stars 14 forks source link

helper for reference file name #93

Closed goretkin closed 2 years ago

goretkin commented 3 years ago

I have the following defined in e.g. MyModule.jl:

function pathof_test()
    normpath(joinpath(@__FILE__, "..", "..", "test"))
end

macro testref(name)
    quote
        $(joinpath)(
            pathof_test(),
            "references",
            $(relpath)($(String(__source__.file)), pathof_test()),
            $(name)
        )
    end
end

Which means I can do

using ReferenceTests: @test_reference
using MyModule: @testref
@test_reference @testref("data.txt") [(1, 2), (3, 4)]

in a few different test files, and only have to worry about choosing a unique name per test file.

I'm just giving this a shot now and thought I'd mention it here.

johnnychen94 commented 2 years ago

Even though people use "test/references" as a convention to place the files, I don't really like to have this into the package -- people can just very easily create their own path generators without using macros at all.

refpath(filename) = joinpath(@__DIR__, "references", filename)

there's very little need to maintain a copy of such one-liners here and document it.