Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R: Test explorer improvements #1808

Closed
4 of 12 tasks
jennybc opened this issue Nov 9, 2023 · 10 comments
Closed
4 of 12 tasks

R: Test explorer improvements #1808

jennybc opened this issue Nov 9, 2023 · 10 comments
Assignees
Labels

Comments

@jennybc
Copy link
Member

jennybc commented Nov 9, 2023

In anticipation of merging #1763 in the near-ish future, I'm opening this issue to track TODOs that are already on my mind, but that won't be part of #1763. It's also a fine place to put feedback as people use the testing feature.

@jennybc
Copy link
Member Author

jennybc commented Nov 11, 2023

When there is no current testing view, we currently see this:

Screenshot 2023-11-14 at 2 43 57 PM

If the workspace is an R package, I think we'd like to not see the contribution from the positron-python package here:

https://github.com/posit-dev/positron-python/blob/98da4f51910f36c1d898a96461acdf19b662d19c/package.json#L2028-L2032

but I think that would require some work/coordination in positron that provides the positron R and Python extensions some notion of "this is an R project" vs. "this is a Python" project, for use in the when clause.

This is now #2637.

@jennybc
Copy link
Member Author

jennybc commented Nov 29, 2023

  • Ask the running R runtime about its locale and then match that in the child process used to run tests

Update: done in #2488

@jennybc
Copy link
Member Author

jennybc commented Dec 4, 2023

readr uses testthat but does not have a tests/testthat.R file. Instead it has tests/first_edition.R and tests/second_edition.R. This violates the current test for whether a package uses testthat:

const dotRPattern = new vscode.RelativePattern(packageRoot, testthatDotRPattern);
const testthatDotR = await vscode.workspace.findFiles(dotRPattern, null, 1);
if (testthatDotR.length === 0) {
Logger.info('tests/testthat.R not found');
return;
}

  • Revisit refreshTestthatStatus() and the way we set the testthatIsConfigured context key. I suppose the check should align with what I do in usethis:

    uses_testthat <- function() {
      paths <- proj_path(c(path("inst", "tests"), path("tests", "testthat")))
      any(dir_exists(paths))
    }
    

Despite this fact, the test explorer still works in readr. This is nice, I guess, but is also somewhat surprising. Rationalize that when I come back to do 👆

Now part of #2638.

@jennybc
Copy link
Member Author

jennybc commented Dec 4, 2023

  • Figure out how to initialize the parser just once.

The intent already is to initialize the tree-sitter-r parser exactly once:

if (parser === undefined) {
parser = await initializeParser();
}

But if the first use of the parser coincides with a full test run, and all the test files are getting parsed for the first time, it appears to effectively result in one initialization per test file:

2023-12-04 09:55:07.706 [info] Test run started
2023-12-04 09:55:07.706 [info] Running all tests
2023-12-04 09:55:07.706 [info] Test type is directory
2023-12-04 09:55:07.706 [info] Parsing test file file:///Users/jenny/rrr/readr/tests/testthat/test-parsing-character.R
2023-12-04 09:55:07.706 [info] Initializing parser
2023-12-04 09:55:07.707 [info] Parsing test file file:///Users/jenny/rrr/readr/tests/testthat/test-utils.R
2023-12-04 09:55:07.707 [info] Initializing parser
2023-12-04 09:55:07.707 [info] Parsing test file file:///Users/jenny/rrr/readr/tests/testthat/test-collectors.R
2023-12-04 09:55:07.707 [info] Initializing parser
2023-12-04 09:55:07.707 [info] Parsing test file file:///Users/jenny/rrr/readr/tests/testthat/test-read-lines.R
2023-12-04 09:55:07.707 [info] Initializing parser
...

The parsing is either happening literally in parallel or in such close succession that it is effectively in parallel. This doesn't seem to cause a user-perceivable problem, but it still seems worth correcting.

Now part of #2638.

@jennybc
Copy link
Member Author

jennybc commented Dec 14, 2023

Slack feedback from @aronatkins:

I was just experimenting with running package tests in Positron and one of the tests encountered an error. When I used devtools::check(remote = TRUE, manual = TRUE) in the console or when run in RStudio, I got an error and its traceback. Is there a way to see the full traceback in the Positron test view? (for the curious: rsconnect bioc local test failures again)

If you’re ever looking for a package that just doesn’t work at all when its tests are run in Positron, look to packrat. Oy. There’s probably all sorts of local filesystem shenanigans that require very specific test ordering…

@jennybc
Copy link
Member Author

jennybc commented Dec 18, 2023

Something I've noticed and was also raised by @hfrick in Slack:

  • Do something (more) sensible with the message associated with a skipped test.

I skip some tests and noticed that the reasons for the skip (= the text inside of skip(), e.g. skip("because I haven't implemented this yet")) are smashed together without a space or line break. Can I wish for a line break?

Screenshot 2023-12-17 at 17 42 10

Update: usethis is a good example for seeing this behaviour:

Reason: Not on GitHub Actions, Travis, or AppveyorReason: Not on GitHub Actions, Travis, or AppveyorReason: Not on GitHub Actions, Travis, or Appveyor

Fixed in #2796

@jennybc
Copy link
Member Author

jennybc commented Dec 18, 2023

Another observation from @hfrick:

Positron seems to struggle with single quotes in test description.

test_that("this test without single quotes will pass", {
  expect_identical(TRUE, TRUE)
})

test_that("this test with 'single quotes' will error in Positron", {
  expect_identical(TRUE, TRUE)
})

Screenshot 2023-12-18 at 16 48 15

Later addition: @hadley is also seeing something odd with test that use backticks in their description.

This is now #2639.

@jennybc
Copy link
Member Author

jennybc commented Dec 18, 2023

Raised by @hadley in slack.

  • Determine the connection between "Test: Run Tests in Current File" and the testing API and our test explorer.
Screenshot 2023-12-18 at 12 14 28 PM

Update: "Test: Run Tests in Current File" does already work if and only if the test files have been loaded into the controller. So, if you've already interacted with the test explorer (the beaker), all is well.

Takeaway: maybe my listener for test file creation and modification should expand to include opening a test file in an editor.

Now part of #2638.

@jennybc
Copy link
Member Author

jennybc commented Jan 31, 2024

Reported by @andrie in slack:

Testing:
Testing using the VS-code testing pane on Windows still throw errors, based on incorrect handling of Windows file paths, e.g:

Error: ℹ Loading vscodereporter
Error: '\U' used without hex digits in character string (<input>:1:32)
Execution halted

Update: this was fixed in #2194

@jennybc
Copy link
Member Author

jennybc commented Apr 3, 2024

This issue was, unofficially, a huge epic. Closing now that I've opened the remaining items as individual issues.

@jennybc jennybc closed this as completed Apr 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants