Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.

Stringify errors before processing #124

Merged
merged 8 commits into from
Oct 2, 2020

Conversation

MagiMaster
Copy link
Collaborator

Since Luau allows non-string errors (e.g. error({})), TestEZ needs to handle those. At the moment, it will try and concatenate the error with the rest of the message, which will fail, which will cause it to not output a stack trace. This calls tostring on any errors before further processing.

Closes #122

@MagiMaster
Copy link
Collaborator Author

Unfortunately, I haven't worked out a great way to test this change yet. The existing tests mostly check that things pass or fail as expected, but this will fail either way. The actual change is to what's collected in the failure, and I need to think on a non-brittle way to verify that there's a stack trace there.

@LucySweetWork
Copy link

Since debug.traceback is subject to change at any time you might not be able to test a stack trace since you can't guarantee the form. You could always set up an object with an __tostring method that returns a certain string and then make sure the error contains that string at least somewhere inside it?

@MagiMaster MagiMaster requested a review from benbrimeyer October 2, 2020 19:16
@@ -8,6 +8,9 @@
* Limitations:
* `expect.extend` cannot be called from within `describe` blocks
* Custom matcher names cannot overwrite pre-existing matchers, including default matchers and matchers introduces from previous `expect.extend` calls.
* Change the way errors are collected to call tostring on them before further processing.
* Luau allows non-string errors, but not concatenating non-strings or passing non-strings to `debug.traceback` as a message, so TestRunner needs to do that step. This is a temporary fix as the better solution would be to retain the error in object form for as long as possible to give the reporter more to work with.
* This also makes a slight change to what's in the traceback to eliminate the unnecessary line mentioning the error collection function.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

@@ -196,7 +196,9 @@ function TestNode:expand()
end
setfenv(self.callback, callbackEnv)

local success, result = xpcall(self.callback, debug.traceback)
local success, result = xpcall(self.callback, function(message)
return debug.traceback(tostring(message), 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Might be good to later move this debug.traceback snippet into its own modules for the sake of making sure we keep it DRY, esp since we're passing in "magic" scope

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's probably several such utility functions that could be pulled out.

Copy link
Collaborator

@benbrimeyer benbrimeyer left a comment

Choose a reason for hiding this comment

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

Feel free to merge!

@MagiMaster MagiMaster merged commit 470e3da into Roblox:master Oct 2, 2020
@MagiMaster MagiMaster deleted the object-errors branch October 2, 2020 20:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Erroring with an object during a testez test creates an error in error handling
3 participants