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)
633
633
)
634
634
end
635
635
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} (" ." )
639
640
relp = chopprefix (path, startdir)
641
+ relp == path && return relp
640
642
sep = Base. Filesystem. path_separator
641
643
if endswith (startdir, sep)
642
644
return relp
643
645
elseif startswith (relp, sep)
644
646
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)
647
649
end
648
650
end
649
651
Original file line number Diff line number Diff line change @@ -394,13 +394,11 @@ end
394
394
@test nestedrelpath (path, " test/dir/other" ) == " test/dir/foo_test.jl"
395
395
@test nestedrelpath (path, " test/dir/other/bar_test.jl" ) == " test/dir/foo_test.jl"
396
396
397
- @static if isdefined (Base, Symbol (" @allocations" )) # added in Julia v1.9
398
- @test 2 >= @allocations (nestedrelpath (path, " test" ))
399
- @test 2 >= @allocations (nestedrelpath (path, " test/dir" ))
400
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/foo_test.jl" ))
401
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other" ))
402
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other/bar_test.jl" ))
403
- end
397
+ # leading '/' doesn't get ignored or stripped
398
+ @test nestedrelpath (" /a/b/c" , " /a/b" ) == " c"
399
+ @test nestedrelpath (" /a/b/c" , " a/b" ) == " /a/b/c"
400
+ @test nestedrelpath (" /a/b" , " /a/b/c" ) == " /a/b"
401
+ @test nestedrelpath (" /a/b" , " c" ) == " /a/b"
404
402
end
405
403
406
404
end # internals.jl testset
You can’t perform that action at this time.
0 commit comments