Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ endif
ifdef ENABLE_COVERAGE
DFLAGS += -cov
endif
UDFLAGS=-unittest -version=StdUnittest

# Set DOTOBJ and DOTEXE
ifeq (,$(findstring win,$(OS)))
Expand Down Expand Up @@ -347,14 +348,14 @@ UT_D_OBJS:=$(addprefix $(ROOT)/unittest/,$(addsuffix .o,$(D_MODULES)))
$(UT_D_OBJS): $(ALL_D_FILES)
$(UT_D_OBJS): $(ROOT)/unittest/%.o: %.d
@mkdir -p $(dir $@)
$(DMD) $(DFLAGS) -unittest -c -of$@ $<
$(DMD) $(DFLAGS) $(UDFLAGS) -c -of$@ $<

ifneq (1,$(SHARED))

$(UT_D_OBJS): $(DRUNTIME)

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME)
$(DMD) $(DFLAGS) -unittest -of$@ $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME) $(LINKDL) -defaultlib= -debuglib=
$(DMD) $(DFLAGS) $(UDFLAGS) -of$@ $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME) $(LINKDL) -defaultlib= -debuglib=

else

Expand All @@ -364,7 +365,7 @@ $(UT_D_OBJS): $(DRUNTIMESO)

$(UT_LIBSO): override PIC:=-fPIC
$(UT_LIBSO): $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO)
$(DMD) $(DFLAGS) -shared -unittest -of$@ $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO) $(LINKDL) -defaultlib= -debuglib=
$(DMD) $(DFLAGS) -shared $(UDFLAGS) -of$@ $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO) $(LINKDL) -defaultlib= -debuglib=

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_LIBSO)
$(DMD) $(DFLAGS) -of$@ $< -L$(UT_LIBSO) -defaultlib= -debuglib=
Expand All @@ -384,7 +385,7 @@ unittest/%.run : $(ROOT)/unittest/test_runner
%.test : %.d $(LIB)
T=`mktemp -d /tmp/.dmd-run-test.XXXXXX` && \
( \
$(DMD) -od$$T $(DFLAGS) -main -unittest $(LIB) -defaultlib= -debuglib= $(LINKDL) -cov -run $< ; \
$(DMD) -od$$T $(DFLAGS) -main $(UDFLAGS) $(LIB) -defaultlib= -debuglib= $(LINKDL) -cov -run $< ; \
RET=$$? ; rm -rf $$T ; exit $$RET \
)

Expand All @@ -400,7 +401,7 @@ unittest/%.run : $(ROOT)/unittest/test_runner
# This forces all of phobos to have debug symbols, which we need as we don't
# know where debugging is leading us.
%.debug_with_debugger : %.d $(LIB)
$(DMD) $(DFLAGS) -main -unittest $(LIB) -defaultlib= -debuglib= $(LINKDL) $<
$(DMD) $(DFLAGS) -main $(UDFLAGS) $(LIB) -defaultlib= -debuglib= $(LINKDL) $<
$(DEBUGGER) ./$(basename $(notdir $<))

# Target for quickly debugging a single module
Expand Down Expand Up @@ -607,7 +608,7 @@ $(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB)
################################################################################
%.publictests: %.d $(LIB) $(TESTS_EXTRACTOR) | $(PUBLICTESTS_DIR)/.directory
@$(TESTS_EXTRACTOR) --inputdir $< --outputdir $(PUBLICTESTS_DIR)
@$(DMD) $(DFLAGS) -defaultlib= -debuglib= $(LIB) -main -unittest -run $(PUBLICTESTS_DIR)/$(subst /,_,$<)
@$(DMD) $(DFLAGS) -defaultlib= -debuglib= $(LIB) -main $(UDFLAGS) -run $(PUBLICTESTS_DIR)/$(subst /,_,$<)

.PHONY : auto-tester-build
auto-tester-build: all checkwhitespace
Expand Down
2 changes: 1 addition & 1 deletion std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ do
}

// Make sure receive() works with free functions as well.
version (unittest)
version(StdUnittest)
{
private void receiveFunction(int x) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public:
}
}

version (unittest)
version(StdUnittest)
{
static void testrw(void[] b)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment
import std.typecons : Ternary;
import std.typecons : tuple, Tuple;

version(StdUnittest)
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this here? I'd assume if no unittest is conducted, unittests are ignored anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From DIP82:

At present, unittest blocks inside of a templated type are compiled into every instantation, which only works with tests that are generic, which most tests aren't, and it almost never works with examples and thus doesn't work for ddoc-ed unittest blocks.

  1. these unittest blocks might not even be run (I have a couple of these issues during the runnable examples story)
  2. these unittest blocks will be executed as part of a user's testsuite

@system unittest
{
import std.algorithm.comparison : max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct FallbackAllocator(Primary, Fallback)

// Need both allocators to be stateless
// This is to avoid using default initialized stateful allocators
version(StdUnittest)
static if (!stateSize!Primary && !stateSize!Fallback)
@system unittest
{
Expand Down
1 change: 1 addition & 0 deletions std/experimental/allocator/building_blocks/free_list.d
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct FreeList(ParentAllocator,
_max = high;
}

version(StdUnittest)
@system unittest
{
import std.experimental.allocator.common : chooseAtRuntime;
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/allocator/building_blocks/free_tree.d
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ struct FreeTree(ParentAllocator)
return true;
}

version(StdUnittest)
@system unittest // test a few simple configurations
{
import std.experimental.allocator.gc_allocator;
Expand All @@ -353,6 +354,7 @@ struct FreeTree(ParentAllocator)
assert(a.formatSizes == "(_)", a.formatSizes);
}

version(StdUnittest)
@system unittest // build a complex free tree
{
import std.experimental.allocator.gc_allocator, std.range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ struct KRRegion(ParentAllocator = NullAllocator)
}

///
version(StdUnittest)
@system unittest
{
import std.experimental.allocator.gc_allocator : GCAllocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ScopedAllocator(ParentAllocator)
static if (!stateSize!ParentAllocator)
{
// This test is available only for stateless allocators
version(StdUnittest)
@system unittest
{
testAllocator!(() => ScopedAllocator());
Expand Down
1 change: 1 addition & 0 deletions std/experimental/allocator/mallocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import std.experimental.allocator.common;
*/
struct Mallocator
{
version(StdUnittest)
@system unittest { testAllocator!(() => Mallocator.instance); }

/**
Expand Down
4 changes: 2 additions & 2 deletions std/experimental/checkedint.d
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ if (isIntegral!T && T.sizeof >= 4)
testPow!ulong(3, 41);
}

version(unittest) private struct CountOverflows
version(StdUnittest) private struct CountOverflows
{
uint calls;
auto onOverflow(string op, Lhs)(Lhs lhs)
Expand All @@ -2643,7 +2643,7 @@ version(unittest) private struct CountOverflows
}
}

version(unittest) private struct CountOpBinary
version(StdUnittest) private struct CountOpBinary
{
uint calls;
auto hookOpBinary(string op, Lhs, Rhs)(Lhs lhs, Rhs rhs)
Expand Down
2 changes: 1 addition & 1 deletion std/internal/cstring.d
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private:

To* _ptr;
size_t _length; // length of the string
version (unittest)
version (StdUnittest)
{
enum buffLength = 16 / To.sizeof; // smaller size to trigger reallocations
}
Expand Down
2 changes: 1 addition & 1 deletion std/net/curl.d
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import std.internal.cstring;

public import etc.c.curl : CurlOption;

version(unittest)
version(StdUnittest)
{
// Run unit test with the PHOBOS_TEST_ALLOW_NET=1 set in order to
// allow net traffic
Expand Down
8 changes: 3 additions & 5 deletions std/variant.d
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,6 @@ private:
return 0;
}

enum doUnittest = is(VariantN == Variant);

public:
/** Constructs a $(D VariantN) value given an argument of a
* generic type. Statically rejects disallowed types.
Expand Down Expand Up @@ -684,7 +682,7 @@ public:
}

///
static if (doUnittest)
version(StdUnittest)
@system unittest
{
Variant a;
Expand Down Expand Up @@ -717,7 +715,7 @@ public:
}

///
static if (doUnittest)
version(StdUnittest)
@system unittest
{
Variant a = 5;
Expand Down Expand Up @@ -1109,7 +1107,7 @@ public:
}

///
static if (doUnittest)
version(StdUnittest)
@system unittest
{
Variant a = new int[10];
Expand Down
Loading