Enable runnable examples - remove the last modules from the blacklist#5607
Enable runnable examples - remove the last modules from the blacklist#5607dlang-bot merged 7 commits intodlang:masterfrom
Conversation
std/experimental/allocator/common.d
Outdated
| */ | ||
| @safe @nogc nothrow pure | ||
| package size_t roundUpToMultipleOf(size_t s, uint base) | ||
| size_t roundUpToMultipleOf(size_t s, uint base) |
There was a problem hiding this comment.
This exposes roundUpToMultipleOf to the docs, it's used in many of the building blocks and the documented examples in quantizer needs it. An alternative would be to use a more simplistic Quantizer than:
alias MyAlloc = Quantizer!(
FreeTree!GCAllocator,
n => n.roundUpToMultipleOf(n <= 16_384 ? 64 : 4096));
``There was a problem hiding this comment.
I made it package-visible because it's in the wrong place. Once we expose it we'll need to do it forever. It should be shuttled to the right place. I'd say put it in std.numeric. Other possible candidates: std.conv, std.math.
There was a problem hiding this comment.
Also, it's much less generic than it could and should be because there wasn't a need. Once we expose it as a public primitive, the requirements change. It probably needs to accept any two unsigned types.
| static import std.file; | ||
|
|
||
| auto testFile = testFilename(); | ||
| auto testFile = std.file.deleteme(); |
There was a problem hiding this comment.
Not a huge fan of this, but deleteme is the "defacto" standard within Phobos and used in many other public examples.
|
|
||
| /// | ||
| // | ||
| @safe unittest |
There was a problem hiding this comment.
Access to private members is not possible with getSymbolsByUDA - the test only works it's in the same module.
Bug report
There was a problem hiding this comment.
I suggest moving out the bad parts of the unit test rather than hiding the entire test.
There was a problem hiding this comment.
I read the issue 17643 I agree with @CyberShadow that we should leave this in a private unittest, until we reach a consensus about whether access to private members should be allowed. (I think one should be able to get the attributes of private members at least in the same module, though that's not what this unittest tested..)
That is excessive. I hoped this feature would be a little smarter and disable itself when it would otherwise ping more than 3-5 people. |
|
The std.stdio changes are fine by me. I guess we never decided if we want to make |
andralex
left a comment
There was a problem hiding this comment.
We need to make sure published functions get due treatment. How about for now you just inline the rounding code in examples therefore making roundUpToMultipleTo unnecessary?
std/experimental/allocator/common.d
Outdated
| */ | ||
| @safe @nogc nothrow pure | ||
| package size_t roundUpToMultipleOf(size_t s, uint base) | ||
| size_t roundUpToMultipleOf(size_t s, uint base) |
There was a problem hiding this comment.
I made it package-visible because it's in the wrong place. Once we expose it we'll need to do it forever. It should be shuttled to the right place. I'd say put it in std.numeric. Other possible candidates: std.conv, std.math.
std/experimental/allocator/common.d
Outdated
| */ | ||
| @safe @nogc nothrow pure | ||
| package size_t roundUpToMultipleOf(size_t s, uint base) | ||
| size_t roundUpToMultipleOf(size_t s, uint base) |
There was a problem hiding this comment.
Also, it's much less generic than it could and should be because there wasn't a need. Once we expose it as a public primitive, the requirements change. It probably needs to accept any two unsigned types.
I thought the same ... according to their docs:
|
bb4921f to
92e319f
Compare
|
|
||
| // check if values are equal to 19 decimal digits of precision | ||
| assert(equalsDigit(mantissa * pow(2.0L, cast(real) exp), 123.456L, 19)); | ||
| assert(approxEqual(mantissa * pow(2.0L, cast(real) exp), 123.456L)); |
There was a problem hiding this comment.
I'd have to check this on a target that demanded it.
There was a problem hiding this comment.
You don't need to, I moved the test to an internal unittest. This change is just needed because approxEqual isn't a public symbol and would error when run online (or wherever the user tries to run the example).
There was a problem hiding this comment.
Yes, but does it pass on ARM? Or any other real==double target for that matter?
If equalsDigit and approxEqual are sufficiently the same, then there's no problem. :)
There was a problem hiding this comment.
If equalsDigit and approxEqual are sufficiently the same, then there's no problem. :)
approxEqual (used for the public examples) is much weaker, than equalsDigit. approxEqual checks by a difference of 1e-5 by default, whereas the equalsDigit tests here are by a precision of 1e-19.
| } | ||
|
|
||
| /// | ||
| @system unittest |
There was a problem hiding this comment.
Actually, why are you testing with both approxEqual() and equalsDigit(19)?
There was a problem hiding this comment.
equalsDigit is private, that's why I copied the test to a separate unittest and inserted approxEqual instead
Well it's better than not having public tests or having public ones that aren't working for the tests. So is anything blocking this then? @CyberShadow we really have an issue with our CIs. Sometimes even everything is red, despite having "good" changes: |
Yep. Turns out continuous integration is hard. Who would have guessed? :) |
92e319f to
6f48f83
Compare
6f48f83 to
56e9e6d
Compare
|
As the GH issues have been resolved, this should be finally good to go. |
| } | ||
|
|
||
| /// | ||
| // |
There was a problem hiding this comment.
Why are we undocumenting useful example blocks?
There was a problem hiding this comment.
Because hasRawAliasing is a private symbol -> https://github.com/dlang/phobos/blob/v2.076.0/std/traits.d#L2661
There was a problem hiding this comment.
Oh, OK. So this was an "example" for a private symbol.
|
|
||
| /// | ||
| // | ||
| @safe unittest |
There was a problem hiding this comment.
I suggest moving out the bad parts of the unit test rather than hiding the entire test.
56e9e6d to
fce9f42
Compare
Done - the other public unittest that I removed in std.traits was from a private symbol. Anything else or can be get this in before 2.077? Would be great because then we can finally enable "runnable examples" for all modules on dlang.org |
fce9f42 to
41de215
Compare
|
so? |
PetarKirov
left a comment
There was a problem hiding this comment.
Apart from what I've commented on , everything looks good.
|
|
||
| /// | ||
| @safe unittest | ||
| @system unittest |
There was a problem hiding this comment.
I wonder why it worked with @safe before?
There was a problem hiding this comment.
Because it was never executed, see the comment about unittest blocks in templates before. By moving the unittest to the module level, this unittest was executed for the first time...
There was a problem hiding this comment.
Quite unfortunate. Thanks for the clarification.
| a.setBounds(64, 128); // equivalent | ||
| assert(a.max == 128); | ||
| assert(a.min == 64); | ||
| } |
There was a problem hiding this comment.
What's the reason for moving the unit test to module level? Is it because the test extractor cannot handle unit tests for member functions? I don't like this change as now the example won't show immediately after the function, but on rather different place (especially with the ddox layout).
There was a problem hiding this comment.
A unittest in a template will be part of every instantiation, they shouldn't have been there in the first place.See DIP82 for a more detailed description of the problem.
Also note that the unittest will still be associated with its struct.
There was a problem hiding this comment.
This can be worked around via static if (doUnittest) (see e.g. https://github.com/libmir/mir-algorithm/blob/e590f7f46058588f1ceb08672c92bd6248863e18/source/mir/ndslice/slice.d#L737).
Essentially you need to make sure that doUnittest is true for a single set of template arguments and that you have a template instance with those arguments (e.g. used in a private unittest).
There was a problem hiding this comment.
(If you don't want to deal with this now, we can leave it for later.)
There was a problem hiding this comment.
This can be worked around via static if (doUnittest)
Considering that the test didn't compile until now (in case you didn't notice, the moved out version is different - it doesn't set the bounds twice as this is prohibited), I was merely trying to get things to work, s.t. we can finally move forward with the runnable examples ;-)
Regarding the static if (doUnittest): I am aware of this pattern (even the old std.experimental.ndslice used this), but AFAIK that has been the only occurrence of this pattern in Phobos.
Anyways, there are still plenty of unittests in templated structs/classes, so I would strongly prefer if such a general cleanup is done in a later PR...
| assert(a.approxMaxLength == 1024); | ||
| a.approxMaxLength = 1; | ||
| assert(a.approxMaxLength == 1); | ||
| } |
|
|
||
| /// | ||
| // | ||
| @safe unittest |
There was a problem hiding this comment.
I read the issue 17643 I agree with @CyberShadow that we should leave this in a private unittest, until we reach a consensus about whether access to private members should be allowed. (I think one should be able to get the attributes of private members at least in the same module, though that's not what this unittest tested..)




After quite a bit of work, we are heading for an end :)
This PR removes the last five modules from the runnable blacklist, s.t. with 2.076 all unittests are runnable
(FYI: the effort started in #4943)
For some modules, I wasn't sure sure on the best approach and I will mark these bits individually.