-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
std.getopt: Add unit tests for delegates as callbacks. #5347
std.getopt: Add unit tests for delegates as callbacks. #5347
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.
I like the idea of testing everything. But why is this unittest @system? As far as I can tell, there's nothing here that's un-@safe.
| @@ -1773,3 +1773,37 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt) | |||
| getopt(args, "f|flag", "Boolean", &flag); | |||
| assert(flag); | |||
| } | |||
|
|
|||
| @system unittest // Delegates as callbacks | |||
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.
Why @system?
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 tried @safe initially, but it fails. Probably why most of the other unit tests are @system. The error with @safe:
std/getopt.d(1799): Error: @safe function 'std.getopt.__unittestL1777_33' cannot call @system function 'std.getopt.getopt!(string, string, void delegate() pure nothrow @nogc @safe, string, string, void delegate(string option) pure nothrow @nogc @safe, string, string, void delegate(string option, string value), string, string, void delegate() pure nothrow @nogc @safe, string, string, void delegate(string option) pure nothrow @nogc @safe, string, string, void delegate(string option, string value)).getopt'
I should have mentioned in the initial description - One rationale for adding delegates to unit tests is that delegates and functions have separate tests in the getopt code. Doesn't show up in code coverage reports because the tests are on the same code line.
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'm not disagreeing that we need to add these unittests... but I think it's worth investigating where exactly it fails to be @safe. It might be a bug in the implementation of getopt.
|
Aha! I found the problem. Well, two problems, actually, both are easily fixable:
Fix these two, and we're good to go! |
|
Okay thanks! Would be good to make these all I tried to find some history on this. Didn't find anything in issues, but the original PR that added As to this PR - Personally I'd prefer to separate adding these unit tests from making std.getopt Let me know how you'd like it done. If you want them both in the same PR it might be a day or so before I get back to it, but there's nothing time critical here. |
|
The |
|
Let's keep it simple. If you don't feel like putting the |
|
Isn't it a phobos requirement that all unittest blocks be annotated with |
|
Fine, then, let's merge this and fix the |
|
Very good, thanks for thoughtful review. |
At present there are no unit tests in std.getopt where delegates are used as callbacks. This adds a few basic tests.