Skip to content

Commit 61b8bcb

Browse files
authored
Add tests for notifications (#91)
1 parent 0fde2d4 commit 61b8bcb

5 files changed

Lines changed: 69 additions & 1 deletion

File tree

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ julia = "0.7, 1"
1010

1111
[extras]
1212
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
13+
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
1314
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1415

1516
[targets]
16-
test = ["Test", "Colors"]
17+
test = ["Test", "Colors", "Example"]

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[deps]
22
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
3+
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
34
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/pkgs/NotifyMe/Project.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name = "NotifyMe"
2+
uuid = "545cf9b9-f575-4090-a54a-9a5287d37f74"
3+
authors = ["Tim Holy <tim.holy@gmail.com>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
8+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

test/pkgs/NotifyMe/src/NotifyMe.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module NotifyMe
2+
3+
using Requires, UUIDs
4+
5+
const notified_args = []
6+
add_require(args...) = push!(notified_args, args)
7+
8+
function __init__()
9+
push!(Requires.notified_pkgs, Base.PkgId(UUID(0x545cf9b9f5754090a54a9a5287d37f74), "NotifyMe"))
10+
end
11+
12+
end # module

test/runtests.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ end
113113
@eval using FooAfterPC
114114
@eval using FooSubAfterNPC
115115
@eval using FooSubAfterPC
116+
117+
pop!(LOAD_PATH)
118+
116119
@test FooAfterNPC.flag
117120
@test FooAfterPC.flag
118121
@test :SubModule in names(FooSubAfterNPC)
@@ -121,3 +124,46 @@ end
121124
@test FooSubAfterPC.SubModule.flag
122125
end
123126
end
127+
128+
module EvalModule end
129+
130+
@testset "Notifications" begin
131+
push!(LOAD_PATH, joinpath(@__DIR__, "pkgs"))
132+
@eval using NotifyMe
133+
134+
mktempdir() do pkgsdir
135+
ndir = joinpath("NotifyTarget", "src")
136+
cd(pkgsdir) do
137+
mkpath(ndir)
138+
cd(ndir) do
139+
open("NotifyTarget.jl", "w") do io
140+
println(io, """
141+
module NotifyTarget
142+
using Requires
143+
function __init__()
144+
@require Example="7876af07-990d-54b4-ab0e-23690620f79a" begin
145+
f(x) = 2x
146+
end
147+
end
148+
end
149+
""")
150+
end
151+
end
152+
end
153+
push!(LOAD_PATH, pkgsdir)
154+
@test isempty(NotifyMe.notified_args)
155+
@eval using NotifyTarget
156+
@test isempty(NotifyMe.notified_args)
157+
@eval using Example
158+
@test length(NotifyMe.notified_args) == 1
159+
nargs = NotifyMe.notified_args[1]
160+
@test nargs[1] == joinpath(pkgsdir, ndir, "NotifyTarget.jl")
161+
@test nargs[2] == NotifyTarget
162+
@test nargs[3] == "7876af07-990d-54b4-ab0e-23690620f79a"
163+
@test nargs[4] == "Example"
164+
Core.eval(EvalModule, nargs[5])
165+
@test Base.invokelatest(EvalModule.f, 3) == 6
166+
end
167+
168+
pop!(LOAD_PATH)
169+
end

0 commit comments

Comments
 (0)