-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Write unit tests for parser #8
Comments
It would be good to coordinate with @seantalts about the amount of unit testing this will require and for which components. The old system never really unit tested the generator in any significant way and the AST tests were huge but trivial. Mostly it was testing end-to-end results on parsing grammar fragments to make sure they either parsed (at all, usually not with generated code checks) or generated the correct error messages. |
Yes. If you guys have thoughts on what precisely should be unit tested, I would love to know. I am currently planning to add some expect tests to make sure that:
What I really don't know is what unit tests to write for the parser. I feel like the semantic check is tested pretty well by the end-to-end tests. The parser, I am less sure about, until we start generating code and testing that. The AST does not need any tests, I would think. |
I'm not sure that's a useful test for the type checker - is that an invariant we care about? I think the way to think about these more granular tests is that anywhere where a function is doing something pretty tricksy or unobvious, you can add a test that demonstrates its behavior in that circumstance. For me, this often occurs while writing the functions because I actually need to test what I'm writing as I'm writing it. Then, you can just leave the test in. |
I think it is an invariant we care about. The semantic check should not change the AST. (Otherwise something is quite clearly wrong.) It should only decorate it or maybe throw. I agree it's a pretty low bar and by no means shows correctness, but it's a good sanity check.
Thought about that way, I think the only part of the parser that was tricky to get right was the precedence of the operators and the dangling else clauses. So should I write expect tests for those? For semantic checking, I think the integrations tests have good coverage. Whenever there was something tricky, I've added test models if there weren't any yet. Does anything else come to mind? |
I think this would be an interesting use case to try out Jane Street's quickcheck testing library, since you basically just need to fuzz input and check a simple invariant.
That sounds good. I can then add some more for anything else I find confusing once the testable hooks are there (e.g. additional I think you're generally right about our end-to-end test coverage being good. I am just thinking about these more granular tests as being documentation that is automatically tested to be up-to-date. So in addition to testing anything that was very tricky, you could add tests to illustrate examples and help explain the code. |
Thanks, @seantalts ! Will do. |
I tested that the pretty printer is a one-sided inverse to the parser. Moreover, the integration tests are tracking changes to the expected pretty printed code. This expected output is now probably correct. Also, I just added unit tests for the parser to check that it does operator precedence correctly. |
@seantalts , I've added a bunch of unit tests for the parser. Could you have a look if they suffice? On a different note, both @bob-carpenter and I felt like it might be cleaner to move the unit tests to their own file. |
Sure thing! I think you forgot to open a PR though. Could you do that and I'll comment on it? |
Also I think that sounds reasonable to have most unit tests in their own file. I also think it's worth having very short expect (and maybe quickcheck) inline to serve as documentation. |
Will open a PR moving the unit tests to their own files once my current PR is moved. (Would like to avoid merge conflicts.) |
I'm not sure if this solves the merge conflicts thing, but with git you can also base a branch off an existing branch: |
Thanks! |
This seems like an interesting test tool: https://github.com/mirage/alcotest |
We currently have a lot of integration tests, but unit tests are missing.
The text was updated successfully, but these errors were encountered: