forked from itsdfish/PackageExtensionsExample.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcool_example.jl
More file actions
47 lines (32 loc) · 1.24 KB
/
cool_example.jl
File metadata and controls
47 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#=
You should be able run this script from any directory with any project settings.
=#
using Pkg
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
# cool function should have no methods until Distributions is loaded
@assert length(methods(cool_function)) == 0
try
cool_function()
catch e
@assert e isa MethodError
end
# calling @cool_macro here throws a LoadError at the module level
# @cool_macro
@assert !isdefined(PackageExtensionsExample,:MyExtType)
###################################################################################################
using Distributions
# cool function should have 1 method now that Distributions is loaded
@assert length(methods(cool_function)) == 1
cool_function()
# should print "calling cool_function()"
@cool_macro
# should print "calling cool_macro()"
@assert isdefined(PackageExtensionsExample,:MyExtType)
println(PackageExtensionsExample.MyExtType())
# should show message containing "hello from DistributionsExt"