File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -633,17 +633,19 @@ function is_testsetup_file(filepath)
633633 )
634634end
635635
636- # like `relpath` but assumes `path` is nested under `startdir`, else just returns `path`
637- function nestedrelpath (path, startdir)
638- path == startdir && return " ."
636+ # Like `relpath` but assumes `path` is nested under `startdir`, else just returns `path`.
637+ # Always returns a `SubString` to be type-stable.
638+ function nestedrelpath (path:: T , startdir:: AbstractString ) where {T <: AbstractString }
639+ path == startdir && return SubString {T} (" ." )
639640 relp = chopprefix (path, startdir)
641+ relp == path && return relp
640642 sep = Base. Filesystem. path_separator
641643 if endswith (startdir, sep)
642644 return relp
643645 elseif startswith (relp, sep)
644646 return chopprefix (relp, sep)
645- else
646- return path
647+ else # `startdir` was a prefix of `path` but not a directory
648+ return SubString {T} ( path)
647649 end
648650end
649651
Original file line number Diff line number Diff line change @@ -391,13 +391,11 @@ end
391391 @test nestedrelpath (path, " test/dir/other" ) == " test/dir/foo_test.jl"
392392 @test nestedrelpath (path, " test/dir/other/bar_test.jl" ) == " test/dir/foo_test.jl"
393393
394- @static if isdefined (Base, Symbol (" @allocations" )) # added in Julia v1.9
395- @test 2 >= @allocations (nestedrelpath (path, " test" ))
396- @test 2 >= @allocations (nestedrelpath (path, " test/dir" ))
397- @test 1 >= @allocations (nestedrelpath (path, " test/dir/foo_test.jl" ))
398- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other" ))
399- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other/bar_test.jl" ))
400- end
394+ # leading '/' doesn't get ignored or stripped
395+ @test nestedrelpath (" /a/b/c" , " /a/b" ) == " c"
396+ @test nestedrelpath (" /a/b/c" , " a/b" ) == " /a/b/c"
397+ @test nestedrelpath (" /a/b" , " /a/b/c" ) == " /a/b"
398+ @test nestedrelpath (" /a/b" , " c" ) == " /a/b"
401399end
402400
403401end # internals.jl testset
You can’t perform that action at this time.
0 commit comments