Skip to content

Commit 8446e46

Browse files
committed
Tests on windows. Fix #37
1 parent 4241c4b commit 8446e46

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

tests/testthat/test_all.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,16 @@ test_that("option setting works", {
122122
setCacheBuildDir(tempdir())
123123
addCacheSearchEnvironment("cacheEnv")
124124

125+
# Windows uses double slashes, which get consumed weirdly by grep;
126+
# This command will replace double slashes with quadruple slashes,
127+
# which behave correctly in grep.
128+
grep_tempdir = gsub("\\\\", "\\\\\\\\", tempdir())
125129
# capture output and check
126130
options_out <- capture_messages(simpleCacheOptions())
127131

128-
expect_true(grepl(tempdir(), options_out[1]))
129-
expect_true(grepl(tempdir(), options_out[2]))
130-
expect_true(grepl(tempdir(), options_out[3]))
132+
expect_true(grepl(grep_tempdir, options_out[1]))
133+
expect_true(grepl(grep_tempdir, options_out[2]))
134+
expect_true(grepl(grep_tempdir, options_out[3]))
131135
expect_true(grepl("cacheEnv", options_out[4]))
132136

133137
# reset the cache search option

tests/testthat/test_cache_lifespan.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ my_test_that("Cache file is replaced if no lifespan is specified and recreate=TR
4343
mySimpleCache("testDF", instruction={ buildTestFrame() })
4444
expect_equal(1, countCacheItems())
4545
expect_true(file_test("-f", fp))
46-
t0 = file.info(fp)$ctime
46+
t0 = file.info(fp)$mtime
4747
Sys.sleep(1) # Delay so that our time comparison can work.
4848
mySimpleCache("testDF", recreate=TRUE, instruction={ buildTestFrame() })
4949
expect_equal(1, countCacheItems())
50-
t1 = file.info(fp)$ctime
50+
t1 = file.info(fp)$mtime
5151
expect_true(t1 > t0)
5252
})
5353

@@ -59,10 +59,10 @@ my_test_that("Cache remains unchanged if younger than explicit lifespan", {
5959
mySimpleCache("testDF", instruction={ buildTestFrame() })
6060
expect_equal(1, countCacheItems())
6161
expect_true(file_test("-f", fp))
62-
t0 = file.info(fp)$ctime
62+
t0 = file.info(fp)$mtime
6363
mySimpleCache("testDF", lifespan=0.5, instruction={ buildTestFrame() })
6464
expect_equal(1, countCacheItems())
65-
t1 = file.info(fp)$ctime
65+
t1 = file.info(fp)$mtime
6666
expect_true(t1 == t0)
6767
})
6868

@@ -74,11 +74,11 @@ my_test_that("Cache is replaced if older than explicit lifespan", {
7474
mySimpleCache("testDF", instruction={ buildTestFrame() })
7575
expect_equal(1, countCacheItems())
7676
expect_true(file_test("-f", fp))
77-
t0 = file.info(fp)$ctime
77+
t0 = file.info(fp)$mtime
7878
Sys.sleep(1) # Time difference comparison reliability.
7979
mySimpleCache("testDF", lifespan=0, instruction={ buildTestFrame() })
8080
expect_equal(1, countCacheItems())
81-
t1 = file.info(fp)$ctime
81+
t1 = file.info(fp)$mtime
8282
expect_true(t1 > t0)
8383
})
8484

@@ -90,11 +90,11 @@ my_test_that("Cache is replaced if recreate=TRUE even if cache is fresh", {
9090
mySimpleCache("testDF", instruction={ buildTestFrame() })
9191
expect_true(file_test("-f", fp))
9292
expect_equal(1, countCacheItems())
93-
t0 = file.info(fp)$ctime
93+
t0 = file.info(fp)$mtime
9494
Sys.sleep(1) # Time difference comparison reliability.
9595
mySimpleCache("testDF", recreate=TRUE, lifespan=0, instruction={ buildTestFrame() })
9696
expect_equal(1, countCacheItems())
97-
t1 = file.info(fp)$ctime
97+
t1 = file.info(fp)$mtime
9898
expect_true(t1 > t0)
9999
})
100100

@@ -104,10 +104,10 @@ my_test_that("simpleCache can pick up option specifying max cache age.", {
104104
expect_false(file_test("-f", fp))
105105
mySimpleCache("testDF", instruction={ buildTestFrame() })
106106
expect_true(file_test("-f", fp))
107-
t0 = file.info(fp)$ctime
107+
t0 = file.info(fp)$mtime
108108
Sys.sleep(1) # Time difference comparison reliability.
109109
mySimpleCache("testDF", instruction={ buildTestFrame() })
110-
t1 = file.info(fp)$ctime
110+
t1 = file.info(fp)$mtime
111111
expect_true(t1 > t0)
112112
})
113113

@@ -117,12 +117,12 @@ my_test_that("Direct lifespan specification is preferred to background option",
117117
expect_false(file_test("-f", fp))
118118
mySimpleCache("testDF", instruction={ buildTestFrame() })
119119
expect_true(file_test("-f", fp))
120-
t0 = file.info(fp)$ctime
120+
t0 = file.info(fp)$mtime
121121
Sys.sleep(1)
122122
mySimpleCache("testDF", instruction={ buildTestFrame() })
123123
expect_equal(t0, file.info(fp)$ctime) # Cache is fresh via MAX.CACHE.AGE.
124124
Sys.sleep(1) # Time difference comparison reliability.
125125
mySimpleCache("testDF", lifespan=0, instruction={ buildTestFrame() })
126-
t1 = file.info(fp)$ctime
126+
t1 = file.info(fp)$mtime
127127
expect_true(t1 > t0) # Cache is stale via lifespan.
128128
})

0 commit comments

Comments
 (0)