Skip to content

Commit 7ce79b1

Browse files
authored
Merge pull request #39 from oxinabox/patch-2
Correct module lookup in compat macro
2 parents 9a5eeb4 + 5a22bad commit 7ce79b1

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/compat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ julia> myjoin("/Users/rory/repos", "FilePaths.jl")
3939
```
4040
"""
4141
macro compat(ex)
42-
mod = @__MODULE__
42+
mod::Module = QuoteNode(__module__).value
4343
new_ex = compat_exp(mod, deepcopy(ex))
4444

4545
return quote

test/compat.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,19 @@ end
3737
# Test for inline definitions
3838
FilePaths.@compat inline(x::AbstractPath, y::AbstractPath) = relative(x, y)
3939

40+
41+
# Test for custom path type
42+
struct MyPath <: AbstractPath
43+
x::String
4044
end
4145

46+
__init__() = FilePathsBase.register(MyPath)
47+
FilePathsBase.ispathtype(::Type{MyPath}, str::AbstractString) = startswith(str, "mypath://")
48+
49+
FilePaths.@compat mypath_testem(path::MyPath) = "**"*path.x
50+
51+
end # TestPkg module
52+
4253
@testset "@compat" begin
4354
cd(abs(parent(Path(@__FILE__)))) do
4455
reg = Sys.iswindows() ? "..\\src\\FilePaths.jl" : "../src/FilePaths.jl"
@@ -117,5 +128,10 @@ end
117128
# Mixing strings and paths should also work here
118129
@test TestPkg.inline(string(p), home()) == relative(p, home())
119130
end
131+
132+
@testset "Custom path type" begin
133+
@test TestPkg.mypath_testem(TestPkg.MyPath("mypath://foo")) == "**mypath://foo"
134+
@test TestPkg.mypath_testem("mypath://foo") == "**mypath://foo"
135+
end
120136
end
121137
end

0 commit comments

Comments
 (0)