File tree 2 files changed +12
-12
lines changed
2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -640,17 +640,19 @@ function is_testsetup_file(filepath)
640
640
)
641
641
end
642
642
643
- # like `relpath` but assumes `path` is nested under `startdir`, else just returns `path`
644
- function nestedrelpath (path, startdir)
645
- path == startdir && return " ."
643
+ # Like `relpath` but assumes `path` is nested under `startdir`, else just returns `path`.
644
+ # Always returns a `SubString` to be type-stable.
645
+ function nestedrelpath (path:: T , startdir:: AbstractString ) where {T <: AbstractString }
646
+ path == startdir && return SubString {T} (" ." )
646
647
relp = chopprefix (path, startdir)
648
+ relp == path && return relp
647
649
sep = Base. Filesystem. path_separator
648
650
if endswith (startdir, sep)
649
651
return relp
650
652
elseif startswith (relp, sep)
651
653
return chopprefix (relp, sep)
652
- else
653
- return path
654
+ else # `startdir` was a prefix of `path` but not a directory
655
+ return SubString {T} ( path)
654
656
end
655
657
end
656
658
Original file line number Diff line number Diff line change @@ -395,13 +395,11 @@ end
395
395
@test nestedrelpath (path, " test/dir/other" ) == " test/dir/foo_test.jl"
396
396
@test nestedrelpath (path, " test/dir/other/bar_test.jl" ) == " test/dir/foo_test.jl"
397
397
398
- @static if isdefined (Base, Symbol (" @allocations" )) # added in Julia v1.9
399
- @test 2 >= @allocations (nestedrelpath (path, " test" ))
400
- @test 2 >= @allocations (nestedrelpath (path, " test/dir" ))
401
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/foo_test.jl" ))
402
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other" ))
403
- @test 1 >= @allocations (nestedrelpath (path, " test/dir/other/bar_test.jl" ))
404
- end
398
+ # leading '/' doesn't get ignored or stripped
399
+ @test nestedrelpath (" /a/b/c" , " /a/b" ) == " c"
400
+ @test nestedrelpath (" /a/b/c" , " a/b" ) == " /a/b/c"
401
+ @test nestedrelpath (" /a/b" , " /a/b/c" ) == " /a/b"
402
+ @test nestedrelpath (" /a/b" , " c" ) == " /a/b"
405
403
end
406
404
407
405
end # internals.jl testset
You can’t perform that action at this time.
0 commit comments