-
Notifications
You must be signed in to change notification settings - Fork 141
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
initial rework of syntest to be usable internally #185
base: master
Are you sure you want to change the base?
Conversation
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.
Just some architectural requests to make it fit better as a public API.
Let me know if you made any real changes to the main body of the function you moved, I didn't read it, assuming it's just a copy-paste.
examples/syntest.rs
Outdated
use syntect::highlighting::ScopeSelectors; | ||
use syntect::easy::{ScopeRegionIterator}; | ||
use syntect::parsing::{SyntaxSet}; | ||
use syntect::easy::{SyntaxTestFileResult, SyntaxTestOutputOptions, process_syntax_test_assertions}; |
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 this should go in the easy
module.
That's for simple wrappers for common use cases. Syntax tests are neither a wrapper around a more advanced API, nor a common use case.
They should probably go in their own syntax_tests
module or something
src/easy.rs
Outdated
Success(usize), | ||
} | ||
|
||
pub fn process_syntax_test_assertions(syntax: &SyntaxDefinition, text: &str, testtoken_start: &str, testtoken_end: Option<&str>, out_opts: &SyntaxTestOutputOptions) -> SyntaxTestFileResult { |
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.
If this is now going to be a public API, could you add a doc comment with short descriptions of what the parameters do? Also useful for our own reference.
src/easy.rs
Outdated
@@ -174,6 +174,236 @@ impl<'a> Iterator for ScopeRegionIterator<'a> { | |||
} | |||
} | |||
|
|||
#[derive(Clone, Copy)] | |||
pub struct SyntaxTestOutputOptions { |
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.
Now that this is an API, it seems a bit weird for it to just print things to stdout.
Maybe you could add a lifetime parameter to this struct and add a output: &'a io::Write
member. Alternatively you could add an extra parameter for the output to the process function.
Then the function then uses writeln!
instead of println!
to write to, and the process function would probably need to return an io::Result
. Then syntest
and possibly also unit tests could just pass stdout.
I have moved it to a new |
Nice, thanks for picking this up :)! In the current form, I don't think we should make it a public API. An API with the only output being some printed text doesn't seem very useful generally. So I would do either one of these two things:
(With the latter, we could do some nice things such as formatting as HTML so you can more easily see the actual scopes, show the results in a text editor instead, etc.) |
Printed text isn't the only output - the API returns the successful/failed assertion count too ;) I would guess that changing the API to return structs with the information about the assertions, and printing them from the |
Hehe :). Is it possible to make it return an |
I think that returning an iterator with the results is a cool idea, it would allow a consumer of the API to fail fast when a failure occurs, if so desired. Though I guess it would likely prevent the use cases we mentioned above, whereby the (optionally colored) output could be combined with the syntax test results, as it would only iterate over those results and then the file would have to be parsed again to achieve an integrated view, which isn't ideal. Marking the API for internal use only would solve needing to make further complicated changes at the moment. But changing the method to |
Okay I'll try and give the new implementation a real review then, likely this weekend. If you'd like I can probably also do the @robinst I agree it's not the greatest thing to have as a public API but:
|
this will allow other functionality to be developed that can use the same syntax test implementation and show the test results in a more friendly manner etc.
Sorry I'm so late on reviewing this, I wanted to use my limited syntect bandwidth for stuff that needed to be in the 3.0 release. This is still on my TODO list. |
No worries, the work you did on the color schemes was awesome and indeed more important ;) |
@keith-hall Is this PR something we still want to try to get in? In general I think it is undesired to add public API only for the purpose of testing, because each increase in API surface makes all subsequent bugfixes and features more complicated to do due to the mere fact that there are more things to take into account, so in general a minimal API surface is desirable. Couldn't we simply keep the tests as mod tests that have access to internal interfaces? I apologize in advance for any ignorance on my part. |
although not mentioned in the original post, the idea behind moving the code from an example to be part of the public API is because running syntax tests isn't just useful for testing |
Thanks for the clarification, that makes sense. I will try to find the time to help review this in a not too distant future. |
this is an initial rework of the
syntest
example, to make it usable internally, as it would be useful for parser tests (see #180 (comment)). I think it will need some more work to properly support assertions that extend over the end of the line (#175) and spill over onto not only the next line, but also the line afterwards etc. although such a scenario may never come up in real life use.