diff --git a/tests/testthat/_snaps/xml_attr.md b/tests/testthat/_snaps/xml_attr.md index 87aef962..c9ec016c 100644 --- a/tests/testthat/_snaps/xml_attr.md +++ b/tests/testthat/_snaps/xml_attr.md @@ -1,4 +1,8 @@ # xml_attrs<- modifies all attributes - `test` must be a list of named character vectors. + Code + xml_attrs(docs) <- "test" + Condition + Error in `xml_attrs<-`: + ! `test` must be a list of named character vectors. diff --git a/tests/testthat/_snaps/xml_children.md b/tests/testthat/_snaps/xml_children.md index 2fadd129..7b38d4df 100644 --- a/tests/testthat/_snaps/xml_children.md +++ b/tests/testthat/_snaps/xml_children.md @@ -1,4 +1,8 @@ # xml_child() errors if more than one search is given - `1` and `2` must be of length 1. + Code + xml_child(x, 1:2) + Condition + Error in `xml_child()`: + ! `1` and `2` must be of length 1. diff --git a/tests/testthat/_snaps/xml_find.md b/tests/testthat/_snaps/xml_find.md index 7d1f0ebe..f20dbf50 100644 --- a/tests/testthat/_snaps/xml_find.md +++ b/tests/testthat/_snaps/xml_find.md @@ -1,6 +1,25 @@ # xml_find_num errors with non numeric results - Element at path `//z` must be a number, not a object. + Code + xml_find_num(x, "//z") + Condition + Error in `xml_find_num()`: + ! Element at path `//z` must be a number, not a object. + Code + xml_find_num(x, "//y") + Condition + Error in `xml_find_num()`: + ! Element at path `//y` must be a number, not a list. + Code + xml_find_num(x, "1=1") + Condition + Error in `xml_find_num()`: + ! Element at path `1=1` must be a number, not `TRUE`. + Code + xml_find_num(x, "string(5)") + Condition + Error in `xml_find_num()`: + ! Element at path `string(5)` must be a number, not the string "5". # xml_find_int errors with non integer results @@ -22,9 +41,47 @@ # xml_find_chr errors with non character results - Element at path `//z` must be a single string, not a object. + Code + xml_find_chr(x, "//z") + Condition + Error in `xml_find_chr()`: + ! Element at path `//z` must be a single string, not a object. + Code + xml_find_chr(x, "//y") + Condition + Error in `xml_find_chr()`: + ! Element at path `//y` must be a single string, not a list. + Code + xml_find_chr(x, "1=1") + Condition + Error in `xml_find_chr()`: + ! Element at path `1=1` must be a single string, not `TRUE`. + Code + xml_find_chr(x, "1+1") + Condition + Error in `xml_find_chr()`: + ! Element at path `1+1` must be a single string, not the number 2. # xml_find_lgl errors with non logical results - Element at path `//z` must be `TRUE` or `FALSE`, not a object. + Code + xml_find_lgl(x, "//z") + Condition + Error in `xml_find_lgl()`: + ! Element at path `//z` must be `TRUE` or `FALSE`, not a object. + Code + xml_find_lgl(x, "//y") + Condition + Error in `xml_find_lgl()`: + ! Element at path `//y` must be `TRUE` or `FALSE`, not a list. + Code + xml_find_lgl(x, "string(5)") + Condition + Error in `xml_find_lgl()`: + ! Element at path `string(5)` must be `TRUE` or `FALSE`, not the string "5". + Code + xml_find_lgl(x, "1+1") + Condition + Error in `xml_find_lgl()`: + ! Element at path `1+1` must be `TRUE` or `FALSE`, not the number 2. diff --git a/tests/testthat/_snaps/xml_name.md b/tests/testthat/_snaps/xml_name.md index 38ee479d..4e93fab4 100644 --- a/tests/testthat/_snaps/xml_name.md +++ b/tests/testthat/_snaps/xml_name.md @@ -1,4 +1,8 @@ # error if missing ns spec - Couldn't find prefix for url http://bar.com + Code + xml_name(bars, ns) + Condition + Error in `xml_name()`: + ! Couldn't find prefix for url http://bar.com diff --git a/tests/testthat/_snaps/xml_parse.md b/tests/testthat/_snaps/xml_parse.md index db748e1a..78446722 100644 --- a/tests/testthat/_snaps/xml_parse.md +++ b/tests/testthat/_snaps/xml_parse.md @@ -1,8 +1,21 @@ # read_xml errors with an empty document - `x` must be a single string, not an empty character vector. + Code + read_xml(character()) + Condition + Error in `read_xml()`: + ! `x` must be a single string, not an empty character vector. # read_xml and read_html fail with > 1 input - `x` must be a single string, not a character vector. + Code + read_xml(c("foo", "bar")) + Condition + Error in `read_xml()`: + ! `x` must be a single string, not a character vector. + Code + read_html(c("foo", "bar")) + Condition + Error in `read_xml()`: + ! `x` must be a single string, not a character vector. diff --git a/tests/testthat/_snaps/xml_write.md b/tests/testthat/_snaps/xml_write.md index 252276e0..bb7a135d 100644 --- a/tests/testthat/_snaps/xml_write.md +++ b/tests/testthat/_snaps/xml_write.md @@ -1,12 +1,24 @@ # write_xml errors for incorrect directory and with invalid inputs - `file` must be a single string, not a character vector. + Code + write_xml(x, c("test.xml", "foo")) + Condition + Error in `write_xml()`: + ! `file` must be a single string, not a character vector. # write_xml works with nodeset input and connections - `file` must be a single string, not a character vector. + Code + write_xml(y[1], c(filename, "foo")) + Condition + Error in `write_xml()`: + ! `file` must be a single string, not a character vector. # write_xml works with node input and files - `file` must be a single string, not a character vector. + Code + write_xml(y, c(filename, "foo")) + Condition + Error in `write_xml()`: + ! `file` must be a single string, not a character vector. diff --git a/tests/testthat/test-xml_attr.R b/tests/testthat/test-xml_attr.R index f602cbff..3fc0c7aa 100644 --- a/tests/testthat/test-xml_attr.R +++ b/tests/testthat/test-xml_attr.R @@ -100,7 +100,7 @@ test_that("xml_attrs<- modifies all attributes", { xml_attrs(doc, ns) <- c("b:id" = "b", "id" = "test") expect_equal(xml_attrs(doc, ns), c("b:id" = "b", "id" = "test")) - expect_snapshot_error(xml_attrs(docs) <- "test") + expect_snapshot(error = TRUE, xml_attrs(docs) <- "test") xml_attrs(docs, ns) <- c("b:id" = "b", "id" = "test") expect_equal( diff --git a/tests/testthat/test-xml_children.R b/tests/testthat/test-xml_children.R index e22bc6f9..125965f6 100644 --- a/tests/testthat/test-xml_children.R +++ b/tests/testthat/test-xml_children.R @@ -11,7 +11,7 @@ test_that("xml_child() returns child by name", { }) test_that("xml_child() errors if more than one search is given", { - expect_snapshot_error(xml_child(x, 1:2)) + expect_snapshot(error = TRUE, xml_child(x, 1:2)) }) test_that("xml_child() errors if search is not numeric or character", { diff --git a/tests/testthat/test-xml_find.R b/tests/testthat/test-xml_find.R index 2311d98b..dccd98f4 100644 --- a/tests/testthat/test-xml_find.R +++ b/tests/testthat/test-xml_find.R @@ -62,7 +62,7 @@ test_that("xml_find_all returns nodeset or list of nodesets based on flatten", { # Find num --------------------------------------------------------------------- test_that("xml_find_num errors with non numeric results", { x <- read_xml("") - expect_snapshot_error({ + expect_snapshot(error = TRUE, { xml_find_num(x, "//z") xml_find_num(x, "//y") xml_find_num(x, "1=1") @@ -106,7 +106,7 @@ test_that("xml_find_int returns a integer result", { # Find chr --------------------------------------------------------------------- test_that("xml_find_chr errors with non character results", { x <- read_xml("") - expect_snapshot_error({ + expect_snapshot(error = TRUE, { xml_find_chr(x, "//z") xml_find_chr(x, "//y") xml_find_chr(x, "1=1") @@ -134,7 +134,7 @@ test_that("xml_find_chr returns a character result", { # Find lgl --------------------------------------------------------------------- test_that("xml_find_lgl errors with non logical results", { x <- read_xml("") - expect_snapshot_error({ + expect_snapshot(error = TRUE, { xml_find_lgl(x, "//z") xml_find_lgl(x, "//y") xml_find_lgl(x, "string(5)") diff --git a/tests/testthat/test-xml_name.R b/tests/testthat/test-xml_name.R index 869db269..65d5595e 100644 --- a/tests/testthat/test-xml_name.R +++ b/tests/testthat/test-xml_name.R @@ -29,7 +29,7 @@ test_that("error if missing ns spec", { ns <- xml_ns(x)[1] bars <- xml_children(xml_children(x)) - expect_snapshot_error(xml_name(bars, ns)) + expect_snapshot(error = TRUE, xml_name(bars, ns)) }) test_that("xml_name<- modifies the name", { diff --git a/tests/testthat/test-xml_parse.R b/tests/testthat/test-xml_parse.R index 2ff6e6ce..b18a4bfe 100644 --- a/tests/testthat/test-xml_parse.R +++ b/tests/testthat/test-xml_parse.R @@ -9,7 +9,9 @@ test_that("download_xml fails if curl is not installed", { }) test_that("read_xml errors with an empty document", { - expect_snapshot_error({read_xml(character())}) + expect_snapshot(error = TRUE, { + read_xml(character()) + }) tf <- tempfile() file.create(tf) @@ -105,7 +107,7 @@ test_that("read_html works with non-ASCII encodings", { }) test_that("read_xml and read_html fail with > 1 input", { - expect_snapshot_error({ + expect_snapshot(error = TRUE, { read_xml(c("foo", "bar")) read_html(c("foo", "bar")) }) diff --git a/tests/testthat/test-xml_write.R b/tests/testthat/test-xml_write.R index fd5fdac3..8fd45c83 100644 --- a/tests/testthat/test-xml_write.R +++ b/tests/testthat/test-xml_write.R @@ -3,8 +3,9 @@ test_that("write_xml errors for incorrect directory and with invalid inputs", { filename <- "does_not_exist/test.xml" expect_error(write_xml(x, filename), "'does_not_exist' does not exist in current working directory") - - expect_snapshot_error(write_xml(x, c("test.xml", "foo"))) + expect_snapshot(error = TRUE, { + write_xml(x, c("test.xml", "foo")) + }) }) test_that("write_xml works with relative file paths", { @@ -74,7 +75,9 @@ test_that("write_xml works with nodeset input and connections", { "Can only save length 1 node sets" ) - expect_snapshot_error(write_xml(y[1], c(filename, "foo"))) + expect_snapshot(error = TRUE, { + write_xml(y[1], c(filename, "foo")) + }) write_xml(y[1], filename, options = "no_declaration") file <- gzfile(filename, "rb") @@ -90,7 +93,7 @@ test_that("write_xml works with node input and files", { y <- xml_find_first(x, "//y") filename <- "../test.xml" - expect_snapshot_error(write_xml(y, c(filename, "foo"))) + expect_snapshot(error = TRUE, write_xml(y, c(filename, "foo"))) write_xml(y, filename, options = "no_declaration") on.exit(unlink(filename))