Skip to content

Conversation

@gegnew
Copy link

@gegnew gegnew commented Apr 27, 2021

Heyo! I've starting trying to implement a test runner for R using testthat. It's proving to be a bit nontrivial, because there is no testthat executable that accepts flag arguments (mostly). To run testthat from the command line, you have to use Rscript, and pass valid R code as a string to the "-e" flag.

i.e.:

Rscript -e "library(testthat); test_local()"
  • I've managed to implement TestFile.
  • TestSuite alone is no problem, but I haven't managed to implement it alongside TestFile. The test executable would ideally be Rscript -e "library(testthat); test_local()", but test#r#testthat#build_position must handle the test_local part of the script like: "test_local(filter='something')", since the filter is not a flag.
  • I have no idea how to implement TestNearest; it may not be possible.

I'd love some help, if anyone has time!

Make sure these boxes are checked before submitting your pull request:

  • Add fixtures and spec when implementing or updating a test runner
  • Update the README accordingly
  • Update the Vim documentation in doc/test.txt

@gegnew gegnew force-pushed the gegnew/testthat branch from 58239a7 to d053990 Compare May 19, 2021 12:55
@codeinabox
Copy link
Collaborator

Thank you for this and your patience. Would love to help out with this, do you have an example of the scenario you are trying to address?

@gegnew
Copy link
Author

gegnew commented Feb 7, 2022

I'm trying to address the situation where I'm editing R in vim (instead of Rstudio), and would like to run testthat files from vim. Something as simple as this test:

# my-r-file.R
test_that("is equal", {
    expect_equal(1, 1)
})

@@ -0,0 +1,49 @@
if !exists('g:test#r#testthat#file_pattern')
let g:test#r#testthat#file_pattern = '\v(test-[^/]+|[^/]+)\.R$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this regex case sensitive? If so, I'd like to support lowercase .r files as well because case insensitive filesystem users often play fast and loose with casing in filenames. (I myself am guilty of this ✋)

Suggested change
let g:test#r#testthat#file_pattern = '\v(test-[^/]+|[^/]+)\.R$'
let g:test#r#testthat#file_pattern = '\v(test-[^/]+|[^/]+)\.[Rr]$'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants