-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
96 lines (62 loc) · 3.53 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
output: downlit::readme_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
pkgload::load_all()
```
# lazytest
<!-- badges: start -->
[![R-CMD-check](https://github.com/cynkra/lazytest/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/cynkra/lazytest/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/lazytest)](https://CRAN.R-project.org/package=lazytest)
<!-- badges: end -->
```{r}
library(lazytest)
```
The goal of lazytest is to save development time by helping you rerun only the tests that have failed during the last run.
It integrates tightly with the testthat package and provides the `lazytest_local()` function, a drop-in replacement for `testthat::test_local()`, that
- memoizes which tests have failed;
- runs only those tests in subsequent runs.
If all active tests have succeeded, the entire test suite is run in a second pass.
## Usage
Call `lazytest_local()` instead of `testthat::test_local()` or `devtools::test()`:
```{r, eval = FALSE}
lazytest::lazytest_local()
```
The package also provides RStudio add-ins that run the tests in a new terminal.
Unfortunately, the "Test package" command is hard-wired to `devtools::test()`, and there seems to be no way to customize it or hook into it.
## Example
```{r child="man/rmd/lazytest_local.Rmd"}
```
## How does it work?
`testthat::test_local()` returns an object from which the tests that have failed can be retrieved.
`lazytest_local()` wraps this function.
If tests have failed, a file named `.lazytest` is written in the package directory.
In the next call, if `.lazytest` exists, it is consulted, and a suitable `filter` argument is constructed and passed to `testthat::test_local()`.
When all tests have passed and not all tests were run, a second call to `testthat::test_local()` is initiated, to make sure that no failures have been introduced in the meantime.
The presence of a `.lazytest` file in the package source indicates that the last test run has failed somewhere.
You should not need to gitignore or Rbuildignore it: you should fix the reason behind the test failure, then run tests again, before committing to your repository's default branch for instance.
## Installation and optional setup
You can install the development version of lazytest from [cynkra R-universe](https://cynkra.r-universe.dev/):
``` r
install.packages('lazytest', repos = c('https://cynkra.r-universe.dev', 'https://cloud.r-project.org'))
```
Or from GitHub:
``` r
pak::pak("krlmlr/lazytest")
```
If you're using RStudio, it is a good idea to remap the shortcut for running tests (default: Ctrl + Shift + T / Cmd + Shift + T).
The add-in provides two commands:
- Run Lazy Tests in New Terminal (recommended mapping: Ctrl + Shift + T / Cmd + Shift + T)
- Reset And Run Lazy Tests in New Terminal (recommended mapping: Ctrl + T / Cmd + T)
This allows you to keep the workflows you're accustomed to and to benefit immediately.
![RStudio shortcut configuration](https://github.com/cynkra/lazytest/raw/main/readme/rstudio-kb.png)
---
## Code of Conduct
Please note that the lazytest project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.