Skip to content

Commit 3a8d050

Browse files
committed
compare file paths with normalizePath() rather than identical()
identical() is a byte-for-byte string comparison, but two paths can denote the same file while differing in separators, case, or symlink resolution. normalize both sides before comparing, preserving system.file()'s "" not-found sentinel (normalizePath("") would resolve to the working dir).
1 parent 4ec8181 commit 3a8d050

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/test-arch-system-file.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ RcppParallel:::test_init()
88

99
arch <- .Platform$r_arch
1010

11+
# compare two file paths for equality. system.file() returns "" when a path is
12+
# not found, so preserve that sentinel; otherwise normalize both sides, since
13+
# strings that differ only in separators, case, or symlinks can still denote
14+
# the same file (and normalizePath("") would resolve to the working directory).
15+
samePath <- function(a, b) {
16+
norm <- function(p) {
17+
if (nzchar(p)) normalizePath(p, winslash = "/", mustWork = FALSE) else p
18+
}
19+
identical(norm(a), norm(b))
20+
}
21+
1122
# with no arch subdirectory (the usual case off Windows), archSystemFile()
1223
# should be equivalent to a plain system.file() call
1324
if (!nzchar(arch)) {
14-
assert(identical(
25+
assert(samePath(
1526
archSystemFile("include"),
1627
system.file("include", package = "RcppParallel")
1728
))
18-
assert(identical(
29+
assert(samePath(
1930
archSystemFile("include", "RcppParallel.h"),
2031
system.file("include/RcppParallel.h", package = "RcppParallel")
2132
))
@@ -28,8 +39,8 @@ expected <- function(dir, name = NULL) {
2839
system.file(paste(parts, collapse = "/"), package = "RcppParallel")
2940
}
3041

31-
assert(identical(archSystemFile("lib"), expected("lib")))
32-
assert(identical(archSystemFile("lib", "libtbb.so"), expected("lib", "libtbb.so")))
42+
assert(samePath(archSystemFile("lib"), expected("lib")))
43+
assert(samePath(archSystemFile("lib", "libtbb.so"), expected("lib", "libtbb.so")))
3344

3445
# a real, shipped resource resolves to an existing path
3546
header <- archSystemFile("include", "RcppParallel.h")

0 commit comments

Comments
 (0)