Skip to content

Enable runnable examples - remove the last modules from the blacklist#5607

Merged
dlang-bot merged 7 commits intodlang:masterfrom
wilzbach:enable_runnable_examples
Oct 7, 2017
Merged

Enable runnable examples - remove the last modules from the blacklist#5607
dlang-bot merged 7 commits intodlang:masterfrom
wilzbach:enable_runnable_examples

Conversation

@wilzbach
Copy link
Contributor

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.

*/
@safe @nogc nothrow pure
package size_t roundUpToMultipleOf(size_t s, uint base)
size_t roundUpToMultipleOf(size_t s, uint base)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
``

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of this, but deleteme is the "defacto" standard within Phobos and used in many other public examples.


///
//
@safe unittest
Copy link
Contributor Author

@wilzbach wilzbach Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to private members is not possible with getSymbolsByUDA - the test only works it's in the same module.
Bug report

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving out the bad parts of the unit test rather than hiding the entire test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..)

@CyberShadow
Copy link
Member

@wilzbach wilzbach requested review from andralex, CyberShadow, ibuclaw, klickverbot, MartinNowak, schveiguy, and ZombineDev as code owners 2 hours ago

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.

@CyberShadow
Copy link
Member

The std.stdio changes are fine by me. I guess we never decided if we want to make testFilename or something like that public, which unfortunately means using an undocumented symbol in our documentation examples.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

*/
@safe @nogc nothrow pure
package size_t roundUpToMultipleOf(size_t s, uint base)
size_t roundUpToMultipleOf(size_t s, uint base)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

*/
@safe @nogc nothrow pure
package size_t roundUpToMultipleOf(size_t s, uint base)
size_t roundUpToMultipleOf(size_t s, uint base)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wilzbach
Copy link
Contributor Author

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.

I thought the same ... according to their docs:

Order is important; the last matching pattern takes the most precedence.

@wilzbach wilzbach force-pushed the enable_runnable_examples branch from bb4921f to 92e319f Compare July 13, 2017 00:14

// 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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to check this on a target that demanded it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why are you testing with both approxEqual() and equalsDigit(19)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equalsDigit is private, that's why I copied the test to a separate unittest and inserted approxEqual instead

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Auto-close Bugzilla Description
16984 Make more modules runnable on dlang.org

@wilzbach
Copy link
Contributor Author

The std.stdio changes are fine by me. I guess we never decided if we want to make testFilename or something like that public, which unfortunately means using an undocumented symbol in our documentation examples.

Well it's better than not having public tests or having public ones that aren't working for the tests.
Btw see also: #5400

So is anything blocking this then?


@CyberShadow we really have an issue with our CIs. Sometimes even everything is red, despite having "good" changes:

image

@CyberShadow
Copy link
Member

we really have an issue with our CIs

Yep.

Turns out continuous integration is hard. Who would have guessed? :)

@wilzbach wilzbach force-pushed the enable_runnable_examples branch from 92e319f to 6f48f83 Compare July 20, 2017 03:00
@wilzbach
Copy link
Contributor Author

wilzbach commented Jul 20, 2017

Turns out continuous integration is hard. Who would have guessed? :)

Okay I tried rebasing for this one - doesn't seem to work either:

image

At least before "auto-tester" was green, so how do we proceed here?

@wilzbach wilzbach force-pushed the enable_runnable_examples branch from 6f48f83 to 56e9e6d Compare September 14, 2017 00:05
@wilzbach
Copy link
Contributor Author

As the GH issues have been resolved, this should be finally good to go.
Ping @CyberShadow :)

}

///
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we undocumenting useful example blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, OK. So this was an "example" for a private symbol.


///
//
@safe unittest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving out the bad parts of the unit test rather than hiding the entire test.

@wilzbach wilzbach force-pushed the enable_runnable_examples branch from 56e9e6d to fce9f42 Compare October 5, 2017 19:36
@wilzbach
Copy link
Contributor Author

wilzbach commented Oct 5, 2017

Access to private members is not possible with getSymbolsByUDA - the test only works it's in the same module.
Bug report
I suggest moving out the bad parts of the unit test rather than hiding the entire test.

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

@wilzbach wilzbach force-pushed the enable_runnable_examples branch from fce9f42 to 41de215 Compare October 5, 2017 19:55
@wilzbach
Copy link
Contributor Author

wilzbach commented Oct 5, 2017

image

Looks like CircleCi is also finally green again :)

@wilzbach
Copy link
Contributor Author

wilzbach commented Oct 7, 2017

image

so?
Ping @CyberShadow @ZombineDev

Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from what I've commented on , everything looks good.


///
@safe unittest
@system unittest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why it worked with @safe before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite unfortunate. Thanks for the clarification.

a.setBounds(64, 128); // equivalent
assert(a.max == 128);
assert(a.min == 64);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor Author

@wilzbach wilzbach Oct 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(If you don't want to deal with this now, we can leave it for later.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

assert(a.approxMaxLength == 1024);
a.approxMaxLength = 1;
assert(a.approxMaxLength == 1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


///
//
@safe unittest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..)

@dlang-bot dlang-bot merged commit 42a1ee5 into dlang:master Oct 7, 2017
@wilzbach wilzbach deleted the enable_runnable_examples branch October 10, 2017 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants