-
Notifications
You must be signed in to change notification settings - Fork 219
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
chore(traits): added exhaustive test for trait function calls #2918
chore(traits): added exhaustive test for trait function calls #2918
Conversation
This test proves that trait function calls from inside the body of other trait functions are resolved and executed correctly.
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 don't think it's very practical to try testing every combination of something. Especially when adding a new dimension of something to test ends up increasing our test cases 4x. Instead of trying to test every single case, lets narrow it down to a select few that are more likely to cause issues for the compiler and aren't already tested by other integration tests.
tooling/nargo_cli/tests/execution_success/trait_function_calls/src/main.nr
Show resolved
Hide resolved
I know it's not always practical to test every combination of something, unless the number of test conditions is small, yielding a small number of combinations. In this case, we have 3 * 3 = 9 cases, that will be extended to 2 * 2 * 3 * 3 = 27 cases, once function calls via Self:: (a.k.a. static methods) are implemented. This is a very practical number of cases for an automated test and I'm not planning to increase the test conditions for this test any further, because it serves a very specific purpose - it tests whether function call resolution is done correctly with regards to choosing between trait default and trait impl ("override") implementation. This is also a feature that is specific to traits and is different, compared to e.g. struct impl function calls, where there's no such thing as default and override implementations (and combinations). We're not planning to adding any more dimensions to the test, that are unrelated to that (for example, once traits for non-struct types are implemented, we're not going to add every non-struct type as a new dimension to this test, but we'll definitely add a new test that just implements a trait for each type - that's because implementing traits for non-struct types is something that is completely independent from trait function call resolution). |
This test proves that trait function calls from inside the body of other trait functions are resolved and executed correctly. All combinations of:
default implementation
override with default
override with no default
are tested, for both the caller and callee. For now, this tests method calls only (functions with self as first parameter). Once function calls via
Self::function_name()
are implemented, the test can be extended to cover that as well.