Skip to content

Commit 4b21f43

Browse files
committed
Slightly overengineered tests for the Base.url backslash issues
1 parent b0e9e4b commit 4b21f43

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/pkg.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ temp_pkg_dir() do
185185
Pkg.pin("Example", v"0.4.0")
186186
@test Pkg.update() == nothing
187187
Pkg.installed()["Example"] == v"0.4.0"
188+
189+
# bug identified in #16850, Base.url \ vs / for non-Base methods
190+
include(Pkg.dir("Example","src","Example.jl"))
191+
meth = first(methods(Example.domath))
192+
fname = string(meth.file)
193+
@test ('\\' in fname) == is_windows()
194+
@test startswith(Base.url(meth), "https://github.com/JuliaLang/Example.jl/tree")
188195
end
189196

190197
# add a directory that is not a git repository

test/reflection.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,50 @@ fLargeTable() = 4
451451
# issue #15280
452452
function f15280(x) end
453453
@test functionloc(f15280)[2] > 0
454+
455+
# bug found in #16850, Base.url with backslashes on Windows
456+
function module_depth(from::Module, to::Module)
457+
if from === to
458+
return 0
459+
else
460+
return 1 + module_depth(from, module_parent(to))
461+
end
462+
end
463+
function has_backslashes(mod::Module)
464+
for n in names(mod, true, true)
465+
isdefined(mod, n) || continue
466+
f = getfield(mod, n)
467+
if isa(f, Module) && module_depth(Main, f) <= module_depth(Main, mod)
468+
continue
469+
end
470+
h = has_backslashes(f)
471+
isnull(h) || return h
472+
end
473+
return Nullable{Method}()
474+
end
475+
function has_backslashes(f::Function)
476+
for m in methods(f)
477+
h = has_backslashes(m)
478+
isnull(h) || return h
479+
end
480+
return Nullable{Method}()
481+
end
482+
function has_backslashes(meth::Method)
483+
if '\\' in string(meth.file)
484+
return Nullable{Method}(meth)
485+
else
486+
return Nullable{Method}()
487+
end
488+
end
489+
has_backslashes(x) = Nullable{Method}()
490+
h16850 = has_backslashes(Base)
491+
if is_windows()
492+
if isnull(h16850)
493+
warn("No methods found in Base with backslashes in file name, ",
494+
"skipping test for Base.url")
495+
else
496+
@test !('\\' in Base.url(get(h16850)))
497+
end
498+
else
499+
@test isnull(h16850)
500+
end

0 commit comments

Comments
 (0)