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

unit tests (documentation request) #62

Closed
pyramids opened this issue Mar 27, 2019 · 4 comments
Closed

unit tests (documentation request) #62

pyramids opened this issue Mar 27, 2019 · 4 comments

Comments

@pyramids
Copy link

I fail at writing unit tests for methods overwritten by @require. There are two problems I'm grappling with:

  1. julia complains if I don't add the optional dependency to the package, possibly causing the next issue.
  2. Whilst a test I want to write works in the REPL if I start with using my package and the optional dependency, it fails to replace the method in question when executed via ] test from the file test/runtests.jl.

Is there a chance that some documentation (or, better yet, a brief example) could be added to the documentation? Thanks alot!

@timholy
Copy link
Member

timholy commented Mar 27, 2019

A copy/pastable example would surely make this easier to address

@pyramids
Copy link
Author

pyramids commented Mar 27, 2019

Thank you for the speedy reply. I made a minimum example project as follows.

Edited multiple times due to a bug. Fixed now.

src/Demo.jl:

module Demo
using Requires
#using DataFrames
#Base.show(io::IO, mime::MIME"text/html", df::DataFrame) = print(io, "success")
function __init__()
    @require DataFrames="a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Base.show(io::IO, mime::MIME"text/html", df::DataFrames.DataFrame) = print(io, "success")
end # __init__
end # module

test/runtests.jl:

using Test
using DataFrames, Demo

@test begin
    io = IOBuffer()
    Base.show(io, "text/html", DataFrame())
    String(take!(io))
end == "success"

This works if I add DataFrames and then Requires as dependencies with ] add (and use the commented-out lines in src/Demo.jl instead of the @require line). In particular, ] test reports that the test passes.

Then I try removing the dependency on DataFrames and switch to the version of src/Demo.jl as shown above. Now the test fails saying I am missing the DataFrames package. Next I add it as an extra (test-only) dependency.

Project.toml then ends in

[deps]
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

But the error message about DataFrames being a missing package persists. It only works again (including the unit test) if I add it as a proper dependency. Doesn't it defeat Requires' purpose if I must add dependency packages into my project if I want to have unit tests?

@shipengcheng1230
Copy link

test = ["Test"]

Perhaps add DataFrames in addition in this line?

@timholy
Copy link
Member

timholy commented Dec 13, 2021

@shipengcheng1230 has the right answer; this is a package-management issue, not a Requires issue.

@timholy timholy closed this as completed Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants