From c709c97e878d8437ba581d59f83c719156f63a0f Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 22 Nov 2019 08:04:42 -0600 Subject: [PATCH] Make object format less fragile Matrices inherit from arrays in R-devel. --- cran-comments.md | 4 +++ tests/testthat/test-object-format.R | 37 +++++---------------------- tests/testthat/test-object-format.txt | 15 +++++++++++ 3 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 tests/testthat/test-object-format.txt diff --git a/cran-comments.md b/cran-comments.md index 682910d70..edf59c728 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,7 @@ +This is a resubmission that fixes a failure on R-devel. + +--- + ## Test environments * local: darwin15.6.0-3.6.0 diff --git a/tests/testthat/test-object-format.R b/tests/testthat/test-object-format.R index 1bc45fec5..f8b5cf152 100644 --- a/tests/testthat/test-object-format.R +++ b/tests/testthat/test-object-format.R @@ -1,32 +1,9 @@ test_that("format has nice defaults for bare vectors", { - expect_equal( - call_to_format(x <- list(a = 1, b = 2)), - "An object of class \\code{list} of length 2." - ) -}) - -test_that("format defaults for S3 objects", { - expect_equal( - call_to_format(x <- ordered(letters[1:5])), - "An object of class \\code{ordered} (inherits from \\code{factor}) of length 5." - ) -}) - -test_that("format has nice defaults for matrices and arrays", { - expect_equal( - call_to_format(x <- diag(10)), - "An object of class \\code{matrix} with 10 rows and 10 columns." - ) - - expect_equal( - call_to_format(x <- array(1:27, dim = c(3, 3, 3))), - "An object of class \\code{array} of dimension 3 x 3 x 3." - ) -}) - -test_that("format has nice defaults for data frames", { - expect_equal( - call_to_format(x <- data.frame(a = 1, b = 2)), - "An object of class \\code{data.frame} with 1 rows and 2 columns." - ) + verify_output(test_path("test-object-format.txt"), { + call_to_format(x <- list(a = 1, b = 2)) + call_to_format(x <- ordered(letters[1:5])) + call_to_format(x <- diag(10)) + call_to_format(x <- array(1:27, dim = c(3, 3, 3))) + call_to_format(x <- data.frame(a = 1, b = 2)) + }) }) diff --git a/tests/testthat/test-object-format.txt b/tests/testthat/test-object-format.txt new file mode 100644 index 000000000..d2b3ae01a --- /dev/null +++ b/tests/testthat/test-object-format.txt @@ -0,0 +1,15 @@ +> call_to_format(x <- list(a = 1, b = 2)) +[1] "An object of class \\code{list} of length 2." + +> call_to_format(x <- ordered(letters[1:5])) +[1] "An object of class \\code{ordered} (inherits from \\code{factor}) of length 5." + +> call_to_format(x <- diag(10)) +[1] "An object of class \\code{matrix} with 10 rows and 10 columns." + +> call_to_format(x <- array(1:27, dim = c(3, 3, 3))) +[1] "An object of class \\code{array} of dimension 3 x 3 x 3." + +> call_to_format(x <- data.frame(a = 1, b = 2)) +[1] "An object of class \\code{data.frame} with 1 rows and 2 columns." +