knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
dubioustests is a testing package for lazy typers with parentheses-phobia.
It essentially proposes shorthands for testthat functions, using a syntax powered by the doubt package, hence its name.
Install with :
remotes::install_github("moodymudskipper/dubioustests")
Let's attach both dubioustests and testthat and review sets of equivalent calls.
library(testthat) library(dubioustests, warn.conflicts = FALSE)
Test if a value is TRUE
:
expect_true(is.numeric(2)) ?~ is.numeric(2)
Test if two values are equal using all.equal()
expect_equal(tan(pi/4), 1) ?e~ tan(pi/4) ? 1
Test if two values are identical using identical()
expect_identical(tan(pi/4), 1) ?i~ tan(pi/4) ? 1
We can also use the infix notation and write tan(pi/4) ?i~ 1
instead of
?i~ tan(pi/4) ? 1
%?%
%?%
is testthat::test_that()
but the description text comes first and we don't
need parentheses anymore.
Putting everything together we get :
"test that my functions work" %?% { ?~ is.numeric(2) ?e~ tan(pi/4) ? 1 }
The package doesn't propose other aliases for testthat functions at the moment.
In many case the ?~
or ?e~
shorthands do the job just fine though. The two
following expressions would only differ by the error message they would generate
but they're explicit either way.
test_that("a few things work as they should", { expect_length(4:6, 4) expect_gt(4, 5) expect_match("foobar","^bar") }) "a few things work as they should" %?% { ?~ length(4:6) == 4 ?~ 4 > 5 ?~ grepl("^bar","foobar") }
And if needed we can easily define new dubious aliases :
`?len~` <- expect_length `?err~` <- expect_error ?len~ 4:6 ? 4 ?err~ stop("foo error") ?err~ stop("foo error") ? "^foo" ?err~ stop("foo error") ? "^bar"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.