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

Add tests for some MorphirRuntimeErrors #662

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

alexsieland
Copy link
Contributor

@alexsieland alexsieland commented Aug 12, 2024

Adds logic to the EvaluatorMDMTests that allows for testing situation where we expect exceptions to get thrown. Also adds some simplified testing to test specific exceptions getting thrown.

An added benefit of this setup is that tests for unhappy path testing should be easier to write going forward (when they expect exceptions to get thrown)

case e => assertNever(s"Expected FailedCoercion but $e was thrown")
},
testExceptionMultiple("UnknownTypeMismatch Test")("exceptionTests", "decimalHundred", List(Data.String("a"))) {
case TopLevelError(_, _, _: TypeError.UnknownTypeMismatch) => assertTrue(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should expect these tests to fail as we improve error messages - the wrapping structure with TopLevelError is messy and should change. (This isn't something that needs to be fixed in this PR, but we should be aware of this brittleness).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two things that are a must change in my opinion is the TopLevelError and any private exceptions like "CodeLocatedError".

And yes, I realize these tests will need to change. The implementation choice should make it relatively easy to revise and add to as the error handling changes though, which is the goal in my mind.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed on both counts - I want the functionality of TopLevel and CodeLocated, but yeah, they should not appear in the type hierarchy.

},
testExceptionMultiple("UnknownTypeMismatch Test")("exceptionTests", "decimalHundred", List(Data.String("a"))) {
case TopLevelError(_, _, _: TypeError.UnknownTypeMismatch) => assertTrue(true)
case TopLevelError(_, _, inner) => assertNever(s"Expected UnsupportedType but $inner was thrown")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these "Expected" look wrong - shouldn't this be UnknownTypeMismatch not UnsupportedTypeMismatch? Given the brittleness I would not specify the expectation at all ("Unexpected exception type thrown")

Copy link
Contributor Author

@alexsieland alexsieland Aug 13, 2024

Choose a reason for hiding this comment

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

That was likely from a copy paste. And on making it generic, fair point, will update.

@@ -3448,6 +3469,57 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
)
)
)
),
suite("Morphir Runtime Exception Tests")(
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these all the errors you were able to replicate, or is this just a first pass to get the unhappy path machinery set up before flushing out additional errors? (I can help you get a few more runtime errors if that would be helpful, or that can be follow up work)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I was able to replicate. There are quite a few exceptions that I feel should be getting thrown but end up throwing a different error, like UnknownTypeMismatch when I would think ArgNumberMismatch would be thrown. If you have consistent ways of replicating other ones, then I'd love to get them added.

That said, I think adding additional exceptions can be added in separate PRs as needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

One trick you can use is to abuse the type checker:

cast : a -> b
cast x = x

Morphir-elm (tho not elm) will compile that; you can use it to generate a lot of the other errors. Incomplete pattern matches should be similar (elm will reject but morphir-elm will not). We can talk about other tricks to sneak things past the compiler if that's helpful. You're also completely right, some of these throw other errors than we'd like... a lot of that depends on how the specific error is encountered.

Let's schedule some time to chat soon, I've got a lot of thoughts on these in general.

Copy link
Contributor

@edwardpeters edwardpeters left a comment

Choose a reason for hiding this comment

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

Made a few optional suggestions, but the only blocking problem I see is that the failing asserts look like they refer to the wrong expectations.

Copy link
Contributor

@michelchan michelchan left a comment

Choose a reason for hiding this comment

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

Approving because I think this is a good first pass at writing Exception tests. I think it'd be good to do several iterations on this so that we can get what we really expect vs what the codebase is giving us. Good work

@michelchan michelchan merged commit 5921d75 into finos:main Aug 13, 2024
14 of 15 checks passed
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