diff --git a/DESCRIPTION b/DESCRIPTION index ad67af68a..7a797eef7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -630,7 +630,7 @@ Suggests: survey, survival (>= 3.6-4), systemfit, - testthat (>= 2.1.0), + testthat (>= 3.0.0), tseries, vars, zoo @@ -673,6 +673,8 @@ Collate: 'glmnet-glmnet-tidiers.R' 'gmm-tidiers.R' 'hmisc-tidiers.R' + 'import-standalone-obj-type.R' + 'import-standalone-types-check.R' 'joinerml-tidiers.R' 'kendall-tidiers.R' 'ks-tidiers.R' @@ -751,3 +753,4 @@ Collate: 'vars-tidiers.R' 'zoo-tidiers.R' 'zzz.R' +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 000000000..9c8fd4f9e --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(broom) + +test_check("broom") diff --git a/tests/testthat/_snaps/drc.md b/tests/testthat/_snaps/drc.md new file mode 100644 index 000000000..298f97b88 --- /dev/null +++ b/tests/testthat/_snaps/drc.md @@ -0,0 +1,16 @@ +# augment.drc + + Code + augment(mod) + Condition + Error: + ! Must specify either `data` or `newdata` argument. + +--- + + Code + augment(mod2) + Condition + Error: + ! Must specify either `data` or `newdata` argument. + diff --git a/tests/testthat/_snaps/ergm.md b/tests/testthat/_snaps/ergm.md new file mode 100644 index 000000000..3a555b1ff --- /dev/null +++ b/tests/testthat/_snaps/ergm.md @@ -0,0 +1,23 @@ +# tidy.ergm + + Code + tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) + Condition + Warning in `tidy.ergm()`: + Exponentiating but model didn't use log or logit link. + +--- + + Code + td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE) + Condition + Warning in `tidy.ergm()`: + Exponentiating but model didn't use log or logit link. + +# glance.ergm + + Code + gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE) + Message + Though `glance` was supplied `mcmc = TRUE`, the model was not fittedusing MCMC, so the corresponding columns will be omitted. + diff --git a/tests/testthat/_snaps/fixest.md b/tests/testthat/_snaps/fixest.md new file mode 100644 index 000000000..5052b4272 --- /dev/null +++ b/tests/testthat/_snaps/fixest.md @@ -0,0 +1,27 @@ +# all other fixest estimators run + + Code + augment(res_fenegbin, df) + Condition + Error in `augment.fixest()`: + ! augment is only supported for fixest models estimated with feols, feglm, or femlm + (supplied model used fenegbin) + +--- + + Code + augment(res_feNmlm, df) + Condition + Error in `augment.fixest()`: + ! augment is only supported for fixest models estimated with feols, feglm, or femlm + (supplied model used feNmlm) + +--- + + Code + augment(res_fepois, df) + Condition + Error in `augment.fixest()`: + ! augment is only supported for fixest models estimated with feols, feglm, or femlm + (supplied model used fepois) + diff --git a/tests/testthat/_snaps/geepack.md b/tests/testthat/_snaps/geepack.md new file mode 100644 index 000000000..aecec1329 --- /dev/null +++ b/tests/testthat/_snaps/geepack.md @@ -0,0 +1,8 @@ +# tidy.geeglm + + Code + td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE) + Condition + Warning in `tidy.geeglm()`: + Exponentiating coefficients, but model did not use a log or logit link function + diff --git a/tests/testthat/_snaps/joineRML.md b/tests/testthat/_snaps/joineRML.md new file mode 100644 index 000000000..e58ff78d1 --- /dev/null +++ b/tests/testthat/_snaps/joineRML.md @@ -0,0 +1,16 @@ +# tidy.mjoint + + Code + tidy(mjoint_fit, boot_se = "cat") + Condition + Error: + ! `boot_se` argument must be a `bootSE` object. + +# augment.mjoint + + Code + augment(mjoint_fit, data = NULL) + Condition + Error: + ! `data` argument is NULL. Try specifying `data` manually. + diff --git a/tests/testthat/_snaps/lfe.md b/tests/testthat/_snaps/lfe.md new file mode 100644 index 000000000..3b0a7acbf --- /dev/null +++ b/tests/testthat/_snaps/lfe.md @@ -0,0 +1,25 @@ +# tidy.felm + + Code + .res <- tidy(fit, robust = TRUE) + Condition + Warning in `tidy.felm()`: + + The "robust" argument has been deprecated in tidy.felm and will be ignored. Please use the "se.type" argument instead. + +# glance.felm + + Code + glance(fit_multi) + Condition + Error: + ! Glance does not support linear models with multiple responses. + +# augment.felm + + Code + augment(fit_multi) + Condition + Error: + ! Augment does not support linear models with multiple responses. + diff --git a/tests/testthat/_snaps/list-xyz.md b/tests/testthat/_snaps/list-xyz.md new file mode 100644 index 000000000..a431f6a17 --- /dev/null +++ b/tests/testthat/_snaps/list-xyz.md @@ -0,0 +1,24 @@ +# tidy_xyz + + Code + tidy(b) + Condition + Error: + ! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. + +--- + + Code + tidy(c) + Condition + Error: + ! To tidy an xyz list, the length of element `x` must equal the number the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. + +--- + + Code + tidy(d) + Condition + Error: + ! To tidy an xyz list, `z` must be a matrix. + diff --git a/tests/testthat/_snaps/list.md b/tests/testthat/_snaps/list.md new file mode 100644 index 000000000..6e515f0ad --- /dev/null +++ b/tests/testthat/_snaps/list.md @@ -0,0 +1,16 @@ +# not all lists can be tidied + + Code + tidy(nl) + Condition + Error: + ! No tidy method recognized for this list. + +--- + + Code + glance(nl) + Condition + Error: + ! No glance method recognized for this list. + diff --git a/tests/testthat/_snaps/mclust.md b/tests/testthat/_snaps/mclust.md new file mode 100644 index 000000000..a1f0cd876 --- /dev/null +++ b/tests/testthat/_snaps/mclust.md @@ -0,0 +1,8 @@ +# augment.Mclust + + Code + augment(fit, 1:10) + Condition + Error: + ! `data` must be a data frame or matrix. + diff --git a/tests/testthat/_snaps/null-and-default.md b/tests/testthat/_snaps/null-and-default.md new file mode 100644 index 000000000..db98dd9a7 --- /dev/null +++ b/tests/testthat/_snaps/null-and-default.md @@ -0,0 +1,120 @@ +# tidy.default + + Code + td <- tidy(raw(1)) + Condition + Error: + ! No tidy method for objects of class raw + +--- + + Code + glance(x) + Condition + Error: + ! No glance method for objects of class foo + +--- + + Code + glance(x) + Condition + Error: + ! No glance method for objects of class foo + +# glance.default + + Code + glance(TRUE) + Condition + Error: + ! No glance method for objects of class logical + +--- + + Code + glance(1) + Condition + Error: + ! No glance method for objects of class numeric + +--- + + Code + glance(1L) + Condition + Error: + ! No glance method for objects of class integer + +--- + + Code + glance("a") + Condition + Error: + ! No glance method for objects of class character + +--- + + Code + glance(x) + Condition + Error: + ! No glance method for objects of class foo + +--- + + Code + glance(x) + Condition + Error: + ! No glance method for objects of class foo + +# augment.default + + Code + augment(TRUE) + Condition + Error: + ! No augment method for objects of class logical + +--- + + Code + augment(1) + Condition + Error: + ! No augment method for objects of class numeric + +--- + + Code + augment(1L) + Condition + Error: + ! No augment method for objects of class integer + +--- + + Code + augment("a") + Condition + Error: + ! No augment method for objects of class character + +--- + + Code + augment(x) + Condition + Error: + ! No augment method for objects of class foo + +--- + + Code + augment(x) + Condition + Error: + ! No augment method for objects of class foo + diff --git a/tests/testthat/_snaps/quantreg-rqs.md b/tests/testthat/_snaps/quantreg-rqs.md new file mode 100644 index 000000000..2d49adce8 --- /dev/null +++ b/tests/testthat/_snaps/quantreg-rqs.md @@ -0,0 +1,8 @@ +# glance.rqs + + Code + glance(fit) + Condition + Error: + ! `glance` cannot handle objects of class 'rqs', i.e. models with more than one tau value. Please use a purrr `map`-based workflow with 'rq' models instead. + diff --git a/tests/testthat/_snaps/speedglm-speedglm.md b/tests/testthat/_snaps/speedglm-speedglm.md new file mode 100644 index 000000000..692cea16b --- /dev/null +++ b/tests/testthat/_snaps/speedglm-speedglm.md @@ -0,0 +1,8 @@ +# augment.speedglm errors + + Code + augment(fit) + Condition + Error: + ! No augment method for objects of class speedglm + diff --git a/tests/testthat/_snaps/speedglm-speedlm.md b/tests/testthat/_snaps/speedglm-speedlm.md new file mode 100644 index 000000000..41d159317 --- /dev/null +++ b/tests/testthat/_snaps/speedglm-speedlm.md @@ -0,0 +1,8 @@ +# augment.speedlm + + Code + augment(fit3) + Condition + Error: + ! Must specify `data` argument or refit speedglm with `fitted = TRUE`. + diff --git a/tests/testthat/_snaps/stats-anova.md b/tests/testthat/_snaps/stats-anova.md new file mode 100644 index 000000000..5fe756eda --- /dev/null +++ b/tests/testthat/_snaps/stats-anova.md @@ -0,0 +1,8 @@ +# tidy.anova + + Code + .res <- tidy(loess_anova) + Condition + Warning in `tidy.anova()`: + The following column names in ANOVA output were not recognized or transformed: ENP + diff --git a/tests/testthat/_snaps/stats-factanal.md b/tests/testthat/_snaps/stats-factanal.md new file mode 100644 index 000000000..df76c7b7a --- /dev/null +++ b/tests/testthat/_snaps/stats-factanal.md @@ -0,0 +1,8 @@ +# augment.factanal works + + Code + augment(fit_none) + Condition + Error: + ! Cannot augment factanal objects fit with `scores = 'none'`. + diff --git a/tests/testthat/_snaps/stats-htest.md b/tests/testthat/_snaps/stats-htest.md new file mode 100644 index 000000000..2c4289d88 --- /dev/null +++ b/tests/testthat/_snaps/stats-htest.md @@ -0,0 +1,31 @@ +# tidy.htest/oneway.test + + Code + td <- tidy(ot) + Message + Multiple parameters; naming those columns num.df, den.df + +# augment.htest (chi squared test) + + Code + augment(tt) + Condition + Error: + ! Augment is only defined for chi squared hypothesis tests. + +--- + + Code + augment(wt) + Condition + Error: + ! Augment is only defined for chi squared hypothesis tests. + +--- + + Code + augment(ct) + Condition + Error: + ! Augment is only defined for chi squared hypothesis tests. + diff --git a/tests/testthat/_snaps/stats-lm.md b/tests/testthat/_snaps/stats-lm.md new file mode 100644 index 000000000..f486bb7d4 --- /dev/null +++ b/tests/testthat/_snaps/stats-lm.md @@ -0,0 +1,32 @@ +# tidy.lm works + + Code + td_rd <- tidy(fit_rd, conf.int = TRUE) + Condition + Warning in `qt()`: + NaNs produced + +# augment.lm + + Code + augment(fit, newdata = mtcars, interval = "confidence", level = 0.95) + Condition + Warning: + The `level` argument is not supported in the `augment()` method for `lm` objects and will be ignored. + Output + # A tibble: 32 x 16 + .rownames mpg cyl disp hp drat wt qsec vs am gear carb + + 1 Mazda RX4 21 6 160 110 3.9 2.62 16.5 0 1 4 4 + 2 Mazda RX4 ~ 21 6 160 110 3.9 2.88 17.0 0 1 4 4 + 3 Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 + 4 Hornet 4 D~ 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 + 5 Hornet Spo~ 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2 + 6 Valiant 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1 + 7 Duster 360 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4 + 8 Merc 240D 24.4 4 147. 62 3.69 3.19 20 1 0 4 2 + 9 Merc 230 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 + 10 Merc 280 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 + # i 22 more rows + # i 4 more variables: .fitted , .lower , .upper , .resid + diff --git a/tests/testthat/_snaps/stats-prcomp.md b/tests/testthat/_snaps/stats-prcomp.md new file mode 100644 index 000000000..9cdf08014 --- /dev/null +++ b/tests/testthat/_snaps/stats-prcomp.md @@ -0,0 +1,8 @@ +# tidy.prcomp + + Code + tidy(pc, matrix = c("d", "u")) + Condition + Error: + ! Must select a single matrix to tidy. + diff --git a/tests/testthat/_snaps/survival-survfit.md b/tests/testthat/_snaps/survival-survfit.md new file mode 100644 index 000000000..c9a64b004 --- /dev/null +++ b/tests/testthat/_snaps/survival-survfit.md @@ -0,0 +1,16 @@ +# glance.survfit + + Code + glance(sfit) + Condition + Error in `glance.survfit()`: + ! Cannot construct a glance of a multi-strata survfit object. + +--- + + Code + glance(fit2) + Condition + Error in `glance.survfit()`: + ! Cannot construct a glance of a multi-state survfit object. + diff --git a/tests/testthat/_snaps/utilities.md b/tests/testthat/_snaps/utilities.md new file mode 100644 index 000000000..ec42cc88b --- /dev/null +++ b/tests/testthat/_snaps/utilities.md @@ -0,0 +1,66 @@ +# ellipsis checking works + + Code + check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE) + Condition + Warning: + The `exponentiate` argument is not supported in the `tidy()` method for `boop` objects and will be ignored. + +--- + + Code + check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE, quick = FALSE) + Condition + Warning: + The `exponentiate` argument is not supported in the `tidy()` method for `boop` objects and will be ignored. + +# ellipsis checking works (whole game, tidy) + + Code + tidy(mod, exponentiate = TRUE) + Condition + Warning: + The `exponentiate` argument is not supported in the `tidy()` method for `nls` objects and will be ignored. + Output + # A tibble: 2 x 5 + term estimate std.error statistic p.value + + 1 k 49.7 3.79 13.1 5.96e-14 + 2 e 0.746 0.0199 37.5 8.86e-27 + +# ellipsis checking works (whole game, augment) + + Code + .res <- augment(mod, data = mtcars, newdata = mtcars) + Condition + Warning: + The `newdata` argument is not supported in the `augment()` method for `kmeans` objects and will be ignored. + +# as_glance_tibble + + Code + as_glance_tibble(x = 1, y = 1, na_types = "rrr") + Condition + Error in `as_glance_tibble()`: + ! The number of columns provided does not match the number of column types provided. + +# appropriate warning on (g)lm-subclassed models + + Code + warn_on_subclass(x, "tidy") + Condition + Warning: + The `tidy()` method for objects of class `boop` is not maintained by the broom team, and is only supported through the `glm` tidier method. Please be cautious in interpreting and reporting broom output. + + This warning is displayed once per session. + +--- + + Code + warn_on_subclass(x, "tidy") + Condition + Warning: + The `tidy()` method for objects of class `bop` is not maintained by the broom team, and is only supported through the `glm` tidier method. Please be cautious in interpreting and reporting broom output. + + This warning is displayed once per session. + diff --git a/tests/testthat/_snaps/vars.md b/tests/testthat/_snaps/vars.md new file mode 100644 index 000000000..7917bb49e --- /dev/null +++ b/tests/testthat/_snaps/vars.md @@ -0,0 +1,8 @@ +# tidy.vars + + Code + .res <- tidy(fit, conf.int = TRUE) + Condition + Warning in `tidy.varest()`: + Confidence intervals are not supported for `varest` objects. The `conf.level` argument will be ignored. + diff --git a/tests/testthat/test-aer.R b/tests/testthat/test-aer.R index 13783e703..a813ee383 100644 --- a/tests/testthat/test-aer.R +++ b/tests/testthat/test-aer.R @@ -1,5 +1,3 @@ -context("aer") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-aov.R b/tests/testthat/test-aov.R index c81cb3853..70e22499f 100644 --- a/tests/testthat/test-aov.R +++ b/tests/testthat/test-aov.R @@ -1,5 +1,3 @@ -context("aov") - library(broom) d <- data.frame( diff --git a/tests/testthat/test-auc.R b/tests/testthat/test-auc.R index 8eadb58d0..aebe15e1b 100644 --- a/tests/testthat/test-auc.R +++ b/tests/testthat/test-auc.R @@ -1,5 +1,3 @@ -context("auc") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-bbmle.R b/tests/testthat/test-bbmle.R index 409b9fd92..9fd34217b 100644 --- a/tests/testthat/test-bbmle.R +++ b/tests/testthat/test-bbmle.R @@ -1,5 +1,3 @@ -context("bbmle") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-betareg.R b/tests/testthat/test-betareg.R index 8f6017363..fd593e783 100644 --- a/tests/testthat/test-betareg.R +++ b/tests/testthat/test-betareg.R @@ -1,5 +1,3 @@ -context("betareg") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-biglm.R b/tests/testthat/test-biglm.R index f3b25f089..6088a5d11 100644 --- a/tests/testthat/test-biglm.R +++ b/tests/testthat/test-biglm.R @@ -1,5 +1,3 @@ -context("biglm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-bingroup.R b/tests/testthat/test-bingroup.R index 681587e80..4abdb6107 100644 --- a/tests/testthat/test-bingroup.R +++ b/tests/testthat/test-bingroup.R @@ -1,5 +1,3 @@ -context("bingroup") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-boot.R b/tests/testthat/test-boot.R index b0ffec1b9..5847ba5e2 100644 --- a/tests/testthat/test-boot.R +++ b/tests/testthat/test-boot.R @@ -1,5 +1,3 @@ -context("boot") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-btergm.R b/tests/testthat/test-btergm.R index 78765b8f6..f278deaac 100644 --- a/tests/testthat/test-btergm.R +++ b/tests/testthat/test-btergm.R @@ -1,5 +1,3 @@ -context("btergm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-car.R b/tests/testthat/test-car.R index e335fadc5..e60207cbd 100644 --- a/tests/testthat/test-car.R +++ b/tests/testthat/test-car.R @@ -1,5 +1,3 @@ -context("car") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-caret.R b/tests/testthat/test-caret.R index dd47979b0..8aea0bec5 100644 --- a/tests/testthat/test-caret.R +++ b/tests/testthat/test-caret.R @@ -1,5 +1,3 @@ -context("caret") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-cluster.R b/tests/testthat/test-cluster.R index 397526750..641f51259 100644 --- a/tests/testthat/test-cluster.R +++ b/tests/testthat/test-cluster.R @@ -1,5 +1,3 @@ -context("cluster") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-cmprsk.R b/tests/testthat/test-cmprsk.R index 0821d9751..5aaafd5f6 100644 --- a/tests/testthat/test-cmprsk.R +++ b/tests/testthat/test-cmprsk.R @@ -1,5 +1,3 @@ -context("cmprsk") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-drc.R b/tests/testthat/test-drc.R index 61e1ea050..9eea9a445 100644 --- a/tests/testthat/test-drc.R +++ b/tests/testthat/test-drc.R @@ -1,5 +1,3 @@ -context("drc") - skip_on_cran() skip_if_not_installed("modeltests") @@ -42,11 +40,8 @@ test_that("glance.drc", { }) test_that("augment.drc", { - expect_error( - augment(mod), - regexp = "Must specify either `data` or `newdata` argument." - ) - + expect_snapshot(error = TRUE, augment(mod)) + check_augment_function( augment.drc, mod, @@ -54,11 +49,8 @@ test_that("augment.drc", { newdata = selenium ) - expect_error( - augment(mod2), - regexp = "Must specify either `data` or `newdata` argument." - ) - + expect_snapshot(error = TRUE, augment(mod2)) + check_augment_function( augment.drc, mod2, diff --git a/tests/testthat/test-emmeans.R b/tests/testthat/test-emmeans.R index 8108790fd..3b7d71aab 100644 --- a/tests/testthat/test-emmeans.R +++ b/tests/testthat/test-emmeans.R @@ -1,5 +1,3 @@ -context("emmeans") - skip_on_cran() # Matrix ABI version may differ (#1204) diff --git a/tests/testthat/test-epiR.R b/tests/testthat/test-epiR.R index 357652c11..843a90965 100644 --- a/tests/testthat/test-epiR.R +++ b/tests/testthat/test-epiR.R @@ -1,5 +1,3 @@ -context("epiR") - skip_on_cran() skip_if_not_installed("epiR") diff --git a/tests/testthat/test-ergm.R b/tests/testthat/test-ergm.R index 3b9c891af..92997b587 100644 --- a/tests/testthat/test-ergm.R +++ b/tests/testthat/test-ergm.R @@ -1,5 +1,3 @@ -context("ergm") - skip_on_cran() skip_if_not_installed("modeltests") @@ -26,8 +24,8 @@ test_that("ergm tidier arguments", { }) test_that("tidy.ergm", { - expect_warning({ - tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) + expect_snapshot({ + tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) }) check_tidy_output(tde) @@ -40,8 +38,8 @@ test_that("tidy.ergm", { # check_dims(tde, 2, 7) # tidy.ergm warns when exponentiating w/o link - expect_warning(td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE)) - + expect_snapshot(td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE)) + check_tidy_output(td2) # see comment above: @@ -51,10 +49,8 @@ test_that("tidy.ergm", { test_that("glance.ergm", { gl <- glance(gest, deviance = TRUE) gl2 <- glance(gest3, deviance = TRUE, mcmc = TRUE) - expect_message( - gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE) - ) - + expect_snapshot(gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE)) + check_glance_outputs(gl) check_dims(gl, expected_cols = 9) check_dims(gl2, expected_cols = 12) diff --git a/tests/testthat/test-fixest.R b/tests/testthat/test-fixest.R index bdb052958..7c5da3602 100644 --- a/tests/testthat/test-fixest.R +++ b/tests/testthat/test-fixest.R @@ -1,5 +1,3 @@ -context("fixest") - skip_on_cran() skip_if_not_installed("modeltests") @@ -130,10 +128,9 @@ test_that("all other fixest estimators run", { strict = FALSE ) - augment_error <- "augment is only supported for fixest models estimated with feols, feglm, or femlm" - expect_error(augment(res_fenegbin, df), augment_error) - expect_error(augment(res_feNmlm, df), augment_error) - expect_error(augment(res_fepois, df), augment_error) + expect_snapshot(error = TRUE, augment(res_fenegbin, df)) + expect_snapshot(error = TRUE, augment(res_feNmlm, df)) + expect_snapshot(error = TRUE, augment(res_fepois, df)) }) diff --git a/tests/testthat/test-gam.R b/tests/testthat/test-gam.R index 5b3af73c4..1ed8b35e8 100644 --- a/tests/testthat/test-gam.R +++ b/tests/testthat/test-gam.R @@ -1,5 +1,3 @@ -context("gam") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-geepack.R b/tests/testthat/test-geepack.R index 94d68a434..f12002785 100644 --- a/tests/testthat/test-geepack.R +++ b/tests/testthat/test-geepack.R @@ -1,5 +1,3 @@ -context("geepack") - skip_on_cran() skip_if_not_installed("modeltests") @@ -22,14 +20,10 @@ test_that("tidy.geeglm", { td <- tidy(fit, conf.int = TRUE) - expect_warning( - td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE), - regexp = paste( - "Exponentiating coefficients, but model did not use a log", - "or logit link function" - ) - ) - + expect_snapshot({ + td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE) + }) + check_tidy_output(td) check_tidy_output(td2) }) diff --git a/tests/testthat/test-glmnet.R b/tests/testthat/test-glmnet.R index 3272fc15b..5fcc7d1de 100644 --- a/tests/testthat/test-glmnet.R +++ b/tests/testthat/test-glmnet.R @@ -1,5 +1,3 @@ -context("glmnet") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-glmnetUtils.R b/tests/testthat/test-glmnetUtils.R index bab2f9086..96578983c 100644 --- a/tests/testthat/test-glmnetUtils.R +++ b/tests/testthat/test-glmnetUtils.R @@ -1,5 +1,3 @@ -context("glmnetUtils") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-gmm.R b/tests/testthat/test-gmm.R index bd86aa5d6..78d4423fa 100644 --- a/tests/testthat/test-gmm.R +++ b/tests/testthat/test-gmm.R @@ -1,5 +1,3 @@ -context("gmm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-hmisc.R b/tests/testthat/test-hmisc.R index 193519da9..80cb5d60b 100644 --- a/tests/testthat/test-hmisc.R +++ b/tests/testthat/test-hmisc.R @@ -1,5 +1,3 @@ -context("hmisc") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-joineRML.R b/tests/testthat/test-joineRML.R index aa2f70757..8db60e242 100644 --- a/tests/testthat/test-joineRML.R +++ b/tests/testthat/test-joineRML.R @@ -1,5 +1,3 @@ -context("joinerml") - skip_on_cran() # Matrix ABI version may differ (#1204) @@ -71,10 +69,7 @@ test_that("tidy.mjoint", { check_tidy_output(td2sbs) check_tidy_output(td2lbs) - expect_error( - tidy(mjoint_fit, boot_se = "cat"), - regexp = "`boot_se` argument must be a `bootSE` object." - ) + expect_snapshot(error = TRUE, tidy(mjoint_fit, boot_se = "cat")) }) @@ -91,11 +86,8 @@ test_that("augment.mjoint", { au <- augment(mjoint_fit) au2 <- augment(mjoint_fit2) - expect_error( - augment(mjoint_fit, data = NULL), - regexp = "`data` argument is NULL. Try specifying `data` manually." - ) - + expect_snapshot(error = TRUE, augment(mjoint_fit, data = NULL)) + check_tibble(au, method = "augment", strict = FALSE) check_tibble(au, method = "augment", strict = FALSE) }) diff --git a/tests/testthat/test-kendall.R b/tests/testthat/test-kendall.R index 98a5d5e43..12822df67 100644 --- a/tests/testthat/test-kendall.R +++ b/tests/testthat/test-kendall.R @@ -1,5 +1,3 @@ -context("kendall") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-ks.R b/tests/testthat/test-ks.R index 17b72cebb..2a1e47c9c 100644 --- a/tests/testthat/test-ks.R +++ b/tests/testthat/test-ks.R @@ -1,5 +1,3 @@ -context("ks") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-lavaan.R b/tests/testthat/test-lavaan.R index 41fd5e92b..712134880 100644 --- a/tests/testthat/test-lavaan.R +++ b/tests/testthat/test-lavaan.R @@ -1,5 +1,3 @@ -context("lavaan") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-leaps.R b/tests/testthat/test-leaps.R index 98ea18c06..cd3d76bdd 100644 --- a/tests/testthat/test-leaps.R +++ b/tests/testthat/test-leaps.R @@ -1,5 +1,3 @@ -context("lmtest") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-lfe.R b/tests/testthat/test-lfe.R index 303e1d29c..96b5aa980 100644 --- a/tests/testthat/test-lfe.R +++ b/tests/testthat/test-lfe.R @@ -1,5 +1,3 @@ -context("lfe") - skip_on_cran() skip_if_not_installed("modeltests") @@ -99,10 +97,7 @@ test_that("tidy.felm", { ) # check for deprecation warning from 0.7.0.9001 - expect_warning( - tidy(fit, robust = TRUE), - '"robust" argument has been deprecated' - ) + expect_snapshot(.res <- tidy(fit, robust = TRUE)) }) test_that("glance.felm", { @@ -112,7 +107,7 @@ test_that("glance.felm", { check_glance_outputs(gl, gl2) check_dims(gl, expected_cols = 8) - expect_error(glance(fit_multi), "Glance does not support linear models with multiple responses.") + expect_snapshot(error = TRUE, glance(fit_multi)) }) test_that("augment.felm", { @@ -140,11 +135,8 @@ test_that("augment.felm", { ) ) - expect_error( - augment(fit_multi), - "Augment does not support linear models with multiple responses." - ) - + expect_snapshot(error = TRUE, augment(fit_multi)) + # Ensure that the .resid and .fitted columns are basic columns, not matrix aug <- augment(fit) expect_false(inherits(aug$.resid, "matrix")) diff --git a/tests/testthat/test-list-irlba.R b/tests/testthat/test-list-irlba.R index 5f74e1673..570a484ce 100644 --- a/tests/testthat/test-list-irlba.R +++ b/tests/testthat/test-list-irlba.R @@ -1,5 +1,3 @@ -context("list-irlba") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-list-optim.R b/tests/testthat/test-list-optim.R index c380a937f..3a5ae92dc 100644 --- a/tests/testthat/test-list-optim.R +++ b/tests/testthat/test-list-optim.R @@ -1,5 +1,3 @@ -context("list-optim") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-list-svd.R b/tests/testthat/test-list-svd.R index a517f8a07..bca8065f4 100644 --- a/tests/testthat/test-list-svd.R +++ b/tests/testthat/test-list-svd.R @@ -1,5 +1,3 @@ -context("list-svd") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-list-xyz.R b/tests/testthat/test-list-xyz.R index 9e0a73413..7e34c305f 100644 --- a/tests/testthat/test-list-xyz.R +++ b/tests/testthat/test-list-xyz.R @@ -1,5 +1,3 @@ -context("list-xyz") - skip_on_cran() skip_if_not_installed("modeltests") @@ -39,23 +37,7 @@ test_that("tidy_xyz", { expect_true(is.numeric(td$y)) expect_true(is.numeric(td$z)) - expect_error( - tidy(b), - regexp = paste( - "To tidy an xyz list, the length of element `x` must equal the number", - "the number of rows of element `z`, and the length of element `y` must", - "equal the number of columns of element `z`." - ) - ) - - expect_error( - tidy(c), - regexp = paste( - "To tidy an xyz list, the length of element `x` must equal the number", - "the number of rows of element `z`, and the length of element `y` must", - "equal the number of columns of element `z`." - ) - ) - - expect_error(tidy(d), "To tidy an xyz list, `z` must be a matrix.") + expect_snapshot(error = TRUE, tidy(b)) + expect_snapshot(error = TRUE, tidy(c)) + expect_snapshot(error = TRUE, tidy(d)) }) diff --git a/tests/testthat/test-list.R b/tests/testthat/test-list.R index fa2e6e23d..35bbe7892 100644 --- a/tests/testthat/test-list.R +++ b/tests/testthat/test-list.R @@ -1,5 +1,3 @@ -context("list") - skip_on_cran() skip_if_not_installed("modeltests") @@ -8,6 +6,6 @@ library(modeltests) test_that("not all lists can be tidied", { nl <- list(a = NULL) - expect_error(tidy(nl), "No tidy method recognized for this list.") - expect_error(glance(nl), "No glance method recognized for this list.") + expect_snapshot(error = TRUE, tidy(nl)) + expect_snapshot(error = TRUE, glance(nl)) }) diff --git a/tests/testthat/test-lmbeta-lm-beta.R b/tests/testthat/test-lmbeta-lm-beta.R index 61d46eef8..d09c050c9 100644 --- a/tests/testthat/test-lmbeta-lm-beta.R +++ b/tests/testthat/test-lmbeta-lm-beta.R @@ -1,5 +1,3 @@ -context("lmbeta-lm-beta") - skip_on_cran() skip_if_not_installed("modeltests") @@ -28,9 +26,10 @@ test_that("tidy.lm.beta works", { td2 <- tidy(fit2) # conf.int = TRUE works for rank deficient fits - # should get a "NaNs produced" warning + # should get a "NaNs produced" warning. + # not snapshotting as we don't own the error message. expect_warning(td_rd <- tidy(fit_rd, conf.int = TRUE)) - + check_tidy_output(td) check_tidy_output(td2) @@ -44,5 +43,5 @@ test_that("tidy.lm.beta works", { # shouldn't error. regression test for issues 166, 241 # rows for confidence intervals of undefined terms should be dropped - expect_error(tidy(fit_na_row, conf.int = TRUE), NA) + expect_no_error(tidy(fit_na_row, conf.int = TRUE)) }) diff --git a/tests/testthat/test-lmodel2.R b/tests/testthat/test-lmodel2.R index 7fe9f3a78..078053cc0 100644 --- a/tests/testthat/test-lmodel2.R +++ b/tests/testthat/test-lmodel2.R @@ -1,5 +1,3 @@ -context("lmodel2") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-lmtest.R b/tests/testthat/test-lmtest.R index ad8c28f41..eaa1d8ec4 100644 --- a/tests/testthat/test-lmtest.R +++ b/tests/testthat/test-lmtest.R @@ -1,5 +1,3 @@ -context("lmtest") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-maps.R b/tests/testthat/test-maps.R index 9a752b481..05e6952f0 100644 --- a/tests/testthat/test-maps.R +++ b/tests/testthat/test-maps.R @@ -1,5 +1,3 @@ -context("maps tidiers") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-margins.R b/tests/testthat/test-margins.R index 5600926ef..deb8b10f4 100644 --- a/tests/testthat/test-margins.R +++ b/tests/testthat/test-margins.R @@ -1,5 +1,3 @@ -context("margins") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mass-fitdistr.R b/tests/testthat/test-mass-fitdistr.R index bffd5ead4..995f69dc5 100644 --- a/tests/testthat/test-mass-fitdistr.R +++ b/tests/testthat/test-mass-fitdistr.R @@ -1,5 +1,3 @@ -context("mass-fitdistr") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mass-negbin.R b/tests/testthat/test-mass-negbin.R index 539676ef8..e5e9030c9 100644 --- a/tests/testthat/test-mass-negbin.R +++ b/tests/testthat/test-mass-negbin.R @@ -1,5 +1,3 @@ -context("mass-negbin") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-mass-polr.R b/tests/testthat/test-mass-polr.R index 11c6fca95..af4635039 100644 --- a/tests/testthat/test-mass-polr.R +++ b/tests/testthat/test-mass-polr.R @@ -1,5 +1,3 @@ -context("mass-polr") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mass-ridgelm.R b/tests/testthat/test-mass-ridgelm.R index 3d5be3304..bec114b01 100644 --- a/tests/testthat/test-mass-ridgelm.R +++ b/tests/testthat/test-mass-ridgelm.R @@ -1,5 +1,3 @@ -context("mass-ridgelm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mass-rlm.R b/tests/testthat/test-mass-rlm.R index 34ead81ea..c148b3da3 100644 --- a/tests/testthat/test-mass-rlm.R +++ b/tests/testthat/test-mass-rlm.R @@ -1,5 +1,3 @@ -context("mass-rlm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mclust.R b/tests/testthat/test-mclust.R index c78c0ac3d..db95f1078 100644 --- a/tests/testthat/test-mclust.R +++ b/tests/testthat/test-mclust.R @@ -1,5 +1,3 @@ -context("mclust") - skip_on_cran() skip_if_not_installed("modeltests") @@ -91,8 +89,5 @@ test_that("augment.Mclust", { # augment(fit_on_vector) # ) - expect_error( - augment(fit, 1:10), - "`data` must be a data frame or matrix." - ) + expect_snapshot(error = TRUE, augment(fit, 1:10)) }) diff --git a/tests/testthat/test-mediation.R b/tests/testthat/test-mediation.R index 7edf96aff..cb54d5d1a 100644 --- a/tests/testthat/test-mediation.R +++ b/tests/testthat/test-mediation.R @@ -1,5 +1,3 @@ -context("mediate") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-metafor.R b/tests/testthat/test-metafor.R index a83f393cf..aedd53527 100644 --- a/tests/testthat/test-metafor.R +++ b/tests/testthat/test-metafor.R @@ -1,5 +1,3 @@ -context("rma") - skip_on_cran() # Matrix ABI version may differ (#1204) diff --git a/tests/testthat/test-mfx.R b/tests/testthat/test-mfx.R index bef5d3e71..55759c73e 100644 --- a/tests/testthat/test-mfx.R +++ b/tests/testthat/test-mfx.R @@ -1,5 +1,3 @@ -context("mfx") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mgcv.R b/tests/testthat/test-mgcv.R index 999822315..1c42ebafa 100644 --- a/tests/testthat/test-mgcv.R +++ b/tests/testthat/test-mgcv.R @@ -1,5 +1,3 @@ -context("mgcv") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-mlogit.R b/tests/testthat/test-mlogit.R index 3ae3f5ee3..bf3c9d41b 100644 --- a/tests/testthat/test-mlogit.R +++ b/tests/testthat/test-mlogit.R @@ -1,5 +1,3 @@ -context("mlogit") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-muhaz.R b/tests/testthat/test-muhaz.R index 5c7044ff1..7e2bef091 100644 --- a/tests/testthat/test-muhaz.R +++ b/tests/testthat/test-muhaz.R @@ -1,5 +1,3 @@ -context("muhaz") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-multcomp.R b/tests/testthat/test-multcomp.R index a8e2f4fee..4cd3f4623 100644 --- a/tests/testthat/test-multcomp.R +++ b/tests/testthat/test-multcomp.R @@ -1,5 +1,3 @@ -context("multcomp") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-nnet.R b/tests/testthat/test-nnet.R index 4ee5af1e5..76e65617e 100644 --- a/tests/testthat/test-nnet.R +++ b/tests/testthat/test-nnet.R @@ -1,5 +1,3 @@ -context("nnet") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-null-and-default.R b/tests/testthat/test-null-and-default.R index 2ac4b28d6..cd5747661 100644 --- a/tests/testthat/test-null-and-default.R +++ b/tests/testthat/test-null-and-default.R @@ -1,5 +1,3 @@ -context("null-and-default") - skip_if_not_installed("modeltests") library(modeltests) @@ -8,12 +6,12 @@ test_that("tidy.NULL", { }) test_that("tidy.default", { - expect_error(td <- tidy(raw(1))) - + expect_snapshot(error = TRUE, td <- tidy(raw(1))) + x <- 5 class(x) <- c("foo", "bar") - expect_error(glance(x), regexp = "foo") - expect_error(glance(x), regexp = "[^bar]") + expect_snapshot(error = TRUE, glance(x)) + expect_snapshot(error = TRUE, glance(x)) }) @@ -22,15 +20,15 @@ test_that("glance.NULL", { }) test_that("glance.default", { - expect_error(glance(TRUE)) - expect_error(glance(1)) - expect_error(glance(1L)) - expect_error(glance("a")) + expect_snapshot(error = TRUE, glance(TRUE)) + expect_snapshot(error = TRUE, glance(1)) + expect_snapshot(error = TRUE, glance(1L)) + expect_snapshot(error = TRUE, glance("a")) x <- 5 class(x) <- c("foo", "bar") - expect_error(glance(x), regexp = "foo") - expect_error(glance(x), regexp = "[^bar]") + expect_snapshot(error = TRUE, glance(x)) + expect_snapshot(error = TRUE, glance(x)) }) test_that("augment.NULL", { @@ -38,13 +36,13 @@ test_that("augment.NULL", { }) test_that("augment.default", { - expect_error(augment(TRUE)) - expect_error(augment(1)) - expect_error(augment(1L)) - expect_error(augment("a")) + expect_snapshot(error = TRUE, augment(TRUE)) + expect_snapshot(error = TRUE, augment(1)) + expect_snapshot(error = TRUE, augment(1L)) + expect_snapshot(error = TRUE, augment("a")) x <- 5 class(x) <- c("foo", "bar") - expect_error(augment(x), regexp = "foo") - expect_error(augment(x), regexp = "[^bar]") + expect_snapshot(error = TRUE, augment(x)) + expect_snapshot(error = TRUE, augment(x)) }) diff --git a/tests/testthat/test-orcutt.R b/tests/testthat/test-orcutt.R index d78d8fc73..cd5a73202 100644 --- a/tests/testthat/test-orcutt.R +++ b/tests/testthat/test-orcutt.R @@ -1,5 +1,3 @@ -context("orcutt") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-ordinal.R b/tests/testthat/test-ordinal.R index 2da988dc8..7b5b6e6b7 100644 --- a/tests/testthat/test-ordinal.R +++ b/tests/testthat/test-ordinal.R @@ -1,5 +1,3 @@ -context("ordinal") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-plm.R b/tests/testthat/test-plm.R index 5d9635ac9..0ef742c63 100644 --- a/tests/testthat/test-plm.R +++ b/tests/testthat/test-plm.R @@ -1,5 +1,3 @@ -context("plm tidiers") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-polca.R b/tests/testthat/test-polca.R index 511c4679c..86e7a1e4c 100644 --- a/tests/testthat/test-polca.R +++ b/tests/testthat/test-polca.R @@ -1,5 +1,3 @@ -context("polca") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-psych.R b/tests/testthat/test-psych.R index 94261f4a6..4b9912bbc 100644 --- a/tests/testthat/test-psych.R +++ b/tests/testthat/test-psych.R @@ -1,5 +1,3 @@ -context("psych") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-quantreg-nlrq.R b/tests/testthat/test-quantreg-nlrq.R index 0ac21f381..383280e10 100644 --- a/tests/testthat/test-quantreg-nlrq.R +++ b/tests/testthat/test-quantreg-nlrq.R @@ -1,5 +1,3 @@ -context("quantreg-nlrq") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-quantreg-rq.R b/tests/testthat/test-quantreg-rq.R index 919e133a5..02e16b7c0 100644 --- a/tests/testthat/test-quantreg-rq.R +++ b/tests/testthat/test-quantreg-rq.R @@ -1,5 +1,3 @@ -context("quantreg-rq") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-quantreg-rqs.R b/tests/testthat/test-quantreg-rqs.R index a8232e296..8ddc1702f 100644 --- a/tests/testthat/test-quantreg-rqs.R +++ b/tests/testthat/test-quantreg-rqs.R @@ -1,5 +1,3 @@ -context("quantreg-rqs") - skip_on_cran() skip_if_not_installed("modeltests") @@ -30,14 +28,7 @@ test_that("tidy.rqs", { }) test_that("glance.rqs", { - expect_error( - glance(fit), - regexp = paste( - "`glance` cannot handle objects of class 'rqs',", - "i.e. models with more than one tau value. Please", - "use a purrr `map`-based workflow with 'rq' models instead." - ) - ) + expect_snapshot(error = TRUE, glance(fit)) }) test_that("augment.rqs", { diff --git a/tests/testthat/test-robust.R b/tests/testthat/test-robust.R index 72a23af3a..dab650079 100644 --- a/tests/testthat/test-robust.R +++ b/tests/testthat/test-robust.R @@ -1,5 +1,3 @@ -context("robust") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-robustbase.R b/tests/testthat/test-robustbase.R index 79754e5e7..28fe6da81 100644 --- a/tests/testthat/test-robustbase.R +++ b/tests/testthat/test-robustbase.R @@ -1,5 +1,3 @@ -context("robustbase") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-spdep.R b/tests/testthat/test-spdep.R index ebb9764dd..a47b1eb7c 100644 --- a/tests/testthat/test-spdep.R +++ b/tests/testthat/test-spdep.R @@ -1,5 +1,3 @@ -context("spdep") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-speedglm-speedglm.R b/tests/testthat/test-speedglm-speedglm.R index 3bcd80239..701c04e3d 100644 --- a/tests/testthat/test-speedglm-speedglm.R +++ b/tests/testthat/test-speedglm-speedglm.R @@ -1,5 +1,3 @@ -context("test-speedglm-speedglm") - skip_on_cran() skip_if_not_installed("modeltests") @@ -38,6 +36,5 @@ test_that("glance.speedglm", { test_that("augment.speedglm errors", { # speedglm sub-classes speedlm, and there's an augment.speedlm() # method we want to make sure isn't accidentally invoked - - expect_error(augment(fit)) + expect_snapshot(error = TRUE, augment(fit)) }) diff --git a/tests/testthat/test-speedglm-speedlm.R b/tests/testthat/test-speedglm-speedlm.R index 64ced4116..55855976e 100644 --- a/tests/testthat/test-speedglm-speedlm.R +++ b/tests/testthat/test-speedglm-speedlm.R @@ -1,5 +1,3 @@ -context("speedglm") - skip_on_cran() skip_if_not_installed("modeltests") @@ -52,8 +50,5 @@ test_that("augment.speedlm", { newdata = mtcars ) - expect_error( - augment(fit3), - "Must specify `data` argument or refit speedglm with `fitted = TRUE`." - ) + expect_snapshot(error = TRUE, augment(fit3)) }) diff --git a/tests/testthat/test-stats-anova.R b/tests/testthat/test-stats-anova.R index 419bc2649..4762816c8 100644 --- a/tests/testthat/test-stats-anova.R +++ b/tests/testthat/test-stats-anova.R @@ -1,5 +1,3 @@ -context("stats-anova") - skip_if_not_installed("modeltests") library(modeltests) @@ -48,7 +46,7 @@ test_that("tidy.anova", { loess(dist ~ speed, cars, control = loess.control(surface = "direct")) ) - expect_warning(tidy(loess_anova)) + expect_snapshot(.res <- tidy(loess_anova)) }) test_that("glance.anova", { @@ -125,7 +123,7 @@ test_that("tidy.linearHypothesis", { expect_equal(td_lht$term, "disp - hp") expect_equal(td_lht$null.value, 0) - expect_equal(td_lht$estimate, -0.00551, tolerance = .00001) + expect_equal(td_lht$estimate, -0.005506, tolerance = .0001) }) # Matrix ABI version may differ (#1204) diff --git a/tests/testthat/test-stats-arima.R b/tests/testthat/test-stats-arima.R index 660e8d926..56efb5466 100644 --- a/tests/testthat/test-stats-arima.R +++ b/tests/testthat/test-stats-arima.R @@ -1,5 +1,3 @@ -context("stats-arima") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-stats-decompose.R b/tests/testthat/test-stats-decompose.R index ec21b6ef3..7f7f0de25 100644 --- a/tests/testthat/test-stats-decompose.R +++ b/tests/testthat/test-stats-decompose.R @@ -1,5 +1,3 @@ -context("stats-decompose") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-stats-factanal.R b/tests/testthat/test-stats-factanal.R index 4dffa94eb..f42904b33 100644 --- a/tests/testthat/test-stats-factanal.R +++ b/tests/testthat/test-stats-factanal.R @@ -1,5 +1,3 @@ -context("stats-factanal") - skip_on_cran() skip_if_not_installed("modeltests") @@ -59,10 +57,7 @@ test_that("augment.factanal works", { # errors for `scores = "none"` fit_none <- factanal(mtcars, n_factors, scores = "none") - expect_error( - augment(fit_none), - regexp = "Cannot augment factanal objects fit with `scores = 'none'`." - ) + expect_snapshot(error = TRUE, augment(fit_none)) }) test_that("augment.factanal works with matrix", { diff --git a/tests/testthat/test-stats-glm.R b/tests/testthat/test-stats-glm.R index 360a8e4e9..a562d0d82 100644 --- a/tests/testthat/test-stats-glm.R +++ b/tests/testthat/test-stats-glm.R @@ -1,5 +1,3 @@ -context("stats-glm") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-stats-htest.R b/tests/testthat/test-stats-htest.R index 7238dbdd2..9851adc24 100644 --- a/tests/testthat/test-stats-htest.R +++ b/tests/testthat/test-stats-htest.R @@ -1,5 +1,3 @@ -context("stats-htest") - skip_if_not_installed("modeltests") library(modeltests) @@ -20,7 +18,7 @@ test_that("tidy.htest same as glance.htest", { test_that("tidy.htest/oneway.test", { mtcars$cyl <- as.factor(mtcars$cyl) ot <- oneway.test(mpg ~ cyl, mtcars) - expect_message(td <- tidy(ot)) + expect_snapshot(td <- tidy(ot)) gl <- glance(ot) check_tidy_output(td) @@ -99,22 +97,13 @@ test_that("augment.htest (chi squared test)", { check_tibble(au2, method = "augment", strict = FALSE) tt <- t.test(rnorm(10)) - expect_error( - augment(tt), - regexp = "Augment is only defined for chi squared hypothesis tests." - ) - + expect_snapshot(error = TRUE, augment(tt)) + wt <- wilcox.test(mpg ~ am, data = mtcars, conf.int = TRUE, exact = FALSE) - expect_error( - augment(wt), - regexp = "Augment is only defined for chi squared hypothesis tests." - ) - + expect_snapshot(error = TRUE, augment(wt)) + ct <- cor.test(mtcars$wt, mtcars$mpg) - expect_error( - augment(ct), - regexp = "Augment is only defined for chi squared hypothesis tests." - ) + expect_snapshot(error = TRUE, augment(ct)) }) test_that("tidy.htest does not return matrix columns", { diff --git a/tests/testthat/test-stats-kmeans.R b/tests/testthat/test-stats-kmeans.R index 3c34d3022..e44d2119b 100644 --- a/tests/testthat/test-stats-kmeans.R +++ b/tests/testthat/test-stats-kmeans.R @@ -1,5 +1,3 @@ -context("stats-kmeans") - skip_if_not_installed("modeltests") library(modeltests) @@ -33,12 +31,6 @@ test_that("tidy.kmeans", { }) test_that("augment.kmeans", { - # data argument cannot be empty - expect_error( - augment(fit), - regexp = "argument \"data\" is missing, with no default" - ) - check_augment_function( aug = augment.kmeans, model = fit, diff --git a/tests/testthat/test-stats-lm.R b/tests/testthat/test-stats-lm.R index 9f8effeb8..3a8fc3fe2 100644 --- a/tests/testthat/test-stats-lm.R +++ b/tests/testthat/test-stats-lm.R @@ -1,5 +1,3 @@ -context("stats-lm") - skip_if_not_installed("modeltests") library(modeltests) @@ -35,8 +33,8 @@ test_that("tidy.lm works", { # conf.int = TRUE works for rank deficient fits # should get a "NaNs produced" warning - expect_warning(td_rd <- tidy(fit_rd, conf.int = TRUE)) - + expect_snapshot(td_rd <- tidy(fit_rd, conf.int = TRUE)) + check_tidy_output(td) check_tidy_output(td2) check_tidy_output(td3) @@ -52,9 +50,9 @@ test_that("tidy.lm works", { expect_equal(td2$term, c("(Intercept)", "wt", "log(disp)")) expect_equal(td3$term, c("(Intercept)")) - # shouldn't error. regression test for issues 166, 241 + # shouldn't error. regression test for issues #166 and #241. # rows for confidence intervals of undefined terms should be dropped - expect_error(tidy(fit_na_row, conf.int = TRUE), NA) + expect_no_error(tidy(fit_na_row, conf.int = TRUE)) }) test_that("glance.lm", { @@ -138,9 +136,8 @@ test_that("augment.lm", { expect_false(any(names(aug) %in% c(".lower", ".upper"))) # warns when passed as level rather than conf.level - expect_warning( - augment(fit, newdata = mtcars, interval = "confidence", level = 0.95), - "\\`level\\` argument is not supported in the \\`augment\\(\\)\\` method for \\`lm\\` objects" + expect_snapshot( + augment(fit, newdata = mtcars, interval = "confidence", level = 0.95) ) }) diff --git a/tests/testthat/test-stats-loess.R b/tests/testthat/test-stats-loess.R index 7a72194c5..3d6544731 100644 --- a/tests/testthat/test-stats-loess.R +++ b/tests/testthat/test-stats-loess.R @@ -1,5 +1,3 @@ -context("stats-loess") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-stats-mlm.R b/tests/testthat/test-stats-mlm.R index 54bcbec47..c8293487f 100644 --- a/tests/testthat/test-stats-mlm.R +++ b/tests/testthat/test-stats-mlm.R @@ -1,5 +1,3 @@ -context("stats-mlm") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-stats-nls.R b/tests/testthat/test-stats-nls.R index 7bbe12f12..bd247aaaf 100644 --- a/tests/testthat/test-stats-nls.R +++ b/tests/testthat/test-stats-nls.R @@ -1,5 +1,3 @@ -context("stats-nls") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-stats-prcomp.R b/tests/testthat/test-stats-prcomp.R index a68cd6a86..669e1b6a9 100644 --- a/tests/testthat/test-stats-prcomp.R +++ b/tests/testthat/test-stats-prcomp.R @@ -1,5 +1,3 @@ -context("stats-prcomp") - skip_if_not_installed("modeltests") library(modeltests) @@ -41,14 +39,11 @@ test_that("tidy.prcomp", { expect_identical(tidy(pc, matrix = "samples"), td3) expect_identical(tidy(pc, matrix = "scores"), td3) - expect_error( - tidy(pc, matrix = c("d", "u")), - regexp = "Must select a single matrix to tidy." - ) - + expect_snapshot(error = TRUE, tidy(pc, matrix = c("d", "u"))) + no_row_nm <- as.data.frame(matrix(1:9, ncol = 3) + rnorm(n = 9, sd = 0.25)) pca <- prcomp(no_row_nm) - expect_error(tidy(pca, matrix = "u"), NA) + expect_no_error(tidy(pca, matrix = "u")) }) test_that("augment.prcomp", { diff --git a/tests/testthat/test-stats-smooth.spline.R b/tests/testthat/test-stats-smooth.spline.R index 4d5d84781..555a5c337 100644 --- a/tests/testthat/test-stats-smooth.spline.R +++ b/tests/testthat/test-stats-smooth.spline.R @@ -1,5 +1,3 @@ -context("stats-smooth.spline") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-stats-summary-lm.R b/tests/testthat/test-stats-summary-lm.R index e1fd5f0f3..30843f136 100644 --- a/tests/testthat/test-stats-summary-lm.R +++ b/tests/testthat/test-stats-summary-lm.R @@ -1,5 +1,3 @@ -context("stats-summary-lm") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-stats-time-series.R b/tests/testthat/test-stats-time-series.R index 5f232c5e9..091f07e28 100644 --- a/tests/testthat/test-stats-time-series.R +++ b/tests/testthat/test-stats-time-series.R @@ -1,5 +1,3 @@ -context("stats-time-series") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-survey.R b/tests/testthat/test-survey.R index 82d3bbd9d..482173c7d 100644 --- a/tests/testthat/test-survey.R +++ b/tests/testthat/test-survey.R @@ -1,5 +1,3 @@ -context("survey") - skip_on_cran() skip_if_not_installed("modeltests") @@ -53,8 +51,5 @@ test_that("glance.svyglm: make sure `nobs` is there", { }) test_that("conf.int merging regression test (#804)", { - expect_error( - tidy(fit_svyglm, conf.int = TRUE), - NA - ) + expect_no_error(tidy(fit_svyglm, conf.int = TRUE)) }) diff --git a/tests/testthat/test-survival-aareg.R b/tests/testthat/test-survival-aareg.R index 62496a9fc..bd950ddef 100644 --- a/tests/testthat/test-survival-aareg.R +++ b/tests/testthat/test-survival-aareg.R @@ -1,5 +1,3 @@ -context("survival-aareg") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-survival-cch.R b/tests/testthat/test-survival-cch.R index d06e4b286..b1d2efbf0 100644 --- a/tests/testthat/test-survival-cch.R +++ b/tests/testthat/test-survival-cch.R @@ -1,5 +1,3 @@ -context("survival-cch") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-survival-coxph.R b/tests/testthat/test-survival-coxph.R index 3a2d32d18..988f5747f 100644 --- a/tests/testthat/test-survival-coxph.R +++ b/tests/testthat/test-survival-coxph.R @@ -1,5 +1,3 @@ -context("survival-coxph") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-survival-pyears.R b/tests/testthat/test-survival-pyears.R index fb1014086..a61c089f0 100644 --- a/tests/testthat/test-survival-pyears.R +++ b/tests/testthat/test-survival-pyears.R @@ -1,5 +1,3 @@ -context("survival-pyears") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-survival-survdiff.R b/tests/testthat/test-survival-survdiff.R index ae6a53944..8f8a8d632 100644 --- a/tests/testthat/test-survival-survdiff.R +++ b/tests/testthat/test-survival-survdiff.R @@ -1,5 +1,3 @@ -context("survival-survdiff") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-survival-survexp.R b/tests/testthat/test-survival-survexp.R index f44c0bd2f..36b12addc 100644 --- a/tests/testthat/test-survival-survexp.R +++ b/tests/testthat/test-survival-survexp.R @@ -1,5 +1,3 @@ -context("survival-survexp") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-survival-survfit.R b/tests/testthat/test-survival-survfit.R index 54a997551..8cb061c45 100644 --- a/tests/testthat/test-survival-survfit.R +++ b/tests/testthat/test-survival-survfit.R @@ -1,5 +1,3 @@ -context("survival-survfit") - skip_on_cran() skip_if_not_installed("modeltests") @@ -34,16 +32,9 @@ test_that("tidy.survfit", { }) test_that("glance.survfit", { - expect_error( - glance(sfit), - regexp = "Cannot construct a glance of a multi-strata survfit object." - ) - - expect_error( - glance(fit2), - regexp = "Cannot construct a glance of a multi-state survfit object." - ) - + expect_snapshot(error = TRUE, glance(sfit)) + expect_snapshot(error = TRUE, glance(fit2)) + gl <- glance(sfit2) check_glance_outputs(gl) }) diff --git a/tests/testthat/test-survival-survreg.R b/tests/testthat/test-survival-survreg.R index a8f1ccc11..cd9682655 100644 --- a/tests/testthat/test-survival-survreg.R +++ b/tests/testthat/test-survival-survreg.R @@ -1,5 +1,3 @@ -context("survival-survreg") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-systemfit.R b/tests/testthat/test-systemfit.R index 663a02ae6..c4a3ad251 100644 --- a/tests/testthat/test-systemfit.R +++ b/tests/testthat/test-systemfit.R @@ -1,5 +1,3 @@ -context("systemfit") - skip_on_cran() skip_if_not_installed("modeltests") diff --git a/tests/testthat/test-tseries.R b/tests/testthat/test-tseries.R index 45702e7a7..01ec4556d 100644 --- a/tests/testthat/test-tseries.R +++ b/tests/testthat/test-tseries.R @@ -1,5 +1,3 @@ -context("tseries") - skip_if_not_installed("modeltests") library(modeltests) diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index 5288aca64..a555c36e1 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -1,37 +1,29 @@ -context("utilities") - skip_if_not_installed("modeltests") library(modeltests) test_that("ellipsis checking works", { - expect_warning( - check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE), - "\\`exponentiate\\` argument is not supported in the \\`tidy\\(\\)\\` method for \\`boop\\` objects" + expect_snapshot( + check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE) ) - - expect_warning( - check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE, quick = FALSE), - "\\`exponentiate\\` argument is not supported in the \\`tidy\\(\\)\\` method for \\`boop\\` objects" + + expect_snapshot( + check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE, quick = FALSE) ) - + expect_silent(check_ellipses("exponentiate", "tidy", "boop", hi = "pal")) }) test_that("ellipsis checking works (whole game, tidy)", { mod <- nls(mpg ~ k * e^wt, data = mtcars, start = list(k = 1, e = 2)) - expect_warning( - tidy(mod, exponentiate = TRUE), - "\\`exponentiate\\` argument is not supported in the \\`tidy\\(\\)\\` method for \\`nls\\` objects" - ) + expect_snapshot(tidy(mod, exponentiate = TRUE)) }) test_that("ellipsis checking works (whole game, augment)", { mod <- kmeans(mtcars, centers = 4) - expect_warning( - augment(mod, data = mtcars, newdata = mtcars), - "\\`newdata\\` argument is not supported in the \\`augment\\(\\)\\` method for \\`kmeans\\` objects" + expect_snapshot( + .res <- augment(mod, data = mtcars, newdata = mtcars) ) }) @@ -135,32 +127,22 @@ test_that("as_glance_tibble", { expect_false(class(df1$y) == class(df2$y)) - expect_error( - as_glance_tibble(x = 1, y = 1, na_types = "rrr") - ) + expect_snapshot(error = TRUE, as_glance_tibble(x = 1, y = 1, na_types = "rrr")) }) test_that("appropriate warning on (g)lm-subclassed models", { x <- 1 class(x) <- c("boop", "glm") - expect_warning( - warn_on_subclass(x, "tidy"), - "class \\`boop\\`.*only supported through the \\`glm\\` tidier method." - ) - + expect_snapshot(warn_on_subclass(x, "tidy")) + # only displayed once per session, per unique dispatch - expect_silent( - warn_on_subclass(x, "tidy") - ) + expect_silent(warn_on_subclass(x, "tidy")) class(x) <- c("bop", "glm", "lm") - expect_warning( - warn_on_subclass(x, "tidy"), - "class \\`bop\\`.*only supported through the `glm` tidier method." - ) - + expect_snapshot(warn_on_subclass(x, "tidy")) + # only displayed once per session, per unique dispatch expect_silent( warn_on_subclass(x, "tidy") diff --git a/tests/testthat/test-vars.R b/tests/testthat/test-vars.R index 1292571da..3ad4219d9 100644 --- a/tests/testthat/test-vars.R +++ b/tests/testthat/test-vars.R @@ -1,5 +1,3 @@ -context("vars") - skip_on_cran() skip_if_not_installed("modeltests") skip_if_not_installed("vars") @@ -20,7 +18,7 @@ test_that("tidy.vars", { check_tidy_output(td) check_dims(td, 24, 6) # vars does not produce confidence intervals - expect_warning(tidy(fit, conf.int = TRUE)) + expect_snapshot(.res <- tidy(fit, conf.int = TRUE)) }) diff --git a/tests/testthat/test-zoo.R b/tests/testthat/test-zoo.R index 9810c8d75..b88acbb8e 100644 --- a/tests/testthat/test-zoo.R +++ b/tests/testthat/test-zoo.R @@ -1,5 +1,3 @@ -context("zoo") - skip_on_cran() skip_if_not_installed("modeltests")