-
-
Notifications
You must be signed in to change notification settings - Fork 749
Enable runnable examples - remove the last modules from the blacklist #5607
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
Changes from all commits
2e96d06
c2d03bf
3cc6300
ff6c0f1
5a20f69
d661120
41de215
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,8 +114,7 @@ struct FreeList(ParentAllocator, | |
| _max = high; | ||
| } | ||
|
|
||
| /// | ||
| @safe unittest | ||
| @system unittest | ||
| { | ||
| import std.experimental.allocator.common : chooseAtRuntime; | ||
| import std.experimental.allocator.mallocator : Mallocator; | ||
|
|
@@ -895,42 +894,13 @@ struct SharedFreeList(ParentAllocator, | |
| @property void max(size_t newMaxSize); | ||
| /// Ditto | ||
| void setBounds(size_t newMin, size_t newMax); | ||
| /// | ||
| @safe unittest | ||
| { | ||
| import std.experimental.allocator.common : chooseAtRuntime; | ||
| import std.experimental.allocator.mallocator : Mallocator; | ||
|
|
||
| shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a; | ||
| // Set the maxSize first so setting the minSize doesn't throw | ||
| a.max = 128; | ||
| a.min = 64; | ||
| a.setBounds(64, 128); // equivalent | ||
| assert(a.max == 128); | ||
| assert(a.min == 64); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be worked around via
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 ;-)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough |
||
|
|
||
| /** | ||
| Properties for getting (and possibly setting) the approximate maximum length of a shared freelist. | ||
| */ | ||
| @property size_t approxMaxLength() const shared; | ||
| /// ditto | ||
| @property void approxMaxLength(size_t x) shared; | ||
| /// | ||
| @safe unittest | ||
| { | ||
| import std.experimental.allocator.common : chooseAtRuntime; | ||
| import std.experimental.allocator.mallocator : Mallocator; | ||
|
|
||
| shared SharedFreeList!(Mallocator, 50, 50, chooseAtRuntime) a; | ||
| // Set the maxSize first so setting the minSize doesn't throw | ||
| a.approxMaxLength = 128; | ||
| assert(a.approxMaxLength == 128); | ||
| a.approxMaxLength = 1024; | ||
| assert(a.approxMaxLength == 1024); | ||
| a.approxMaxLength = 1; | ||
| assert(a.approxMaxLength == 1); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1071,6 +1041,34 @@ struct SharedFreeList(ParentAllocator, | |
| } | ||
| } | ||
|
|
||
| /// | ||
| @safe unittest | ||
| { | ||
| import std.experimental.allocator.common : chooseAtRuntime; | ||
| import std.experimental.allocator.mallocator : Mallocator; | ||
|
|
||
| shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a; | ||
| a.setBounds(64, 128); | ||
| assert(a.max == 128); | ||
| assert(a.min == 64); | ||
| } | ||
|
|
||
| /// | ||
| @safe unittest | ||
| { | ||
| import std.experimental.allocator.common : chooseAtRuntime; | ||
| import std.experimental.allocator.mallocator : Mallocator; | ||
|
|
||
| shared SharedFreeList!(Mallocator, 50, 50, chooseAtRuntime) a; | ||
| // Set the maxSize first so setting the minSize doesn't throw | ||
| a.approxMaxLength = 128; | ||
| assert(a.approxMaxLength == 128); | ||
| a.approxMaxLength = 1024; | ||
| assert(a.approxMaxLength == 1024); | ||
| a.approxMaxLength = 1; | ||
| assert(a.approxMaxLength == 1); | ||
| } | ||
|
|
||
| @system unittest | ||
| { | ||
| import core.thread : ThreadGroup; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2771,8 +2771,7 @@ if (isFloatingPoint!T) | |
| int exp; | ||
| real mantissa = frexp(123.456L, exp); | ||
|
|
||
| // 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)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd have to check this on a target that demanded it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| assert(frexp(-real.nan, exp) && exp == int.min); | ||
| assert(frexp(real.nan, exp) && exp == int.min); | ||
|
|
@@ -2782,6 +2781,15 @@ if (isFloatingPoint!T) | |
| assert(frexp(0.0, exp) == 0.0 && exp == 0); | ||
| } | ||
|
|
||
| @system unittest | ||
| { | ||
| int exp; | ||
| real mantissa = frexp(123.456L, exp); | ||
|
|
||
| // check if values are equal to 19 decimal digits of precision | ||
| assert(equalsDigit(mantissa * pow(2.0L, cast(real) exp), 123.456L, 19)); | ||
| } | ||
|
|
||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
|
|
@@ -3619,6 +3627,11 @@ real log2(real x) @safe pure nothrow @nogc | |
| } | ||
|
|
||
| /// | ||
| @system unittest | ||
| { | ||
| assert(approxEqual(log2(1024.0L), 10)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, why are you testing with both
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| @system unittest | ||
| { | ||
| // check if values are equal to 19 decimal digits of precision | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -930,7 +930,7 @@ $(D rawRead) always reads in binary mode on Windows. | |
| { | ||
| static import std.file; | ||
|
|
||
| auto testFile = testFilename(); | ||
| auto testFile = std.file.deleteme(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge fan of this, but |
||
| std.file.write(testFile, "\r\n\n\r\n"); | ||
| scope(exit) std.file.remove(testFile); | ||
|
|
||
|
|
@@ -985,7 +985,7 @@ Throws: $(D ErrnoException) if the file is not opened or if the call to $(D fwri | |
| { | ||
| static import std.file; | ||
|
|
||
| auto testFile = testFilename(); | ||
| auto testFile = std.file.deleteme(); | ||
| auto f = File(testFile, "w"); | ||
| scope(exit) std.file.remove(testFile); | ||
|
|
||
|
|
@@ -1092,7 +1092,7 @@ Throws: $(D Exception) if the file is not opened. | |
| import std.conv : text; | ||
| static import std.file; | ||
|
|
||
| auto testFile = testFilename(); | ||
| auto testFile = std.file.deleteme(); | ||
| std.file.write(testFile, "abcdefghijklmnopqrstuvwqxyz"); | ||
| scope(exit) { std.file.remove(testFile); } | ||
|
|
||
|
|
@@ -1839,7 +1839,7 @@ $(CONSOLE | |
| { | ||
| static import std.file; | ||
|
|
||
| auto deleteme = testFilename(); | ||
| auto deleteme = std.file.deleteme(); | ||
| std.file.write(deleteme, "hello\nworld\ntrue\nfalse\n"); | ||
| scope(exit) std.file.remove(deleteme); | ||
| string s; | ||
|
|
@@ -2491,7 +2491,7 @@ $(REF readText, std,file) | |
| import std.typecons : tuple; | ||
|
|
||
| // prepare test file | ||
| auto testFile = testFilename(); | ||
| auto testFile = std.file.deleteme(); | ||
| scope(failure) printf("Failed test at line %d\n", __LINE__); | ||
| std.file.write(testFile, "1 2\n4 1\n5 100"); | ||
| scope(exit) std.file.remove(testFile); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2490,6 +2490,7 @@ template Fields(T) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
| struct S { int x; float y; } | ||
| static assert(is(Fields!S == AliasSeq!(int, float))); | ||
| } | ||
|
|
@@ -2546,6 +2547,7 @@ template FieldNameTuple(T) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
| struct S { int x; float y; } | ||
| static assert(FieldNameTuple!S == AliasSeq!("x", "y")); | ||
| static assert(FieldNameTuple!int == AliasSeq!""); | ||
|
|
@@ -2692,7 +2694,7 @@ private template hasRawAliasing(T...) | |
| enum hasRawAliasing = Impl!(RepresentationTypeTuple!T); | ||
| } | ||
|
|
||
| /// | ||
| // | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we undocumenting useful example blocks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| { | ||
| // simple types | ||
|
|
@@ -2788,7 +2790,7 @@ private template hasRawUnsharedAliasing(T...) | |
| enum hasRawUnsharedAliasing = Impl!(RepresentationTypeTuple!T); | ||
| } | ||
|
|
||
| /// | ||
| // | ||
| @safe unittest | ||
| { | ||
| // simple types | ||
|
|
@@ -4009,6 +4011,8 @@ template BaseTypeTuple(A) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
|
|
||
| interface I1 { } | ||
| interface I2 { } | ||
| interface I12 : I1, I2 { } | ||
|
|
@@ -4062,6 +4066,8 @@ template BaseClassesTuple(T) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
|
|
||
| class C1 { } | ||
| class C2 : C1 { } | ||
| class C3 : C2 { } | ||
|
|
@@ -4422,6 +4428,8 @@ template TemplateArgsOf(T : Base!Args, alias Base, Args...) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
|
|
||
| struct Foo(T, U) {} | ||
| static assert(is(TemplateArgsOf!(Foo!(int, real)) == AliasSeq!(int, real))); | ||
| } | ||
|
|
@@ -7331,6 +7339,8 @@ template mostNegative(T) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
|
|
||
| foreach (T; AliasSeq!(bool, byte, short, int, long)) | ||
| static assert(mostNegative!T == T.min); | ||
|
|
||
|
|
@@ -7397,6 +7407,7 @@ template mangledName(sth...) | |
| /// | ||
| @safe unittest | ||
| { | ||
| import std.meta : AliasSeq; | ||
| alias TL = staticMap!(mangledName, int, const int, immutable int); | ||
| static assert(TL == AliasSeq!("i", "xi", "yi")); | ||
| } | ||
|
|
@@ -7851,18 +7862,14 @@ template getSymbolsByUDA(alias symbol, alias attribute) | |
| enum Attr; | ||
| struct A | ||
| { | ||
| alias int INT; | ||
| alias INT = int; | ||
| alias void function(INT) SomeFunction; | ||
| @Attr int a; | ||
| int b; | ||
| @Attr private int c; | ||
| private int d; | ||
| } | ||
|
|
||
| // Here everything is fine, we have access to private member c | ||
| static assert(getSymbolsByUDA!(A, Attr).length == 2); | ||
| static assert(getSymbolsByUDA!(A, Attr).length == 1); | ||
| static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[0], Attr)); | ||
| static assert(hasUDA!(getSymbolsByUDA!(A, Attr)[1], Attr)); | ||
| } | ||
|
|
||
| // #16387: getSymbolsByUDA works with structs but fails with classes | ||
|
|
||
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 wonder why it worked with
@safebefore?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.
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.
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.