-
Notifications
You must be signed in to change notification settings - Fork 1
added macro example #2
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
Conversation
|
Thank you for making this pull request. Once a few issues are fixed, I think this will be very helpful. When I run your fork locally, I get the following problem starting on this line: After this point, Thanks again! |
|
It worked on Julia 1.10. In 1.11 they changed the extension mechanism. If you comment out the init() code, and run it AFTER you get to the REPL, it works. I'm just not sure how to make it automatic in 1.11 yet. |
|
I used a hack that delays the eval until after |
|
Thanks for the fix! |
|
@mind6, would you be willing to advise on the proper way to unit test the new components you added? I have little experience with macros.I tried the following, but received a warning and error. @testset "before import" begin
@test length(methods(cool_function)) == 0
# warning here
@test_throws LoadError @macroexpand @cool_macro
@test !isdefined(PackageExtensionsExample,:MyExtType)
end
@testset "after import" begin
using Distributions
@test length(methods(cool_function)) == 1
@test @macroexpand @cool_macro
# error here
@test isdefined(PackageExtensionsExample,:MyExtType)
end |
|
Sure, you can try this: using Test
@testset "cool_macro" begin
tmpmod = Module()
@test try
@eval tmpmod begin
using PackageExtensionsExample
@cool_macro
end
false
catch e
e isa LoadError
end
end |
|
Thank you. Unfortunately, I'm not sure if that works. It passes both when distributions is imported and when it is not imported. I was hoping to have two tests: one showing it has an error before Distributions is imported, and a second test showing that it works after Distributions is imported. Any ideas. I fixed the other error by increasing the delay after importing Distributions: sleep(.1)
@test isdefined(PackageExtensionsExample, :MyExtType)Increasing the delay in the source code did not work. |
|
right, I guess temporary modules aren't set up as packages and it does nothing when you import another package. You might try ask on discourse if there's any way to catch a LoadError. |
|
try this: #=
You should be able run this script from any directory with any project settings.
=#
using Pkg, Test
cd(@__DIR__)
# activates the project in the script's directory
Pkg.activate(".")
# adds the local PackageExtensionsExample package to the script project (don't use Pkg.add here)
Pkg.develop(path="../")
using PackageExtensionsExample
@testset "before loading Distributions" begin
@test try
Core.eval(Main, :(
module m1
using PackageExtensionsExample
@cool_macro
end
))
false
catch e
for (exc, bt) in Base.current_exceptions()
showerror(stdout, exc, bt)
println()
end
e isa LoadError
end
end
using Distributions
@testset "after loading Distributions" begin
@test try
Core.eval(Main, :(
module m2
using PackageExtensionsExample
@cool_macro
end
))
true
catch e
false
end
end |
No description provided.