-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: pending tests, single/double quotes, logger #38
base: master
Are you sure you want to change the base?
Conversation
|
||
if ok then | ||
file:write(result) | ||
file:close() | ||
else | ||
io_write("Failed to encode test results to json: " .. result .. "\n") | ||
io_flush() | ||
os.exit(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.
Why is this necessary? Is it because the process cannot continue in a sane way if json encoding failed?
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.
Yes, that and also busted is often run as a separate process wrapped in status, error = pcall(..)
for example. Setting the exit code, allows to assert the error. Neotest also runs the tree with the spec that your adapter provides wrapped in xpcall
and asserts the exit status.
I have actually updated the busted json formatter here https://github.com/lunarmodules/busted/pull/748/files
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.
I see but couldn't you assert on the error if you returned false
as the second return value? Or called error
? I don’t believe os.exit
is necessary for pcall
/xpcall
to register an error.
Nice that you contributed to busted (and that it seems maintained). We can wait and see what the outcome of that PR is since it would probably be a good idea to align with what busted’s builtin handlers do.
;; pending blocks | ||
((function_call | ||
name: (identifier) @func_name | ||
arguments: (arguments (_) @test.name (function_definition)) | ||
) (#match? @func_name "^pending$")) @test.definition | ||
|
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.
I’ve had a chance to play around with this query and there are a few corner cases.
- In the example you gave here Help with busted, local-lua config 🙏 #17 (comment), the call to
pending
in the first test should not be matched, only theit
test itself should. I think it needs match calls topending
whose parent is adescribe
. Runningbusted —list <spec>
on the file shows what busted considers a test. - The query won’t match calls to
pending
without a second function argument.
I’ve got some working queries locally for these cases and I’ll continue to test it out a bit to make sure I haven’t missed something.
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.
Totally agree. That was a quick copy/paste from it block.
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.
Fair enough, I figured it was. Here’s what I got so far. Haven’t found a better way yet to encode the parent-child relationship.
;; pending blocks constrained to have a describe as a parent
((function_call
name: (identifier) @func_name1 (#match? @func_name1 "^describe$")
arguments: (arguments
(_) @namespace.name
(function_definition
parameters: (parameters)
body: (block
((function_call
name: (identifier) @func_name2
arguments: (arguments (_) @test.name (function_definition)?)
) (#match? @func_name2 "^pending$")
) @test.definition
)
)
)
)) @namespace.definition
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.
I am afraid this does not work properly with Neotest summary panel.
it('this test does not run..)
should not come up in the panel, as it is inside the pending block'
I would also argue, that top level pending
should be parsed as it does come up with busted --list
and it is quite convenient to mark a whole buch of tests to pending by just renaming describe to pending.
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.
;; pending blocks
((function_call
name: (identifier) @func_name
arguments: (arguments (string) @test.name)
) (#match? @func_name "^pending$")) @test.definition
this fixes it.
I would not bother trying to encode the nested cases:
- in the case
pending..it
- all nestedit
are skipped anyway - in the case of
it..pending
, busted correctly marks the parentit
as pending
This is just to show the changes I have made locally. Still investigating the json encoding of non-string objects.