Skip to content

Commit

Permalink
docs: add .lazytest guidance
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Apr 20, 2023
1 parent 7875faa commit 797260a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ In the next call, if `.lazytest` exists, it is consulted, and a suitable `filter

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

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<pre class='chroma'>
<span><span class='kr'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='o'>(</span><span class='nv'><a href='https://github.com/cynkra/lazytest'>lazytest</a></span><span class='o'>)</span></span></pre>

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()`](https://cynkra.github.io/lazytest/reference/lazytest_local.html) function, a drop-in replacement for [`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html), that
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()`](https://lazytest.cynkra.com/reference/lazytest_local.html) function, a drop-in replacement for [`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html), that

- memoizes which tests have failed;
- runs only those tests in subsequent runs.
Expand All @@ -20,10 +20,10 @@ If all active tests have succeeded, the entire test suite is run in a second pas

## Usage

Call [`lazytest_local()`](https://cynkra.github.io/lazytest/reference/lazytest_local.html) instead of [`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html) or [`devtools::test()`](https://devtools.r-lib.org/reference/test.html):
Call [`lazytest_local()`](https://lazytest.cynkra.com/reference/lazytest_local.html) instead of [`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html) or [`devtools::test()`](https://devtools.r-lib.org/reference/test.html):

<pre class='chroma'>
<span><span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://cynkra.github.io/lazytest/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span></pre>
<span><span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://lazytest.cynkra.com/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span></pre>

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()`](https://devtools.r-lib.org/reference/test.html), and there seems to be no way to customize it or hook into it.

Expand All @@ -48,7 +48,7 @@ If we run the tests, they all pass.
<pre class='chroma'>
<span><span class='nf'>withr</span><span class='nf'>::</span><span class='nf'><a href='https://withr.r-lib.org/reference/with_dir.html'>with_dir</a></span><span class='o'>(</span></span>
<span> <span class='nv'>pkg_dir</span>,</span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://cynkra.github.io/lazytest/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://lazytest.cynkra.com/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span><span class='o'>)</span></span>
<span><span class='c'>#&gt; <span style='color: #00BBBB;'>ℹ</span> Testing all tests.</span></span>
<span><span class='c'>#&gt; <span style='color: #00BB00;'>✔</span> | <span style='color: #BBBB00;'>F</span> <span style='color: #BB00BB;'>W</span> <span style='color: #0000BB;'>S</span> <span style='color: #00BB00;'> OK</span> | Context</span></span>
Expand All @@ -57,6 +57,8 @@ If we run the tests, they all pass.
<span><span class='c'>#&gt; </span></span>
<span><span class='c'>#&gt; ══ <span style='font-weight: bold;'>Results</span> ═════════════════════════════════════════════════════════════════════</span></span>
<span><span class='c'>#&gt; [ FAIL 0 | WARN 0 | SKIP 0 | <span style='color: #00BB00;'>PASS</span> 2 ]</span></span>
<span><span class='c'>#&gt; </span></span>
<span><span class='c'>#&gt; <span style='color: #00BB00;'>😀</span></span></span>
<span><span class='c'>#&gt; → Testing all tests next time.</span></span></pre>

Now if we replace one of the tests with a failing test,
Expand All @@ -76,7 +78,7 @@ and then run the tests,
<pre class='chroma'>
<span><span class='nf'>withr</span><span class='nf'>::</span><span class='nf'><a href='https://withr.r-lib.org/reference/with_dir.html'>with_dir</a></span><span class='o'>(</span></span>
<span> <span class='nv'>pkg_dir</span>,</span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://cynkra.github.io/lazytest/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://lazytest.cynkra.com/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span><span class='o'>)</span></span>
<span><span class='c'>#&gt; <span style='color: #00BBBB;'>ℹ</span> Testing all tests.</span></span>
<span><span class='c'>#&gt; <span style='color: #00BB00;'>✔</span> | <span style='color: #BBBB00;'>F</span> <span style='color: #BB00BB;'>W</span> <span style='color: #0000BB;'>S</span> <span style='color: #00BB00;'> OK</span> | Context</span></span>
Expand Down Expand Up @@ -109,7 +111,7 @@ Next time we run the tests, only this test will be run, until it is fixed at whi
<pre class='chroma'>
<span><span class='nf'>withr</span><span class='nf'>::</span><span class='nf'><a href='https://withr.r-lib.org/reference/with_dir.html'>with_dir</a></span><span class='o'>(</span></span>
<span> <span class='nv'>pkg_dir</span>,</span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://cynkra.github.io/lazytest/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span> <span class='nf'>lazytest</span><span class='nf'>::</span><span class='nf'><a href='https://lazytest.cynkra.com/reference/lazytest_local.html'>lazytest_local</a></span><span class='o'>(</span><span class='o'>)</span></span>
<span><span class='o'>)</span></span>
<span><span class='c'>#&gt; <span style='color: #00BBBB;'>ℹ</span> Testing only tests that failed last time:</span></span>
<span><span class='c'>#&gt; <span style='color: #00BBBB;'>•</span> blop</span></span>
Expand All @@ -130,10 +132,12 @@ Next time we run the tests, only this test will be run, until it is fixed at whi

## How does it work?

[`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html) returns an object from which the tests that have failed can be retrieved. [`lazytest_local()`](https://cynkra.github.io/lazytest/reference/lazytest_local.html) 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()`](https://testthat.r-lib.org/reference/test_package.html).
[`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html) returns an object from which the tests that have failed can be retrieved. [`lazytest_local()`](https://lazytest.cynkra.com/reference/lazytest_local.html) 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()`](https://testthat.r-lib.org/reference/test_package.html).

When all tests have passed and not all tests were run, a second call to [`testthat::test_local()`](https://testthat.r-lib.org/reference/test_package.html) 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/):
Expand All @@ -144,7 +148,7 @@ You can install the development version of lazytest from [cynkra R-universe](htt
Or from GitHub:

<pre class='chroma'>
<span><span class='nf'>pak</span><span class='nf'>::</span><span class='nf'><a href='https://pak.r-lib.org/reference/pak.html'>pak</a></span><span class='o'>(</span><span class='s'>"krlmlr/lazytest"</span><span class='o'>)</span></span></pre>
<span><span class='nf'>pak</span><span class='nf'>::</span><span class='nf'><a href='http://pak.r-lib.org/reference/pak.html'>pak</a></span><span class='o'>(</span><span class='s'>"krlmlr/lazytest"</span><span class='o'>)</span></span></pre>

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:

Expand Down

0 comments on commit 797260a

Please sign in to comment.