Cleanup of test functions.
This commit is contained in:
parent
8231a0d1b8
commit
277e478466
|
|
@ -90,7 +90,7 @@ private:
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
class Cat // [warn]: This class has a zero-argument constructor as well as a constructor with one default argument. This can be confusing
|
class Cat // [warn]: This class has a zero-argument constructor as well as a constructor with one default argument. This can be confusing
|
||||||
{
|
{
|
||||||
this() {}
|
this() {}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class DeleteCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testDelete()
|
void testDelete()
|
||||||
{
|
{
|
||||||
int[int] data = [1 : 2];
|
int[int] data = [1 : 2];
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class FloatOperatorCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testFish()
|
void testFish()
|
||||||
{
|
{
|
||||||
float z = 1.5f;
|
float z = 1.5f;
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,18 @@ module analysis.helpers;
|
||||||
|
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.traits;
|
import std.traits;
|
||||||
|
|
||||||
import std.d.ast;
|
import std.d.ast;
|
||||||
|
|
||||||
|
|
||||||
S between(S)(S value, S before, S after)
|
S between(S)(S value, S before, S after)
|
||||||
if (isSomeString!S) {
|
if (isSomeString!S)
|
||||||
|
{
|
||||||
return value.after(before).before(after);
|
return value.after(before).before(after);
|
||||||
}
|
}
|
||||||
|
|
||||||
S before(S)(S value, S separator)
|
S before(S)(S value, S separator)
|
||||||
if (isSomeString!S) {
|
if (isSomeString!S)
|
||||||
|
{
|
||||||
auto i = indexOf(value, separator);
|
auto i = indexOf(value, separator);
|
||||||
|
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
|
|
@ -27,7 +28,8 @@ if (isSomeString!S) {
|
||||||
}
|
}
|
||||||
|
|
||||||
S after(S)(S value, S separator)
|
S after(S)(S value, S separator)
|
||||||
if(isSomeString!S) {
|
if (isSomeString!S)
|
||||||
|
{
|
||||||
auto i = indexOf(value, separator);
|
auto i = indexOf(value, separator);
|
||||||
|
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
|
|
@ -38,19 +40,12 @@ if(isSomeString!S) {
|
||||||
return value[start .. $];
|
return value[start .. $];
|
||||||
}
|
}
|
||||||
|
|
||||||
S afterLast(S)(S value, S separator)
|
/**
|
||||||
if (isSomeString!S) {
|
* This assert function will analyze the passed in code, get the warnings,
|
||||||
size_t i = rindex(value, separator);
|
* and make sure they match the warnings in the comments. Warnings are
|
||||||
|
* marked like so: // [warn]: Failed to do somethings.
|
||||||
if (i == value.length)
|
*/
|
||||||
return "";
|
void assertAnalyzerWarnings(string code, analysis.run.AnalyzerCheck analyzers, string file=__FILE__, size_t line=__LINE__)
|
||||||
|
|
||||||
size_t start = i + separator.length;
|
|
||||||
|
|
||||||
return value[start .. $];
|
|
||||||
}
|
|
||||||
|
|
||||||
void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=__FILE__, size_t line=__LINE__)
|
|
||||||
{
|
{
|
||||||
import analysis.run;
|
import analysis.run;
|
||||||
|
|
||||||
|
|
@ -64,7 +59,6 @@ void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=_
|
||||||
{
|
{
|
||||||
size_t warnLine = line - 1 + std.conv.to!size_t(rawWarnings[i].between("test(", ":"));
|
size_t warnLine = line - 1 + std.conv.to!size_t(rawWarnings[i].between("test(", ":"));
|
||||||
warnings[warnLine] = rawWarnings[i].after(")");
|
warnings[warnLine] = rawWarnings[i].after(")");
|
||||||
// stderr.writefln("!!! warnings[%d] = \"%s\"", warnLine, warnings[warnLine]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all the messages from the comments in the code
|
// Get all the messages from the comments in the code
|
||||||
|
|
@ -85,14 +79,12 @@ void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=_
|
||||||
size_t lineNo = i + line;
|
size_t lineNo = i + line;
|
||||||
|
|
||||||
// Get the message
|
// Get the message
|
||||||
// stderr.writefln("!!! message[%d] = \"%s\"", lineNo, commentPart);
|
|
||||||
messages[lineNo] = commentPart;
|
messages[lineNo] = commentPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw an assert error if any messages are not listed in the warnings
|
// Throw an assert error if any messages are not listed in the warnings
|
||||||
foreach (lineNo, message; messages)
|
foreach (lineNo, message; messages)
|
||||||
{
|
{
|
||||||
// stderr.writefln("!!!!!! messages[%d] : %s", lineNo, messages[lineNo]);
|
|
||||||
// No warning
|
// No warning
|
||||||
if (lineNo !in warnings)
|
if (lineNo !in warnings)
|
||||||
{
|
{
|
||||||
|
|
@ -102,8 +94,8 @@ void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=_
|
||||||
codeLines[lineNo - line]
|
codeLines[lineNo - line]
|
||||||
);
|
);
|
||||||
throw new core.exception.AssertError(errors, file, lineNo);
|
throw new core.exception.AssertError(errors, file, lineNo);
|
||||||
// Different warning
|
|
||||||
}
|
}
|
||||||
|
// Different warning
|
||||||
else if (warnings[lineNo] != messages[lineNo])
|
else if (warnings[lineNo] != messages[lineNo])
|
||||||
{
|
{
|
||||||
string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format(
|
string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format(
|
||||||
|
|
@ -120,7 +112,6 @@ void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=_
|
||||||
string[] unexpectedWarnings;
|
string[] unexpectedWarnings;
|
||||||
foreach (lineNo, warning; warnings)
|
foreach (lineNo, warning; warnings)
|
||||||
{
|
{
|
||||||
// stderr.writefln("!!!!!! warnings[%d] : %s", lineNo, warning);
|
|
||||||
// Unexpected warning
|
// Unexpected warning
|
||||||
if (lineNo !in messages)
|
if (lineNo !in messages)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class IfElseSameCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testSizeT()
|
void testSizeT()
|
||||||
{
|
{
|
||||||
string person = "unknown";
|
string person = "unknown";
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class NumberStyleCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testNumbers()
|
void testNumbers()
|
||||||
{
|
{
|
||||||
int a;
|
int a;
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class ObjectConstCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testConsts()
|
void testConsts()
|
||||||
{
|
{
|
||||||
// Will be ok because all are declared const/immutable
|
// Will be ok because all are declared const/immutable
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class PokemonExceptionCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testCatch()
|
void testCatch()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ class BackwardsRangeCheck : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
void testRange()
|
void testRange()
|
||||||
{
|
{
|
||||||
int[] data = [1, 2, 3, 4, 5];
|
int[] data = [1, 2, 3, 4, 5];
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class StyleChecker : BaseAnalyzer
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
shouldWarn(q{
|
assertAnalyzerWarnings(q{
|
||||||
module AMODULE; // [warn]: Module/package name 'AMODULE' does not match style guidelines
|
module AMODULE; // [warn]: Module/package name 'AMODULE' does not match style guidelines
|
||||||
|
|
||||||
bool A_VARIABLE; // FIXME:
|
bool A_VARIABLE; // FIXME:
|
||||||
|
|
|
||||||
|
|
@ -3056,8 +3056,7 @@ unittest
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Disabling this test because it is machine dependent
|
// FIXME: Disabling this test because it is machine dependent
|
||||||
/*
|
version (none) unittest
|
||||||
unittest
|
|
||||||
{
|
{
|
||||||
InSituRegion!(4096) r1;
|
InSituRegion!(4096) r1;
|
||||||
auto a = r1.allocate(2001);
|
auto a = r1.allocate(2001);
|
||||||
|
|
@ -3069,7 +3068,7 @@ unittest
|
||||||
a = r2.allocate(2001);
|
a = r2.allocate(2001);
|
||||||
assert(a.length == 2001);
|
assert(a.length == 2001);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
_Options for $(D AllocatorWithStats) defined below. Each enables during
|
_Options for $(D AllocatorWithStats) defined below. Each enables during
|
||||||
compilation one specific counter, statistic, or other piece of information.
|
compilation one specific counter, statistic, or other piece of information.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue