Added ASSERT() to CBot unit tests
parent
b102f767d0
commit
a18c2c39d9
|
@ -28,6 +28,7 @@ public:
|
||||||
{
|
{
|
||||||
CBotProgram::Init();
|
CBotProgram::Init();
|
||||||
CBotProgram::AddFunction("FAIL", rFail, cFail);
|
CBotProgram::AddFunction("FAIL", rFail, cFail);
|
||||||
|
CBotProgram::AddFunction("ASSERT", rAssert, cAssert);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown()
|
void TearDown()
|
||||||
|
@ -74,6 +75,24 @@ private:
|
||||||
throw CBotTestFail(message);
|
throw CBotTestFail(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CBotTypResult cAssert(CBotVar* &var, void* user)
|
||||||
|
{
|
||||||
|
if (var == nullptr) return CBotTypResult(CBotErrLowParam);
|
||||||
|
if (var->GetType() != CBotTypBoolean) return CBotTypResult(CBotErrBadString);
|
||||||
|
var = var->GetNext();
|
||||||
|
return CBotTypResult(CBotTypVoid);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool rAssert(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||||
|
{
|
||||||
|
bool status = var->GetValInt();
|
||||||
|
if (!status)
|
||||||
|
{
|
||||||
|
throw CBotTestFail("CBot assertion failed");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Modified version of PutList from src/script/script.cpp
|
// Modified version of PutList from src/script/script.cpp
|
||||||
// Should be probably moved somewhere into the CBot library
|
// Should be probably moved somewhere into the CBot library
|
||||||
void PrintVars(std::stringstream& ss, CBotVar* var, const std::string& baseName = "", bool bArray = false)
|
void PrintVars(std::stringstream& ss, CBotVar* var, const std::string& baseName = "", bool bArray = false)
|
||||||
|
@ -219,7 +238,7 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CBotUT, Test)
|
TEST_F(CBotUT, EmptyTest)
|
||||||
{
|
{
|
||||||
ExecuteTest(
|
ExecuteTest(
|
||||||
"extern void EmptyTest()"
|
"extern void EmptyTest()"
|
||||||
|
@ -228,20 +247,6 @@ TEST_F(CBotUT, Test)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CBotUT, DISABLED_TestFail)
|
|
||||||
{
|
|
||||||
ExecuteTest(
|
|
||||||
"extern void FailingTest()"
|
|
||||||
"{"
|
|
||||||
" FAIL();"
|
|
||||||
"}"
|
|
||||||
"extern void AnotherFailingTest()"
|
|
||||||
"{"
|
|
||||||
" FAIL(\"This is a message\");"
|
|
||||||
"}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(CBotUT, DivideByZero)
|
TEST_F(CBotUT, DivideByZero)
|
||||||
{
|
{
|
||||||
ExecuteTest(
|
ExecuteTest(
|
||||||
|
@ -273,4 +278,33 @@ TEST_F(CBotUT, UndefinedFunction)
|
||||||
"}",
|
"}",
|
||||||
CBotErrUndefCall
|
CBotErrUndefCall
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CBotUT, BasicOperations)
|
||||||
|
{
|
||||||
|
ExecuteTest(
|
||||||
|
"extern void Comparations()"
|
||||||
|
"{"
|
||||||
|
" ASSERT(true);"
|
||||||
|
" ASSERT(!false);"
|
||||||
|
" ASSERT(1 != 0);"
|
||||||
|
" ASSERT(1 == 1);"
|
||||||
|
" ASSERT(1 > 0);"
|
||||||
|
" ASSERT(1 >= 0);"
|
||||||
|
" ASSERT(1 >= 1);"
|
||||||
|
" ASSERT(0 < 1);"
|
||||||
|
" ASSERT(0 <= 1);"
|
||||||
|
" ASSERT(1 <= 1);"
|
||||||
|
"}"
|
||||||
|
""
|
||||||
|
"extern void BasicMath()"
|
||||||
|
"{"
|
||||||
|
" ASSERT(2+2 == 4);"
|
||||||
|
" ASSERT(4-2 == 2);"
|
||||||
|
" ASSERT(2*2 == 4);"
|
||||||
|
" ASSERT(2/2 == 1);"
|
||||||
|
" ASSERT(5%2 == 1);"
|
||||||
|
" ASSERT(5**3 == 125);"
|
||||||
|
"}"
|
||||||
|
);
|
||||||
}
|
}
|
Loading…
Reference in New Issue