From e448911ab8b66b980ad4c5076ec09d156f30e5e9 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Mon, 11 Sep 2023 16:32:57 +0100 Subject: [PATCH 1/3] Remove the requirement for {here} --- DESCRIPTION | 1 - tests/testthat/test-file_size.R | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8a8deba..df018e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,7 +41,6 @@ Imports: utils Suggests: covr, - here, spelling, testthat (>= 3.0.0) RdMacros: diff --git a/tests/testthat/test-file_size.R b/tests/testthat/test-file_size.R index bcab9db..c51ecce 100644 --- a/tests/testthat/test-file_size.R +++ b/tests/testthat/test-file_size.R @@ -43,7 +43,7 @@ test_that("Output is identical over time", { }) test_that("Errors if supplied with invalid filepath", { - expect_error(file_size(here::here("reference_files"))) + expect_error(file_size(test_path("reference_files"))) expect_error(file_size(NA)) expect_error(file_size(NULL)) }) From 3c9460d6334ad9408add929bbadf9f60edeb0f23 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Mon, 11 Sep 2023 16:33:46 +0100 Subject: [PATCH 2/3] Split the tests into Windows / UNIX This is required because Windows will see .txt files as bigger due to the end of line characters. --- tests/testthat/_snaps/{ => windows}/file_size.md | 2 +- tests/testthat/test-file_size.R | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) rename tests/testthat/_snaps/{ => windows}/file_size.md (94%) diff --git a/tests/testthat/_snaps/file_size.md b/tests/testthat/_snaps/windows/file_size.md similarity index 94% rename from tests/testthat/_snaps/file_size.md rename to tests/testthat/_snaps/windows/file_size.md index d2cbe3a..bb84b21 100644 --- a/tests/testthat/_snaps/file_size.md +++ b/tests/testthat/_snaps/windows/file_size.md @@ -11,7 +11,7 @@ 3 iris.csv CSV 4 kB 4 mtcars.sav SPSS 4 kB 5 plant-growth.rds RDS 316 B - 6 puromycin.txt Text 418 B + 6 puromycin.txt Text 442 B 7 stackloss.fst FST 897 B 8 swiss.tsv TSV 1 kB diff --git a/tests/testthat/test-file_size.R b/tests/testthat/test-file_size.R index c51ecce..477fc49 100644 --- a/tests/testthat/test-file_size.R +++ b/tests/testthat/test-file_size.R @@ -38,8 +38,15 @@ test_that("Returns sizes in alphabetical order", { }) test_that("Output is identical over time", { - expect_snapshot(file_size(test_path("files"))) - expect_snapshot(file_size(test_path("files"), "xlsx?")) + # Text files report as larger on Windows so snapshot per OS + os <- ifelse( + "windows" %in% tolower(Sys.info()[["sysname"]]), + "windows", + "UNIX" + ) + + expect_snapshot(file_size(test_path("files")), variant = os) + expect_snapshot(file_size(test_path("files"), "xlsx?"), variant = os) }) test_that("Errors if supplied with invalid filepath", { From 6bf370149e95b885146c567c736515087dde9c36 Mon Sep 17 00:00:00 2001 From: James McMahon Date: Mon, 11 Sep 2023 16:37:11 +0100 Subject: [PATCH 3/3] Add UNIX (non-Windows) test snaps --- tests/testthat/_snaps/UNIX/file_size.md | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/testthat/_snaps/UNIX/file_size.md diff --git a/tests/testthat/_snaps/UNIX/file_size.md b/tests/testthat/_snaps/UNIX/file_size.md new file mode 100644 index 0000000..d2cbe3a --- /dev/null +++ b/tests/testthat/_snaps/UNIX/file_size.md @@ -0,0 +1,28 @@ +# Output is identical over time + + Code + file_size(test_path("files")) + Output + # A tibble: 8 x 2 + name size + + 1 airquality.xls Excel 26 kB + 2 bod.xlsx Excel 5 kB + 3 iris.csv CSV 4 kB + 4 mtcars.sav SPSS 4 kB + 5 plant-growth.rds RDS 316 B + 6 puromycin.txt Text 418 B + 7 stackloss.fst FST 897 B + 8 swiss.tsv TSV 1 kB + +--- + + Code + file_size(test_path("files"), "xlsx?") + Output + # A tibble: 2 x 2 + name size + + 1 airquality.xls Excel 26 kB + 2 bod.xlsx Excel 5 kB +