-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtests.jl
60 lines (53 loc) · 1.5 KB
/
runtests.jl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
module TestContextVariables
using ContextVariables
using ContextVariables: with_variables_impl
using Test
const cvar1 = ContextVar(:cvar1, 42)
const cvar2 = ContextVar{Int}(:cvar2)
const cvar3 = ContextVar(:cvar3)
@testset "typed, w/ default" begin
ok = Ref(0)
@sync @async begin
with_variables() do
@test cvar1[] == 42
cvar1[] = 0
@test cvar1[] == 0
ok[] += 1
@async begin
@test cvar1[] == 0
ok[] += 1
end
with_variables(cvar1 => 1) do
@test cvar1[] == 1
ok[] += 1
end
@test cvar1[] == 0
ok[] += 1
end
end
@test ok[] == 4
end
@testset "typed, w/o default" begin
with_variables_impl() do
@test_throws InexactError cvar2[] = 0.5
@test_throws KeyError cvar2[]
cvar2[] = 1.0
@test cvar2[] === 1
end
end
@testset "untyped, w/o default" begin
with_variables_impl() do
cvar3[] = 1
@test cvar3[] === 1
cvar3[] = 'a'
@test cvar3[] === 'a'
end
end
@testset "show" begin
@test endswith(sprint(show, ContextVar(:x, 42)), "ContextVar(:x, 42)")
@test endswith(sprint(show, ContextVar{Int}(:x)), "ContextVar{$Int}(:x)")
@test endswith(sprint(show, ContextVar(:x)), "ContextVar(:x)")
@test endswith(sprint(show, ContextVar{Union{Missing,Int64}}(:x, 1)),
"ContextVar{Union{Missing, Int64}}(:x, 1)")
end
end # module