Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the file size test #105

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Imports:
utils
Suggests:
covr,
here,
spelling,
testthat (>= 3.0.0)
RdMacros:
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/_snaps/windows/file_size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Output is identical over time

Code
file_size(test_path("files"))
Output
# A tibble: 8 x 2
name size
<chr> <chr>
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 442 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
<chr> <chr>
1 airquality.xls Excel 26 kB
2 bod.xlsx Excel 5 kB

13 changes: 10 additions & 3 deletions tests/testthat/test-file_size.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ 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", {
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))
})
Expand Down