Skip to content

Commit

Permalink
Merge pull request #39 from oxinabox/patch-2
Browse files Browse the repository at this point in the history
Correct module lookup in compat macro
  • Loading branch information
rofinn authored Jul 17, 2019
2 parents 9a5eeb4 + 5a22bad commit 7ce79b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ julia> myjoin("/Users/rory/repos", "FilePaths.jl")
```
"""
macro compat(ex)
mod = @__MODULE__
mod::Module = QuoteNode(__module__).value
new_ex = compat_exp(mod, deepcopy(ex))

return quote
Expand Down
16 changes: 16 additions & 0 deletions test/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,19 @@ end
# Test for inline definitions
FilePaths.@compat inline(x::AbstractPath, y::AbstractPath) = relative(x, y)


# Test for custom path type
struct MyPath <: AbstractPath
x::String
end

__init__() = FilePathsBase.register(MyPath)
FilePathsBase.ispathtype(::Type{MyPath}, str::AbstractString) = startswith(str, "mypath://")

FilePaths.@compat mypath_testem(path::MyPath) = "**"*path.x

end # TestPkg module

@testset "@compat" begin
cd(abs(parent(Path(@__FILE__)))) do
reg = Sys.iswindows() ? "..\\src\\FilePaths.jl" : "../src/FilePaths.jl"
Expand Down Expand Up @@ -117,5 +128,10 @@ end
# Mixing strings and paths should also work here
@test TestPkg.inline(string(p), home()) == relative(p, home())
end

@testset "Custom path type" begin
@test TestPkg.mypath_testem(TestPkg.MyPath("mypath://foo")) == "**mypath://foo"
@test TestPkg.mypath_testem("mypath://foo") == "**mypath://foo"
end
end
end

0 comments on commit 7ce79b1

Please sign in to comment.