Skip to contents

This function will test a source package using testthat, making sure the package and its source package dependencies are up-to-date and loaded

Usage

pkg_test(
  pkgid,
  filter = NULL,
  src_pkgs = get_srcpkgs(),
  export_all = TRUE,
  quiet = TRUE,
  ...
)

Arguments

pkgid

a package name, path or package object

filter

filter in the tests to run. cf testthat::test_dir()

src_pkgs

a collection of source packages as a srckgs object.

export_all

passed to pkg_load(). Enables the test functions to easily access to non-exported functions. Caveat: If the pkg is already loaded and up-to-date with export_all=FALSE, it will not work.

quiet

whether to be quiet/silent

...

passed to testthat::test_dir()

Value

the results as a pkg_test object, which is an empty listL if no tests were found

Examples

 pkg <- setup_and_get_dummy_srcpkg()
 res <- pkg_test(pkg)
#>  | F W  S  OK | Context
#> 
#> ⠏ |          0 | failure                                                        
#>  | 1        0 | failure
#> ────────────────────────────────────────────────────────────────────────────────
#> Failure (test_failure.R:3:3): does_nothing_special - failure
#> does_nothing_special() not equal to 0.
#> 1/1 mismatches
#> [1] 42 - 0 == 42
#> ────────────────────────────────────────────────────────────────────────────────
#> 
#> ⠏ |          0 | success                                                        
#>  |          1 | success
#> 
#> ══ Results ═════════════════════════════════════════════════════════════════════
#> ── Failed tests ────────────────────────────────────────────────────────────────
#> Failure (test_failure.R:3:3): does_nothing_special - failure
#> does_nothing_special() not equal to 0.
#> 1/1 mismatches
#> [1] 42 - 0 == 42
#> 
#> [ FAIL 1 | WARN 0 | SKIP 0 | PASS 1 ]
 print(res)
#> 
#> ── Test results by test for package dummy.srcpkg ───────────────────────────────
#> ╒════════════╤══════════════════════════════╤══╤══════╤══════╤═══════╤═════╤═══════╤═════╕
#> │ file       │ test                         │nb│failed│passed│skipped│error│warning│ time│
#> ╞════════════╪══════════════════════════════╪══╪══════╪══════╪═══════╪═════╪═══════╪═════╡
#> │test_failure│does_nothing_special - failure│ 1│ 1    │ 0    │ FALSE │FALSE│ 0     │0.034
#> │test_success│does_nothing_special - success│ 1│ 0    │ 1    │ FALSE │FALSE│ 0     │0.019
#> ╘════════════╧══════════════════════════════╧══╧══════╧══════╧═══════╧═════╧═══════╧═════╛
#> 
#> ── Test results by file for package dummy.srcpkg ───────────────────────────────
#> ╒════════════╤══╤══════╤══════╤═══════╤═════╤═══════╤═════╕
#> │ file       │nb│failed│passed│skipped│error│warning│ time│
#> ╞════════════╪══╪══════╪══════╪═══════╪═════╪═══════╪═════╡
#> │test_failure│ 1│ 1    │ 0    │ 0     │ 0   │ 0     │0.034
#> │test_success│ 1│ 0    │ 1    │ 0     │ 0   │ 0     │0.019
#> ╘════════════╧══╧══════╧══════╧═══════╧═════╧═══════╧═════╛
#> 
#> ── Test results overview for package dummy.srcpkg ──────────────────────────────
#> ╒══╤══════╤══════╤═══════╤═════╤═══════╤══════════════════╕
#> │nb│failed│passed│skipped│error│warning│ time             │
#> ╞══╪══════╪══════╪═══════╪═════╪═══════╪══════════════════╡
#> │ 2│ 1    │ 1    │ 0     │ 0   │ 0     │0.0530000000000044│
#> ╘══╧══════╧══════╧═══════╧═════╧═══════╧══════════════════╛