Skip to content

Commit 6b61322

Browse files
committed
Reorder piracy.jl
1 parent 94a9c7a commit 6b61322

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

src/piracy.jl

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
"""
2+
test_piracy(m::Module)
3+
4+
Test that `m` does not commit type piracy.
5+
See [Julia documentation](https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy)
6+
for more information about type piracy.
7+
8+
# Keyword Arguments
9+
- `broken::Bool = false`: If true, it uses `@test_broken` instead of
10+
`@test`.
11+
- `treat_as_own = Union{Function, Type}[]`: The types in this container
12+
are considered to be "owned" by the module `m`. This is useful for
13+
testing packages that deliberately commit some type piracy, e.g. modules
14+
adding higher-level functionality to a lightweight C-wrapper, or packages
15+
that are extending `StatsAPI.jl`.
16+
"""
17+
function test_piracy(m::Module; broken::Bool = false, kwargs...)
18+
v = Piracy.hunt(m; kwargs...)
19+
if !isempty(v)
20+
printstyled(
21+
stderr,
22+
"Possible type-piracy detected:\n";
23+
bold = true,
24+
color = Base.error_color(),
25+
)
26+
show(stderr, MIME"text/plain"(), v)
27+
println(stderr)
28+
end
29+
if broken
30+
@test_broken isempty(v)
31+
else
32+
@test isempty(v)
33+
end
34+
end
35+
136
module Piracy
237

338
using Test: @test, @test_broken
@@ -172,37 +207,3 @@ function hunt(pkg::Base.PkgId; from::Module, kwargs...)
172207
end
173208

174209
end # module
175-
176-
"""
177-
test_piracy(m::Module)
178-
179-
Test that `m` does not commit type piracy.
180-
See [Julia documentation](https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy) for more information about type piracy.
181-
182-
# Keyword Arguments
183-
- `broken::Bool = false`: If true, it uses `@test_broken` instead of
184-
`@test`.
185-
- `treat_as_own = Union{Function, Type}[]`: The types in this container
186-
are considered to be "owned" by the module `m`. This is useful for
187-
testing packages that deliberately commit some type piracy, e.g. modules
188-
adding higher-level functionality to a lightweight C-wrapper, or packages
189-
that are extending `StatsAPI.jl`.
190-
"""
191-
function test_piracy(m::Module; broken::Bool = false, kwargs...)
192-
v = Piracy.hunt(m; kwargs...)
193-
if !isempty(v)
194-
printstyled(
195-
stderr,
196-
"Possible type-piracy detected:\n";
197-
bold = true,
198-
color = Base.error_color(),
199-
)
200-
show(stderr, MIME"text/plain"(), v)
201-
println(stderr)
202-
end
203-
if broken
204-
@test_broken isempty(v)
205-
else
206-
@test isempty(v)
207-
end
208-
end

0 commit comments

Comments
 (0)