diff --git a/tests/testthat/_snaps/edition-1/read-csv.md b/tests/testthat/_snaps/edition-1/read-csv.md new file mode 100644 index 00000000..263250cb --- /dev/null +++ b/tests/testthat/_snaps/edition-1/read-csv.md @@ -0,0 +1,41 @@ +# warning lines are correct after skipping + + Code + out3 <- read_csv(I("v1,v2\n\n1,2\n\n3,4"), col_types = "i") + Warning + Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two. + 2 parsing failures. + row col expected actual file + 1 -- 1 columns 2 columns literal data + 2 -- 1 columns 2 columns literal data + +--- + + Code + out4 <- read_csv(I("v1,v2\n#foo\n1,2\n#bar\n3,4"), col_types = "i", comment = "#") + Warning + Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two. + 2 parsing failures. + row col expected actual file + 1 -- 1 columns 2 columns literal data + 2 -- 1 columns 2 columns literal data + +# too few or extra col_types generates warnings + + Code + out1 <- read_csv(I("v1,v2\n1,2"), col_types = "i", lazy = FALSE) + Warning + Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two. + 1 parsing failure. + row col expected actual file + 1 -- 1 columns 2 columns literal data + +# comments are ignored regardless of where they appear + + Code + out4 <- read_csv(I("x,y\n1,#comment"), comment = "#", col_types = "cc") + Warning + 1 parsing failure. + row col expected actual file + 1 -- 2 columns 1 columns literal data + diff --git a/tests/testthat/_snaps/edition-2/read-csv.md b/tests/testthat/_snaps/edition-2/read-csv.md new file mode 100644 index 00000000..fd6e264a --- /dev/null +++ b/tests/testthat/_snaps/edition-2/read-csv.md @@ -0,0 +1,5 @@ +# comments are ignored regardless of where they appear + + Code + out4 <- read_csv(I("x,y\n1,#comment"), comment = "#", col_types = "cc") + diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index dfa9c4b0..85ac6076 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -42,3 +42,7 @@ skip_if_edition_second <- function() { skip_if_edition_first <- function() { skip_if(edition_first()) } + +edition_variant <- function() { + paste0("edition-", edition_get()) +} diff --git a/tests/testthat/test-read-csv.R b/tests/testthat/test-read-csv.R index 0a1e29ea..62d08d1f 100644 --- a/tests/testthat/test-read-csv.R +++ b/tests/testthat/test-read-csv.R @@ -135,8 +135,14 @@ test_that("warning lines are correct after skipping", { expect_equal(problems(out2)$row, 1) - expect_warning(out3 <- read_csv(I("v1,v2\n\n1,2\n\n3,4"), col_types = "i")) - expect_warning(out4 <- read_csv(I("v1,v2\n#foo\n1,2\n#bar\n3,4"), col_types = "i", comment = "#")) + expect_snapshot( + out3 <- read_csv(I("v1,v2\n\n1,2\n\n3,4"), col_types = "i"), + variant = edition_variant() + ) + expect_snapshot( + out4 <- read_csv(I("v1,v2\n#foo\n1,2\n#bar\n3,4"), col_types = "i", comment = "#"), + variant = edition_variant() + ) expect_equal(problems(out3)$row, c(1, 2)) @@ -158,7 +164,10 @@ test_that("extra columns generates warnings", { test_that("too few or extra col_types generates warnings", { skip_if_edition_second() - expect_warning(out1 <- read_csv(I("v1,v2\n1,2"), col_types = "i", lazy = FALSE)) + expect_snapshot( + out1 <- read_csv(I("v1,v2\n1,2"), col_types = "i", lazy = FALSE), + variant = edition_variant() + ) expect_equal(problems(out1)$expected, "1 columns") expect_equal(problems(out1)$actual, "2 columns") @@ -219,7 +228,10 @@ test_that("comments are ignored regardless of where they appear", { expect_equal(out2$x, 1) expect_equal(out3$x, 1) - out4 <- read_csv(I("x,y\n1,#comment"), comment = "#", col_types = "cc") + expect_snapshot( + out4 <- read_csv(I("x,y\n1,#comment"), comment = "#", col_types = "cc"), + variant = edition_variant() + ) expect_equal(out4$y, NA_character_) expect_warning(out5 <- read_csv(I("x1,x2,x3\nA2,B2,C2\nA3#,B2,C2\nA4,A5,A6"), comment = "#", lazy = FALSE)) diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R index 6c93356f..1a1351d5 100644 --- a/tests/testthat/test-write.R +++ b/tests/testthat/test-write.R @@ -57,7 +57,11 @@ test_that("roundtrip preserves dates and datetimes", { }) test_that("fails to create file in non-existent directory", { - expect_error(write_csv(mtcars, file.path(tempdir(), "/x/y")), "open") + expect_error( + expect_warning( + write_csv(mtcars, file.path(tempdir(), "/x/y")), "open" + ) + ) }) test_that("write_excel_csv/csv2 includes a byte order mark", {