How to do grammar rule coverage? #193
Replies: 20 comments
-
The heavily templated nature of the PEGTL in general, and the way that parsing rules are defined in particular, indeed render gcov hard to use, or even pretty useless. We don't really have a ready solution, our usual approach can best be described as "write a lot of testcases while you still remember everything about the grammar", and that works well if you are thorough. If I were to try and build some kind of grammar-rule-coverage I would probably start with the tracer in Generating a list of all (sub-)rules of a grammar might be possible using the |
Beta Was this translation helpful? Give feedback.
-
Thank you for this quick response! Yes, your first paragraph is also my usual approach :-) |
Beta Was this translation helpful? Give feedback.
-
Let us know how it goes, would be interesting to see what you manage to put together, you won't be the only person wanting a rule coverage test! |
Beta Was this translation helpful? Give feedback.
-
@michael-brade Did you manage to get something up-and-running? Do you need any help? |
Beta Was this translation helpful? Give feedback.
-
thanks for asking, but no, I did not get the time to do so yet... crazy current situation! I did not forget, though. |
Beta Was this translation helpful? Give feedback.
-
Right, sorry, I forgot the most important thing: Stay healthy! |
Beta Was this translation helpful? Give feedback.
-
😆 no problem, I'm not worried about the virus at all. It's what they make out of it that is the problem.... |
Beta Was this translation helpful? Give feedback.
-
The new |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
I had a look at it yesterday and I am impressed! :-) So little code for so much functionality. The day just didn't have enough hours for me to test it on my project. Thanks for your quick solution, I hope I'll get to it today. |
Beta Was this translation helpful? Give feedback.
-
We have further improved and refined the implementation, most importantly making it fully compatible with custom controls, actions and states. I will close this issue for now, but please feel free to ask any further questions, or reopen the issue, if something does not work for you. And thank you for asking about rule coverage; we hadn't planned this refactoring, but it was a good opportunity and we like the result :-) |
Beta Was this translation helpful? Give feedback.
-
Wow, really great work! And again, it took longer than expected -- I'm not even done yet, partly because I had to migrate to 3.0 first :-D But I do already have a little bit of feedback. Let me suggest to expand the migration guide for 3.0.0:
parse_tree:
The When I'm done with all of it, I'll let you know about the coverage part. |
Beta Was this translation helpful? Give feedback.
-
Thanks! I implemented almost all of those suggestions, only the tracer part is still missing as Colin and me are going to work on that a little bit more. |
Beta Was this translation helpful? Give feedback.
-
Very nice again! I have now gotten the coverage to work. It looks good with exactly the required information! One question/suggestion: my unit tests consist of many different calls to So what about a new function like
to merge individual coverage result objects? |
Beta Was this translation helpful? Give feedback.
-
And another issue: |
Beta Was this translation helpful? Give feedback.
-
So you are trying to get coverage information for a parsing run that failed with an exception, and the exception was produced by what, an action rather than a rule? PS: We are working on the merge. |
Beta Was this translation helpful? Give feedback.
-
We reduced the |
Beta Was this translation helpful? Give feedback.
-
Yes, exactly.
good question, I don't know yet :-) Will check after I updated to your new code. |
Beta Was this translation helpful? Give feedback.
-
I'm assuming everything is working for now, otherwise, as usual, feel free to come back here with any question and/or reopen this issue. |
Beta Was this translation helpful? Give feedback.
-
Yes, I will. Again, I am behind with a TODO list that is too long. I will get back to this probably next week. |
Beta Was this translation helpful? Give feedback.
-
Hi, when I write a large grammar I usually also try to write unit tests that cover all the grammar rules. However, it is not so easy to find out if actually all the possibilities are tested. Since PEGTL rules are basically just C++ type declarations, gcov doesn't show them at all.
Do you have any methods or tricks of how to find out about how many rules a parser run covered?
Beta Was this translation helpful? Give feedback.
All reactions