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

Remove all util functions from test files #1824

Closed
senekor opened this issue Dec 14, 2023 · 6 comments
Closed

Remove all util functions from test files #1824

senekor opened this issue Dec 14, 2023 · 6 comments

Comments

@senekor
Copy link
Contributor

senekor commented Dec 14, 2023

Some test files include some common code in the form of a funtion. Individual tests then call that function. This is a good instinct to do in normal code: reduce duplication (DRY). But our test runner should at some point (hopefully soon) gain the ability to extract the code of a test to show it to students when a test fails. In that case, it is very bad to call a separate function in the test body. Every test function should contain all of the logic required to understand what it's doing.

Here's an example of such a util function.

Since we're now using a test generator anyway, we don't need to worry about having to keep all this copied logic in sync manually.

Make sure to update the documentation where these util funtions are encouraged.

@senekor
Copy link
Contributor Author

senekor commented Dec 15, 2023

Apart from util functions, declarative macros should not be used either for the same reason.

@senekor
Copy link
Contributor Author

senekor commented Dec 16, 2023

On second thoughts, macros might be fine. If we're going to get the source code of the tests by AST, macros should already be resolved by that point.

And using tera templates for exercises which don't come from problem-specifications might be inconvenient. Macros can still be a good option in that case.

@senekor
Copy link
Contributor Author

senekor commented Dec 17, 2023

Might also be a good idea to document this in CONTRIBUTING.md, since it's not really possible to write a test against this.

@senekor
Copy link
Contributor Author

senekor commented Apr 2, 2024

For reference, here is an earlier discussion about using table-driven tests for this track. (its conclusion: table-driven bad, macros good)

@senekor
Copy link
Contributor Author

senekor commented Aug 13, 2024

On second thoughts, macros might be fine. If we're going to get the source code of the tests by AST, macros should already be resolved by that point.

This is incorrect, AST parsing with syn does not resolve macro invocations. There are only five exercises with macro definitions in test files left, we should just get rid of them.

senekor added a commit that referenced this issue Aug 14, 2024
senekor added a commit that referenced this issue Aug 14, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 14, 2024
@senekor senekor mentioned this issue Aug 14, 2024
senekor added a commit that referenced this issue Aug 14, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 14, 2024
senekor added a commit that referenced this issue Aug 14, 2024
[no important files changed]

part of #1824

This is simply a manual expansion of the macros. There is no canonical
data from problem specifications, so the tests won't change often and
the maintenance burden of the duplication should be acceptable.
senekor added a commit that referenced this issue Aug 14, 2024
senekor added a commit that referenced this issue Aug 14, 2024
senekor added a commit that referenced this issue Aug 15, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 15, 2024
senekor added a commit that referenced this issue Aug 15, 2024
senekor added a commit that referenced this issue Aug 15, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 15, 2024
senekor added a commit that referenced this issue Aug 15, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824

The small util function for constructing a `DateTime` value was left as
is because it's only noise and not necessary to understand what's going
on in the test case.
senekor added a commit that referenced this issue Aug 16, 2024
@senekor senekor mentioned this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
@senekor senekor mentioned this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
@senekor senekor mentioned this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
part of #1824

This is by no means perfect, but I attempted to make the test functions
a little more concise and readable. This is desirable when the test code
is shown to users online, while it wasn't a requirement when these tests
were generated by macros.
senekor added a commit that referenced this issue Aug 16, 2024
part of #1824

This is another case where I think it makes sense to actually keep the util
function around. It produces a good error message and in combination with the
body of the test function, users should have enough information.
senekor added a commit that referenced this issue Aug 16, 2024
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824

This is by no means perfect, but I attempted to make the test functions
a little more concise and readable. This is desirable when the test code
is shown to users online, while it wasn't a requirement when these tests
were generated by macros.
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824

This is another case where I think it makes sense to actually keep the
util function around. It produces a good error message and in
combination with the body of the test function, users should have enough
information.

As the comment in the diff already states, the removed tests are
redundant because the type system prevents such errors anyway.
senekor added a commit that referenced this issue Aug 16, 2024
[no important files changed]

part of #1824
@senekor
Copy link
Contributor Author

senekor commented Aug 16, 2024

There are still a few of these around. Not every piece of testing code has been moved into a test function body. But I think for the remaining occurrences, it makes sense and the test functions are still understandable on their own.

@senekor senekor closed this as completed Aug 16, 2024
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

No branches or pull requests

1 participant