1## ---- include = FALSE---------------------------------------------------------
2knitr::opts_chunk$set(
3  collapse = TRUE,
4  comment = "#>"
5)
6
7## ---- message = FALSE---------------------------------------------------------
8library(testthat)
9local_edition(3)
10
11## -----------------------------------------------------------------------------
12test_that("I can use the 3rd edition", {
13  local_edition(3)
14  expect_true(TRUE)
15})
16
17## -----------------------------------------------------------------------------
18test_that("I want to use the 2nd edition", {
19  local_edition(2)
20  expect_true(TRUE)
21})
22
23## -----------------------------------------------------------------------------
24f <- function() {
25  warning("First warning")
26  warning("Second warning")
27  warning("Third warning")
28}
29
30local_edition(2)
31expect_warning(f(), "First")
32
33## -----------------------------------------------------------------------------
34local_edition(3)
35expect_warning(f(), "First")
36
37## -----------------------------------------------------------------------------
38f() %>%
39  expect_warning("First") %>%
40  expect_warning("Second") %>%
41  expect_warning("Third")
42
43f() %>%
44  expect_warning("First") %>%
45  suppressWarnings()
46
47## -----------------------------------------------------------------------------
48test_that("f() produces expected outputs/messages/warnings", {
49  expect_snapshot(f())
50})
51
52## ---- error = TRUE------------------------------------------------------------
53f1 <- factor(letters[1:3])
54f2 <- ordered(letters[1:3], levels = letters[1:4])
55
56local_edition(2)
57expect_equal(f1, f2)
58
59local_edition(3)
60expect_equal(f1, f2)
61
62## ---- error = TRUE------------------------------------------------------------
63dt1 <- dt2 <- ISOdatetime(2020, 1, 2, 3, 4, 0)
64attr(dt1, "tzone") <- ""
65attr(dt2, "tzone") <- Sys.timezone()
66
67local_edition(2)
68expect_equal(dt1, dt2)
69
70local_edition(3)
71expect_equal(dt1, dt2)
72
73