Skip to content

Commit

Permalink
replace dunittest.d with D unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 21, 2015
1 parent 4f50d3e commit c509313
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 98 deletions.
23 changes: 0 additions & 23 deletions src/dunittest.d

This file was deleted.

19 changes: 8 additions & 11 deletions src/imphint.d
Expand Up @@ -50,16 +50,13 @@ extern (C++) const(char)* importHint(const(char)* s)
return null; // didn't find it
}

version (unittest)
unittest
{
extern (C++) void unittest_importHint()
{
const(char)* p;
p = importHint("printf");
assert(p);
p = importHint("fabs");
assert(p);
p = importHint("xxxxx");
assert(!p);
}
const(char)* p;
p = importHint("printf");
assert(p);
p = importHint("fabs");
assert(p);
p = importHint("xxxxx");
assert(!p);
}
2 changes: 0 additions & 2 deletions src/mars.d
Expand Up @@ -25,7 +25,6 @@ import ddmd.dmodule;
import ddmd.doc;
import ddmd.dscope;
import ddmd.dsymbol;
import ddmd.dunittest;
import ddmd.errors;
import ddmd.expression;
import ddmd.globals;
Expand Down Expand Up @@ -266,7 +265,6 @@ extern (C++) int tryMain(size_t argc, const(char)** argv)
printf("DMD %s DEBUG\n", global._version);
fflush(stdout); // avoid interleaving with stderr output when redirecting
}
unittests();
// Check for malformed input
if (argc < 1 || !argv)
{
Expand Down
6 changes: 3 additions & 3 deletions src/posix.mak
Expand Up @@ -180,13 +180,13 @@ endif


FRONT_SRCS=$(addsuffix .d,access aggregate aliasthis apply argtypes arrayop \
arraytypes attrib builtin canthrow clone complex cond constfold \
arraytypes attrib builtin canthrow clone complex cond constfold \
cppmangle ctfeexpr dcast dclass declaration delegatize denum dimport \
dinifile dinterpret dmacro dmangle dmodule doc dscope dstruct dsymbol \
dtemplate dunittest dversion entity errors escape expression func \
dtemplate dversion entity errors escape expression func \
globals hdrgen id identifier impcnvtab imphint init inline intrange \
json lexer lib link mars mtype nogc nspace opover optimize parse sapply \
sideeffect statement staticassert target tokens traits utf visitor \
sideeffect statement staticassert target tokens traits utf visitor \
typinf)

ifeq ($(D_OBJC),1)
Expand Down
21 changes: 9 additions & 12 deletions src/root/aav.d
Expand Up @@ -155,17 +155,14 @@ extern (C++) void dmd_aaRehash(AA** paa)
}
}

version (unittest)
unittest
{
extern (C++) void unittest_aa()
{
AA* aa = null;
Value v = dmd_aaGetRvalue(aa, null);
assert(!v);
Value* pv = dmd_aaGet(&aa, null);
assert(pv);
*pv = cast(void*)3;
v = dmd_aaGetRvalue(aa, null);
assert(v == cast(void*)3);
}
AA* aa = null;
Value v = dmd_aaGetRvalue(aa, null);
assert(!v);
Value* pv = dmd_aaGet(&aa, null);
assert(pv);
*pv = cast(void*)3;
v = dmd_aaGetRvalue(aa, null);
assert(v == cast(void*)3);
}
89 changes: 43 additions & 46 deletions src/root/speller.d
Expand Up @@ -210,55 +210,52 @@ void* speller(const(char)* seed, scope dg_speller_t dg, const(char)* charset)
return null; // didn't find it
}

version (unittest)
unittest
{
void unittest_speller()
{
static __gshared const(char)*** cases =
[
["hello", "hell", "y"],
["hello", "hel", "y"],
["hello", "ello", "y"],
["hello", "llo", "y"],
["hello", "hellox", "y"],
["hello", "helloxy", "y"],
["hello", "xhello", "y"],
["hello", "xyhello", "y"],
["hello", "ehllo", "y"],
["hello", "helol", "y"],
["hello", "abcd", "n"],
["hello", "helxxlo", "y"],
["hello", "ehlxxlo", "n"],
["hello", "heaao", "y"],
["_123456789_123456789_123456789_123456789", "_123456789_123456789_123456789_12345678", "y"],
[null, null, null]
];
//printf("unittest_speller()\n");
static __gshared const(char)*** cases =
[
["hello", "hell", "y"],
["hello", "hel", "y"],
["hello", "ello", "y"],
["hello", "llo", "y"],
["hello", "hellox", "y"],
["hello", "helloxy", "y"],
["hello", "xhello", "y"],
["hello", "xyhello", "y"],
["hello", "ehllo", "y"],
["hello", "helol", "y"],
["hello", "abcd", "n"],
["hello", "helxxlo", "y"],
["hello", "ehlxxlo", "n"],
["hello", "heaao", "y"],
["_123456789_123456789_123456789_123456789", "_123456789_123456789_123456789_12345678", "y"],
[null, null, null]
];
//printf("unittest_speller()\n");

void* dgarg;
void* dgarg;

void* speller_test(const(char)* s, ref int cost)
{
//printf("speller_test(%s, %s)\n", dgarg, s);
cost = 0;
if (strcmp(cast(char*)dgarg, s) == 0)
return dgarg;
return null;
}
void* speller_test(const(char)* s, ref int cost)
{
//printf("speller_test(%s, %s)\n", dgarg, s);
cost = 0;
if (strcmp(cast(char*)dgarg, s) == 0)
return dgarg;
return null;
}

dgarg = cast(char*)"hell";
const(void)* p = speller(cast(const(char)*)"hello", &speller_test, idchars);
assert(p !is null);
for (int i = 0; cases[i][0]; i++)
{
//printf("case [%d]\n", i);
dgarg = cast(void*)cases[i][1];
void* p2 = speller(cases[i][0], &speller_test, idchars);
if (p2)
assert(cases[i][2][0] == 'y');
else
assert(cases[i][2][0] == 'n');
}
//printf("unittest_speller() success\n");
dgarg = cast(char*)"hell";
const(void)* p = speller(cast(const(char)*)"hello", &speller_test, idchars);
assert(p !is null);
for (int i = 0; cases[i][0]; i++)
{
//printf("case [%d]\n", i);
dgarg = cast(void*)cases[i][1];
void* p2 = speller(cases[i][0], &speller_test, idchars);
if (p2)
assert(cases[i][2][0] == 'y');
else
assert(cases[i][2][0] == 'n');
}
//printf("unittest_speller() success\n");
}
2 changes: 1 addition & 1 deletion src/win32.mak
Expand Up @@ -141,7 +141,7 @@ FRONT_SRCS=access.d aggregate.d aliasthis.d apply.d argtypes.d arrayop.d \
cond.d constfold.d cppmangle.d ctfeexpr.d dcast.d dclass.d \
declaration.d delegatize.d denum.d dimport.d dinifile.d dinterpret.d \
dmacro.d dmangle.d dmodule.d doc.d dscope.d dstruct.d dsymbol.d \
dtemplate.d dunittest.d dversion.d entity.d errors.d escape.d \
dtemplate.d dversion.d entity.d errors.d escape.d \
expression.d func.d globals.d hdrgen.d id.d identifier.d imphint.d \
impcnvtab.d init.d inline.d intrange.d json.d lexer.d lib.d link.d \
mars.d mtype.d nogc.d nspace.d objc_stubs.d opover.d optimize.d parse.d \
Expand Down

0 comments on commit c509313

Please sign in to comment.