-
Notifications
You must be signed in to change notification settings - Fork 92
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
Test parsing and running upgrades #2796
Conversation
@@ -152,6 +152,7 @@ module.exports.indentationFilter = [ | |||
// --- Start Positron --- | |||
'!**/amalthea/**/*', | |||
'!extensions/positron-r/resources/scripts/*.R', | |||
'!extensions/positron-r/resources/testing/**', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tree-sitter queries are in .scm
files and some of the precommit hygiene checks are not appropriate.
That also applies to the embedded R package for test reporting, which also lives here.
Same for the diff just below.
(namespace_operator | ||
lhs: (identifier) | ||
rhs: (identifier) @parent_function | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In https://github.com/posit-dev/positron/pull/2726/files#r1559866539 I promised to bring back the ability to parse testthat::test_that()
and here it is.
@@ -0,0 +1,32 @@ | |||
(call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving these queries into their own files has various advantages:
- If we want to add queries, we can drop the
.scm
files here and the test parser will pick them up automatically now. These queries are extremely un-fun to write and are similar to regular expressions in terms of how hard they are to understand later. I suspect it will be easier to handle more styles of usage by adding queries than by making these queries increasingly complicated. - Easier to test the queries in https://github.com/DavisVaughan/r-tree-sitter.
- Easier to maintain the queries and look at diffs, now that they have some reasonable syntax highlighting. Apparently the
.scm
extension is conventional because it's almost like Scheme.
* Is this a top-level call in the testthat file? Only top-level tests can be run individually. | ||
* This is really about making sure we can distinguish a top-level `describe()` (individually | ||
* runnable) from a `describe()` that's nested inside another `describe()` call (only runnable | ||
* as part of its enclosing `describe()` or test file). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is work yet to be done re: nested describe()
s. But this is one part of what's needed to determine whether a describe()
can be run individually. Not used yet, but will be in future. See #2805.
const escapedLabel = test?.label.replace(/(['"`])/g, '\\$1'); | ||
const descInsert = isSingleTest ? ` desc = '${escapedLabel || '<all tests>'}', ` : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what fixes things for tests where the description contains quotes or backticks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, here's what happened when trying to run a test item with '
, "
, or backtick in its description:
Screen.Recording.2024-04-18.at.8.18.52.AM.mov
After, it works:
Screen.Recording.2024-04-18.at.8.14.20.AM.mov
@@ -158,7 +165,7 @@ export async function runThatTest( | |||
break; | |||
case 'add_result': | |||
if (data.result !== undefined && data.test !== undefined) { | |||
const testItem = isSingleTest | |||
const testItem = testType === ItemType.TestThat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can only assume a test result is for the test item that triggered this test run if you're running a single test_that()
. In describe(it())
-land, you get results for the individual it()
calls, which are not the test item for the test run (although they are children of it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recording in https://github.com/posit-dev/positron/pull/2796/files#r1570975865 also covers this, i.e. it's why the it()
calls are correctly receiving green checks.
edfb344
to
2e63fac
Compare
// TODO: Should really also require that this is a top-level describe(). | ||
case ItemType.Describe: { | ||
const testthatInstalled = await checkInstalled('testthat', '3.2.1'); | ||
if (!testthatInstalled) { | ||
return Promise.resolve('testthat >= 3.2.1 is needed to run R a single describe() test.'); | ||
} | ||
LOGGER.info('Single describe() test'); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running an individual top-level describe()
now works, for most usage. Known issues recorded in #2805: nested describe()
is not fully accounted for; different behaviour when clicking in test explorer tree view vs. in gutter of test file when the describe()
has exactly 1 it()
.
This recording shows running a single describe()
. Note that its it()
children correctly receive their result (success) and the other describe()
s in the file remain un-executed.
Screen.Recording.2024-04-18.at.8.23.41.AM.mov
// Currently skip messages leak out to the TEST RESULTS | ||
// area, which is presumably not the long-term plan for | ||
// how we want to use that space. | ||
// But in the meantime, let's at least break lines. | ||
// appendOutput method is documented to need CRLF not LF. | ||
run.appendOutput( | ||
data.message + ': ' + data.location + '\r\n', | ||
undefined, | ||
testItem | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is clearly much room for improvement re: how we use the TEST RESULTS tab of the panel, but skip message are at least readable/usable now.
Before, where skip messages are smushed together and convey no information about where they originated:
After, where we have one entry per skip and identify the origniating test file location:
// we start at 1 and end at (length - 1) because we don't want the surrounding quotes | ||
desc: captureDesc.node.text.substring(1, captureDesc.node.text.length - 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There has been a request to expose a node for string_contents
which is string
without the "
or '
quotes in the simple case, and for raw strings it would be without the raw string prefix/suffix, which is otherwise hard to account for.
What you have here won't work for raw strings, but i would not worry about that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for that heads up. Yeah, I would definitely be a customer for string_contents
if it gets added to the grammar. Agree that raw strings aren't super relevant here.
Co-authored-by: Davis Vaughan <davis@rstudio.com> Signed-off-by: Jennifer (Jenny) Bryan <jenny.f.bryan@gmail.com>
I'm now waiting for https://github.com/posit-dev/positron/actions/runs/8756403214 because I want to make sure the |
Intent
desc
in R test explorer #2639describe()
tests in the test explorer #2634test_that()
-like functions exported by packages other than testthat or internal helpers for a specific package.QA Notes
In a workspace that is an R package, click on the flask in the activity bar to activate the test explorer. If the package has testthat tests, the relevant test files will appear in a tree view, for navigation, execution, and display of test results.
I have put up a toy R package that can be used to exercise the bug fixes and features in this PR: https://github.com/jennybc/testfun. I would install this with
pak::pak("jennybc/testfun")
. Another good option isremotes::install_github("jennybc/testfun")
.More intelligent handling of quotes inside test desc in R test explorer #2639
Run the entire test suite or just the file▶️ button in the test explorer tree view or the ▶️ button in the gutter of test file to run a test item (file or test) or the double ▶️ button at the top of the explorer to run all tests.
test-banana.R
or just the individual test'subtraction `still` "works"'
. You can use theThe test
'subtraction `still` "works"'
(and any other tests that have vexing quotes in the description) should run and pass.Provide more support for describe() tests in the test explorer #2634
Use the test explorer to navigate to
test-mathstuff.R
and use the expando to reveal all the tests. Clear all test results from the menu accessed via the...
in the upper right corner of the TEST tree view. Here is the expected behaviour:describe("matrix()", { ... })
should work: it should run, there should be green checks for both of itsit()
s and for thedescribe()
itself. No other test items in this file should appear as being run; they should still have the grey circle.describe("addition()", { ... })
should work if you run it from the gutter. Adescribe()
with exactly 1it()
cannot be run from the explorer's treeview (VS Code tries to run just the childit()
) and I'm still analyzing whether this is our problem or a bug in VS Code. This is a known issue; see Account for nesteddescribe()
in R test explorer #2805.describe()
s and the enclosingdescribe("top-level describe with describe inside", { ... })
cannot be run individually and this is a known issue. For now, such a structure can only be run when the entire file is run. See Account for nesteddescribe()
in R test explorer #2805.Improved output for skipped tests #1808 (comment)
Run the single test file
test-apple-wtf.R
. The messages appearing in the TEST OUTPUT tab of the lower panel should appear one to a line and include the test file location where the skip originated.Good:
Bad: