1
1
using Test
2
2
3
- function writepkg (name, precomp:: Bool , submod :: Bool )
3
+ function writepkg (name, precomp:: Bool , sub :: Union{Symbol, Nothing} )
4
4
action = """
5
5
global flag = true
6
6
"""
7
7
8
- if submod
9
- open (" $(name) _submod.jl" , " w" ) do io
10
- println (io, """
11
- export SubModule
12
- module SubModule
13
- using Colors
14
- flag = true
15
- end
16
- """ )
8
+ if sub === :module
9
+ sub_action = """
10
+ export SubModule
11
+ module SubModule
12
+ using Colors
13
+ flag = true
14
+ end
15
+ """
16
+ elseif sub === :file
17
+ sub_action = """
18
+ global subflag = false
19
+ @init begin
20
+ global subflag = true
21
+ end
22
+ """
23
+ end
24
+ @assert sub === :module || sub === :file || sub === nothing
25
+
26
+ if sub != = nothing
27
+ open (" $(name) _sub.jl" , " w" ) do io
28
+ println (io, sub_action)
17
29
end
18
30
19
31
action *= """
20
- include("$(name) _submod .jl")
32
+ include("$(name) _sub .jl")
21
33
"""
22
34
end
23
35
@@ -31,10 +43,8 @@ using Requires
31
43
32
44
flag = false
33
45
34
- function __init__()
35
- @require Colors="5ae59095-9a9b-59fe-a467-6f913c188581" begin
36
- $(action)
37
- end
46
+ @init @require Colors="5ae59095-9a9b-59fe-a467-6f913c188581" begin
47
+ $(action)
38
48
end
39
49
40
50
end
48
58
npcdir = joinpath (" FooNPC" , " src" )
49
59
mkpath (npcdir)
50
60
cd (npcdir) do
51
- writepkg (" FooNPC" , false , false )
61
+ writepkg (" FooNPC" , false , nothing )
52
62
end
53
63
npcdir = joinpath (" FooPC" , " src" )
54
64
mkpath (npcdir)
55
65
cd (npcdir) do
56
- writepkg (" FooPC" , true , false )
66
+ writepkg (" FooPC" , true , nothing )
67
+ end
68
+ npcdir = joinpath (" FooSubModNPC" , " src" )
69
+ mkpath (npcdir)
70
+ cd (npcdir) do
71
+ writepkg (" FooSubModNPC" , false , :module )
57
72
end
58
- npcdir = joinpath (" FooSubNPC " , " src" )
73
+ npcdir = joinpath (" FooSubModPC " , " src" )
59
74
mkpath (npcdir)
60
75
cd (npcdir) do
61
- writepkg (" FooSubNPC " , false , true )
76
+ writepkg (" FooSubModPC " , true , :module )
62
77
end
63
- npcdir = joinpath (" FooSubPC " , " src" )
78
+ npcdir = joinpath (" FooSubIncNPC " , " src" )
64
79
mkpath (npcdir)
65
80
cd (npcdir) do
66
- writepkg (" FooSubPC" , true , true )
81
+ writepkg (" FooSubIncNPC" , false , :file )
82
+ end
83
+ npcdir = joinpath (" FooSubIncPC" , " src" )
84
+ mkpath (npcdir)
85
+ cd (npcdir) do
86
+ writepkg (" FooSubIncPC" , true , :file )
67
87
end
68
88
end
69
89
push! (LOAD_PATH , pkgsdir)
72
92
@test ! FooNPC. flag
73
93
@eval using FooPC
74
94
@test ! FooPC. flag
75
- @eval using FooSubNPC
76
- @test ! (:SubModule in names (FooSubNPC))
77
- @eval using FooSubPC
78
- @test ! (:SubModule in names (FooSubPC))
95
+ @eval using FooSubModNPC
96
+ @test ! (:SubModule in names (FooSubModNPC))
97
+ @eval using FooSubModPC
98
+ @test ! (:SubModule in names (FooSubModPC))
99
+ @eval using FooSubIncPC
100
+ @test ! isdefined (FooSubIncPC, :subflag )
101
+ @eval using FooSubIncNPC
102
+ @test ! isdefined (FooSubIncNPC, :subflag )
79
103
80
104
@eval using Colors
81
105
82
106
@test FooNPC. flag
83
107
@test FooPC. flag
84
- @test :SubModule in names (FooSubNPC)
85
- @test FooSubNPC. SubModule. flag
86
- @test :SubModule in names (FooSubPC)
87
- @test FooSubPC. SubModule. flag
108
+ @test :SubModule in names (FooSubModNPC)
109
+ @test FooSubModNPC. SubModule. flag
110
+ @test :SubModule in names (FooSubModPC)
111
+ @test FooSubModPC. SubModule. flag
112
+ @test_broken FooSubIncPC. subflag
113
+ @test_broken FooSubIncNPC. subflag
88
114
89
115
cd (pkgsdir) do
90
116
npcdir = joinpath (" FooAfterNPC" , " src" )
91
117
mkpath (npcdir)
92
118
cd (npcdir) do
93
- writepkg (" FooAfterNPC" , false , false )
119
+ writepkg (" FooAfterNPC" , false , nothing )
94
120
end
95
121
pcidr = joinpath (" FooAfterPC" , " src" )
96
122
mkpath (pcidr)
97
123
cd (pcidr) do
98
- writepkg (" FooAfterPC" , true , false )
124
+ writepkg (" FooAfterPC" , true , nothing )
125
+ end
126
+ sanpcdir = joinpath (" FooSubModAfterNPC" , " src" )
127
+ mkpath (sanpcdir)
128
+ cd (sanpcdir) do
129
+ writepkg (" FooSubModAfterNPC" , false , :module )
99
130
end
100
- sanpcdir = joinpath (" FooSubAfterNPC" , " src" )
131
+ sapcdir = joinpath (" FooSubModAfterPC" , " src" )
132
+ mkpath (sapcdir)
133
+ cd (sapcdir) do
134
+ writepkg (" FooSubModAfterPC" , true , :module )
135
+ end
136
+ sanpcdir = joinpath (" FooSubIncAfterNPC" , " src" )
101
137
mkpath (sanpcdir)
102
138
cd (sanpcdir) do
103
- writepkg (" FooSubAfterNPC " , false , true )
139
+ writepkg (" FooSubIncAfterNPC " , false , :file )
104
140
end
105
- sapcdir = joinpath (" FooSubAfterPC " , " src" )
141
+ sapcdir = joinpath (" FooSubIncAfterPC " , " src" )
106
142
mkpath (sapcdir)
107
143
cd (sapcdir) do
108
- writepkg (" FooSubAfterPC " , true , true )
144
+ writepkg (" FooSubIncAfterPC " , true , :file )
109
145
end
110
146
end
111
147
112
148
@eval using FooAfterNPC
113
149
@eval using FooAfterPC
114
- @eval using FooSubAfterNPC
115
- @eval using FooSubAfterPC
150
+ @eval using FooSubModAfterNPC
151
+ @eval using FooSubModAfterPC
152
+ @eval using FooSubIncAfterNPC
153
+ @eval using FooSubIncModAfterPC
116
154
@test FooAfterNPC. flag
117
155
@test FooAfterPC. flag
118
- @test :SubModule in names (FooSubAfterNPC)
119
- @test FooSubAfterNPC. SubModule. flag
120
- @test :SubModule in names (FooSubAfterPC)
121
- @test FooSubAfterPC. SubModule. flag
156
+ @test :SubModule in names (FooSubModAfterNPC)
157
+ @test FooSubModAfterNPC. SubModule. flag
158
+ @test :SubModule in names (FooSubModAfterPC)
159
+ @test FooSubModAfterPC. SubModule. flag
160
+ @test FooSubIncAfterPC. subflag
161
+ @test FooSubIncAfterNPC. subflag
162
+
122
163
end
123
164
end
0 commit comments