Skip to content

Commit b6df41a

Browse files
fix for windows
1 parent 8a30c72 commit b6df41a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/testthat/test-testing.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
test_that("local_test_setup changes back to old cache location", {
2+
split_path <- function(x) {
3+
if (Sys.info()[1] == "Windows") {
4+
# not on other platforms as normalizePath messes up /private/var and /var
5+
x <- normalizePath(x, mustWork = FALSE)
6+
}
7+
unlist(strsplit(x, .Platform$file.sep, fixed = TRUE))
8+
}
29
withr::defer(cache_deactivate(verbose = FALSE))
310
old <- cache_info(format = "tabular")
411
cache_activate(verbose = FALSE)
512

613
test <- function() {
714
local_test_setup()
8-
base <- unlist(strsplit(tempfile(), .Platform$file.sep, fixed = TRUE))[2]
15+
base <- split_path(tempfile())[2]
916
expect_equal(
10-
unlist(strsplit(cache_info(format = "tabular")$location, .Platform$file.sep, fixed = TRUE))[2],
17+
split_path(cache_info(format = "tabular")$location)[2],
1118
base
1219
)
1320
}
@@ -19,12 +26,19 @@ test_that("local_test_setup changes back to old cache location", {
1926
test_that("local_test_setup changes back to old cache location", {
2027
old <- cache_info(format = "tabular")
2128
# don't activate
29+
split_path <- function(x) {
30+
if (Sys.info()[1] == "Windows") {
31+
# not on other platforms as normalizePath messes up /private/var and /var
32+
x <- normalizePath(x, mustWork = FALSE)
33+
}
34+
unlist(strsplit(x, .Platform$file.sep, fixed = TRUE))
35+
}
2236

2337
test <- function() {
2438
local_test_setup()
25-
base <- unlist(strsplit(tempfile(), .Platform$file.sep, fixed = TRUE))[2]
39+
base <- split_path(tempfile())[2]
2640
expect_equal(
27-
unlist(strsplit(cache_info(format = "tabular")$location, .Platform$file.sep, fixed = TRUE))[2],
41+
split_path(cache_info(format = "tabular")$location)[2],
2842
base
2943
)
3044
}

0 commit comments

Comments
 (0)