1
0

Add unittest

This commit is contained in:
otya128
2017-07-08 17:56:14 +09:00
parent 75d9e8edbf
commit 390c47e3d6
4 changed files with 22 additions and 1 deletions

View File

@@ -45,6 +45,13 @@ class InternalError : SmileBasicError
this.errnum = 1; this.errnum = 1;
super("Internal Error"); super("Internal Error");
} }
Throwable throwable;
this(Throwable throwable)
{
this.throwable = throwable;
this.errnum = 1;
super("Internal Error");
}
} }
class SyntaxError : SmileBasicError class SyntaxError : SmileBasicError
{ {

View File

@@ -32,3 +32,11 @@ int main(string[] argv)
}*/ }*/
return 0; return 0;
} }
unittest
{
auto petitcomputer = new PetitComputer();
petitcomputer.run(true, "TEST.txt", false, true);
assert(petitcomputer.lastError is null);
}

View File

@@ -1128,6 +1128,7 @@ class PetitComputer
bool isRunningDirectMode = false; bool isRunningDirectMode = false;
GLenum textureScaleMode; GLenum textureScaleMode;
int maincnt; int maincnt;
SmileBasicError lastError;
void run(bool nodirectmode = false, string inputfile = "", bool antialiasing = false, bool redirectConsole = false) void run(bool nodirectmode = false, string inputfile = "", bool antialiasing = false, bool redirectConsole = false)
{ {
if (antialiasing) if (antialiasing)
@@ -1180,9 +1181,11 @@ class PetitComputer
if(sbe.getErrorMessage2.length) console.print(sbe.getErrorMessage2, "\n"); if(sbe.getErrorMessage2.length) console.print(sbe.getErrorMessage2, "\n");
writeln(sbe.to!string); writeln(sbe.to!string);
writeln(sbe.getErrorMessage2); writeln(sbe.getErrorMessage2);
lastError = sbe;
} }
catch(Throwable t) catch(Throwable t)
{ {
lastError = new InternalError(t);
writeln(t); writeln(t);
} }
} }
@@ -1335,16 +1338,19 @@ class PetitComputer
writeln(sbe.to!string); writeln(sbe.to!string);
writeln(sbe.getErrorMessage2); writeln(sbe.getErrorMessage2);
writeln(sbe.func); writeln(sbe.func);
lastError = sbe;
loc = vm.currentLocation; loc = vm.currentLocation;
console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc)); console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc));
} }
catch(Throwable t) catch(Throwable t)
{ {
lastError = new InternalError(t);
writeln(t); writeln(t);
} }
} }
catch(Throwable t) catch(Throwable t)
{ {
lastError = new InternalError(t);
running = false; running = false;
try try
{ {

View File

@@ -10,5 +10,5 @@
"buildRequirements": ["allowWarnings"], "buildRequirements": ["allowWarnings"],
"targetPath": "out", "targetPath": "out",
"workingDirectory": "out", "workingDirectory": "out",
"copyFiles": ["SMILEBASIC/resources/*.txt", "SMILEBASIC/spdef.csv", "SMILEBASIC/dialogresource", "SDL_GameControllerDB/gamecontrollerdb.txt"] "copyFiles": ["SMILEBASIC/TEST.txt", "SMILEBASIC/resources/*.txt", "SMILEBASIC/spdef.csv", "SMILEBASIC/dialogresource", "SDL_GameControllerDB/gamecontrollerdb.txt"]
} }