-
Notifications
You must be signed in to change notification settings - Fork 20
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
No tests to express expected failure for templates and other things #42
Comments
Below is an example corpus test for
|
Note the following quote by the tree-sitter creator:
Also, looking at the first comment in this, it seems possible that tweaks to one's grammar might change whether and where there might be If that is the case, then having too many corpus tests that indicate precise failure patterns might not be so great from a maintenance perspective... |
I don't think we should test for expected failures, I think we should just let them be failures. Like you point out, we can't really control how things fail. Changes to tree sitter versions and the grammar may change what the failures look like. To me, the important cases to test are what we expect tree sitter to parse correctly. That's all consumers of the parser care about, is that valid clojure produces a usable parse tree. Errors are expected to occur while the library is in use, and those errors are completely ignored most of the time. |
That sounds mostly good. I want to document that we don't necessarily support some things though, like the items mentioned earlier. If the testing could have been reliable, that would have been a bit more convenient. |
There is always the option of some more hand crafted tests. Like a script that parses a file with the grammar, and we assert that it returns a non-zero exit code, but also that it doesn't crash the parsers (like the null byte did). There is no reason it needs to go through the corpus testing. |
Good point. So perhaps the zero byte [1] thing is something we should have a test for too. Regarding the
(I'm posting multiple links though it's the same discussion because GitHub discussions tends to hide things -- not a helpful UI / UX sometimes.) I'm not sure whether we're supposed to be able to handle them... [1] At this point, from the perspective of widespread use, I'm not sure whether "nul" or "null" is an appropriate term. I started using "zero byte" at some point to avoid the whole topic, but apparently not as far back as the referenced discussion :) See here for some more on this if interested. |
I suspect Regardless of that one scenario, some simple tests like this might be worth throwing into a script. |
Ok, I'll update the initial post to include mention of zero bytes so there's a place we can look that fits on most normal screens :) |
I added some preliminary expected failure testing in 51ca143 (on the dev branch). There isn't anything yet for ClojureCLR's pipe-delimited symbols, but I did add something for a template file that leads to a parse error and something for a file with a zero byte in it. The tests can be invoked by Not crazy about the output but at least the testing occurs. On a related note, I experimented with using TAP in tree-sitter-janet-simple as mentioned at the bottom of #39 (comment) (see the link named "described here" if interested) [1]. Possibly it would be interesting to consider using TAP here too. [1] I'm avoiding putting the link here because then this issue will show up at the tree-sitter repository unnecessarily :P |
For the ClojureCLR pipe-delimited symbol testing, it's not necessarily that we get an error parsing, it's that the parsed result may be quite different from correct. Here is a comment that has an example along with the resulting parse output. Testing for that would be different from the other two things where there was checking for an exit code of 1 (possibly parsing the output to look for |
The failure tests work great so far. For the CLR test case, it's not a failure, but a strange parse tree that is technically does not produce errors. I can pass this into the JVM clojure repl
And it gives me a valid result. I don't think it should produce an error then. Since that is how the reference implementation behaves, perhaps this should just be described in a corups test?? Edit: here is a PR against dev. Feel free to press merge if you like it #48 |
Thanks for trying things out. I think that:
is supposed to be a single symbol. Interacting with
I think what's happening here is that:
The ClojureCLR docs here have this bit:
So the parsing doesn't seem correct to me. I suspect if this is to be handled that doing it via an external scanner might be worth considering. I'm not yet convinced effort should be spent on it at this stage though. [1] I tried the following too:
so that seems to be evidence in favor of |
In JVM clojure it is definitely more than one symbol, and it is possible to parse those symbols without errors (executing is another matter). It seems that in clojure CLR it is a single symbol. We can't support both because while scanning we don't know what platform the code is intended to run on. Maybe it's CLR, maybe JVM, maybe it's both, but we don't have that info while parsing. I think in this case we support the more common platform. Errors are not produced when parsing, so the only downside I can see is for CLR clojure they might get some funny syntax highlighting on these types of symbols. Since the CLR implementation has a different reader, then I think this would be the case for a special grammar that inherits this grammar as a parent and adds custom rules for these symbols. I doubt anyone will think this is enough of a problem to actually write the new grammar. It would be a lot of hassle to use just for the CLR. Based on how clojure CLR is used, it would be difficult to know when to use a CLR grammar since a lot of the code uses the normal |
@dmiller might have thoughts here. I know he's currently in the process of rewriting the ClojureCLR in F#, maybe he'd be willing to shed some insights on this stuff for us. If the cljr community can move to relying on a different filetype, we could help fork this for them. Otherwise, I agree we're at an impasse. |
Yeah, it's would be an involved process. Not only would we need a sub-grammar based on this one, editors would also need some support to use it. It would result in a special Unrelated: It is very cool to see ClojureCLR getting rewritten in F#. |
I'm not sure of all the questions being asked, but here goes from what I can figure out. Regarding |System.Collections.Generic.IList`1[System.Int32]| -- this unfortunately is the actual CLR name for the type. How JVM handles it -- well, you can see it is weird. Does this help? |
_It is good to know that this syntax is probably not going away. One question that I think would be good to know: will clojure CLR be moving to a new file extension If the plan is to stick with .clj that is fine, the only consequence is that type names like |System.Collections.Generic.IList`1[System.Int32]| might have some strange syntax highlighting in certain editors. |
The plan is to move to a new extension .cljr. |
In c86581f [1] I've added a babashka task to demonstrate an expected misparse.
[1] This is on a temporary branch where I'm working on various babashka tasks. |
Most (if not all) of the testing for these bits will be living in a separate repository, so I'll close this issue for now. Thanks to all the participants! |
There was a query about how expected failures might be tested for at the tree-sitter repository.
It got me thinking that we might be able to capture and express some of our intents about what we don't support.
Some possible examples of such things might include:
{{
and}}
pairsClojureDart's new(?)[1]#/
constructAdditions based on further discussion:
[1] I think we now know what construct this is and ATM it seems reasonable to try to support it.
The text was updated successfully, but these errors were encountered: