From 390c47e3d67a9fcbbfa9adec8543ff5cf817a27a Mon Sep 17 00:00:00 2001 From: otya128 Date: Sat, 8 Jul 2017 17:56:14 +0900 Subject: [PATCH] Add unittest --- SMILEBASIC/error.d | 7 +++++++ SMILEBASIC/main.d | 8 ++++++++ SMILEBASIC/petitcomputer.d | 6 ++++++ dub.json | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/SMILEBASIC/error.d b/SMILEBASIC/error.d index d55b991..8873abc 100644 --- a/SMILEBASIC/error.d +++ b/SMILEBASIC/error.d @@ -45,6 +45,13 @@ class InternalError : SmileBasicError this.errnum = 1; super("Internal Error"); } + Throwable throwable; + this(Throwable throwable) + { + this.throwable = throwable; + this.errnum = 1; + super("Internal Error"); + } } class SyntaxError : SmileBasicError { diff --git a/SMILEBASIC/main.d b/SMILEBASIC/main.d index 30e64ef..6f5575f 100644 --- a/SMILEBASIC/main.d +++ b/SMILEBASIC/main.d @@ -32,3 +32,11 @@ int main(string[] argv) }*/ return 0; } + +unittest +{ + auto petitcomputer = new PetitComputer(); + petitcomputer.run(true, "TEST.txt", false, true); + assert(petitcomputer.lastError is null); +} + diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 03895d4..8229ae0 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -1128,6 +1128,7 @@ class PetitComputer bool isRunningDirectMode = false; GLenum textureScaleMode; int maincnt; + SmileBasicError lastError; void run(bool nodirectmode = false, string inputfile = "", bool antialiasing = false, bool redirectConsole = false) { if (antialiasing) @@ -1180,9 +1181,11 @@ class PetitComputer if(sbe.getErrorMessage2.length) console.print(sbe.getErrorMessage2, "\n"); writeln(sbe.to!string); writeln(sbe.getErrorMessage2); + lastError = sbe; } catch(Throwable t) { + lastError = new InternalError(t); writeln(t); } } @@ -1335,16 +1338,19 @@ class PetitComputer writeln(sbe.to!string); writeln(sbe.getErrorMessage2); writeln(sbe.func); + lastError = sbe; loc = vm.currentLocation; console.print(vm.currentSlotNumber, ":", loc.line, ":", loc.pos, ":", program.slot[vm.currentSlotNumber].getLine(loc)); } catch(Throwable t) { + lastError = new InternalError(t); writeln(t); } } catch(Throwable t) { + lastError = new InternalError(t); running = false; try { diff --git a/dub.json b/dub.json index f64575d..3c531eb 100644 --- a/dub.json +++ b/dub.json @@ -10,5 +10,5 @@ "buildRequirements": ["allowWarnings"], "targetPath": "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"] }