From 2e96d0654bb7146d40f71697c66a8fa6826440ee Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 19:21:26 +0200 Subject: [PATCH 1/7] Issue 16984 - Make std.math runnable --- std/math.d | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/std/math.d b/std/math.d index 7e297b21c76..39082ab4c7b 100644 --- a/std/math.d +++ b/std/math.d @@ -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)); 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)); +} + @system unittest { // check if values are equal to 19 decimal digits of precision From c2d03bf75492c9141026fc58db865e5e0ca4d5e8 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 21:10:07 +0200 Subject: [PATCH 2/7] Issue 16984 - Make std.stdio runnable --- std/stdio.d | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index 8b96fa04639..ef430f6e1cf 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -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(); 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); From 3cc63005e1bb05fdf78fd3017c1d9eb3c41705cc Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 21:18:14 +0200 Subject: [PATCH 3/7] Issue 16984 - Make std.traits runnable --- std/traits.d | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/std/traits.d b/std/traits.d index 19d62503a68..ee44ae0dbb7 100644 --- a/std/traits.d +++ b/std/traits.d @@ -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); } -/// +// @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")); } @@ -7845,13 +7856,13 @@ template getSymbolsByUDA(alias symbol, alias attribute) static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); } -/// +// @safe unittest { enum Attr; struct A { - alias int INT; + alias INT = int; alias void function(INT) SomeFunction; @Attr int a; int b; From ff6c0f1dfc2405b4d0f92d08079d390fc4cc14a0 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 21:22:52 +0200 Subject: [PATCH 4/7] Issue 16984 - Make stdx.allocator.building_blocks.quantizer runnable --- std/experimental/allocator/building_blocks/quantizer.d | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/std/experimental/allocator/building_blocks/quantizer.d b/std/experimental/allocator/building_blocks/quantizer.d index b3f205dcc61..6df77e59468 100644 --- a/std/experimental/allocator/building_blocks/quantizer.d +++ b/std/experimental/allocator/building_blocks/quantizer.d @@ -212,14 +212,19 @@ struct Quantizer(ParentAllocator, alias roundingFunction) @system unittest { import std.experimental.allocator.building_blocks.free_tree : FreeTree; - import std.experimental.allocator.common : roundUpToMultipleOf; import std.experimental.allocator.gc_allocator : GCAllocator; + size_t roundUpToMultipleOf(size_t s, uint base) + { + auto rem = s % base; + return rem ? s + base - rem : s; + } + // Quantize small allocations to a multiple of cache line, large ones to a // multiple of page size alias MyAlloc = Quantizer!( FreeTree!GCAllocator, - n => n.roundUpToMultipleOf(n <= 16_384 ? 64 : 4096)); + n => roundUpToMultipleOf(n, n <= 16_384 ? 64 : 4096)); MyAlloc alloc; const buf = alloc.allocate(256); assert(buf.ptr); From 5a20f69160443a17a0fbc1abe2e676b60e5485d2 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 21:59:43 +0200 Subject: [PATCH 5/7] Issue 16984 - Make stdx.allocator.building_blocks.free_list runnable --- .../allocator/building_blocks/free_list.d | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/std/experimental/allocator/building_blocks/free_list.d b/std/experimental/allocator/building_blocks/free_list.d index 88608060107..a2bacef3584 100644 --- a/std/experimental/allocator/building_blocks/free_list.d +++ b/std/experimental/allocator/building_blocks/free_list.d @@ -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,20 +894,6 @@ 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); - } /** Properties for getting (and possibly setting) the approximate maximum length of a shared freelist. @@ -916,21 +901,6 @@ struct SharedFreeList(ParentAllocator, @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); - } } /** @@ -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; From d661120ff3bef457f1e9413965ebef3dd3f14fff Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 12 Jul 2017 21:59:56 +0200 Subject: [PATCH 6/7] Fix Issue 16984 - Remove runnable blacklist --- posix.mak | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/posix.mak b/posix.mak index c413d21fb2b..f42f904a31f 100644 --- a/posix.mak +++ b/posix.mak @@ -264,15 +264,6 @@ MAKEFILE = $(firstword $(MAKEFILE_LIST)) # build with shared library support (defaults to true on supported platforms) SHARED=$(if $(findstring $(OS),linux freebsd),1,) -# Check for missing imports in public unittest examples. -# A blacklist of ignored module is provided as not all public unittest in -# Phobos are independently runnable yet -IGNORED_PUBLICTESTS= $(addprefix std/, \ - $(addprefix experimental/allocator/, \ - building_blocks/free_list building_blocks/quantizer \ - ) \ - math stdio traits) -PUBLICTESTS= $(addsuffix .publictests,$(filter-out $(IGNORED_PUBLICTESTS), $(D_MODULES))) TESTS_EXTRACTOR=$(ROOT)/tests_extractor PUBLICTESTS_DIR=$(ROOT)/publictests @@ -593,7 +584,7 @@ style_lint: dscanner $(LIB) ################################################################################ # Check for missing imports in public unittest examples. ################################################################################ -publictests: $(PUBLICTESTS) +publictests: $(addsuffix .publictests,$(D_MODULES)) $(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB) DFLAGS="$(DFLAGS) $(LIB) -defaultlib= -debuglib= $(LINKDL)" $(DUB) build --force --compiler=$${PWD}/$(DMD) --single $< From 41de215c91fbc053934c5de9b36f30a9f61a53c6 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 5 Oct 2017 21:36:12 +0200 Subject: [PATCH 7/7] Remove invalid private access by getSymbolsByUDA from unittest --- std/traits.d | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/std/traits.d b/std/traits.d index ee44ae0dbb7..ce555f4daaa 100644 --- a/std/traits.d +++ b/std/traits.d @@ -7856,7 +7856,7 @@ template getSymbolsByUDA(alias symbol, alias attribute) static assert(hasUDA!(getSymbolsByUDA!(HasPrivateMembers, Attr)[0], Attr)); } -// +/// @safe unittest { enum Attr; @@ -7866,14 +7866,10 @@ template getSymbolsByUDA(alias symbol, alias attribute) 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