diff --git a/Makefile.m68k b/Makefile.m68k index 7413a0b2..655599c5 100644 --- a/Makefile.m68k +++ b/Makefile.m68k @@ -438,7 +438,7 @@ amigacatalogs: .PHONY: test test: app - ./amath test + ./amath testz .PHONY: install install: app diff --git a/app/main.cpp b/app/main.cpp index aabd43d5..13c9ff5a 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -33,5 +33,5 @@ int main(int argc, char **argv) Program->Initialize(argc, argv); Program->Run(); Cleanup(); - return 0; + return Program->GetExitStatus(); } diff --git a/app/system/base/io.cpp b/app/system/base/io.cpp index f9945509..fbdf09ae 100644 --- a/app/system/base/io.cpp +++ b/app/system/base/io.cpp @@ -79,7 +79,9 @@ static struct IntuitionBase *IntuitionBase = NULL; class Program* CreateProgram(int argc, char **argv) { #ifdef WITHTEST if (argc == 2 && StrIsEqual(argv[1], "test")) { - return new TestProgram(); + return new TestProgram(false); + } else if (argc == 2 && StrIsEqual(argv[1], "testz")) { + return new TestProgram(true); } else #endif { diff --git a/app/system/program.cpp b/app/system/program.cpp index 825877ea..e837dbec 100644 --- a/app/system/program.cpp +++ b/app/system/program.cpp @@ -34,6 +34,7 @@ Program::Program() { + status = 0; Variables = new VariableList(); Functions = new FunctionList(); Graphs = new GraphList(); @@ -104,3 +105,8 @@ void Program::SetLastResult(Number *number) delete ins; ins = number->Clone(); } + +int Program::GetExitStatus() +{ + return status; +} diff --git a/app/system/program.h b/app/system/program.h index 745416ad..feff2c59 100644 --- a/app/system/program.h +++ b/app/system/program.h @@ -64,6 +64,7 @@ public: void NewPositionalOutput(short unsigned int base, short unsigned int digits); void SetLastResult(Number *number); void SetPrompt(const char *text); + int GetExitStatus(); struct Number* GetLastResult(); class Language *Language; class ConsoleBase *Console; @@ -75,6 +76,9 @@ public: class FunctionList *Functions; class GraphList *Graphs; +protected: + int status; + private: struct Number* ins; }; diff --git a/app/system/program_test.cpp b/app/system/program_test.cpp index 728a157d..7f7e79bd 100644 --- a/app/system/program_test.cpp +++ b/app/system/program_test.cpp @@ -33,9 +33,11 @@ #include "system/base/io.h" #include -TestProgram::TestProgram() +TestProgram::TestProgram(bool silent) : Program() { + this->silent = silent; + // Ignore type of locale fraction point. delete Input; Input = new DecimalSystem(Preferences->GetDigits(), '.'); @@ -52,10 +54,11 @@ void TestProgram::Run() RunTests(); if (fail == 0) { - printf("All tests passed (%i)." NEWLINE, pass); + printf("All tests passed (%i)" NEWLINE, pass); } else { printf("Something went wrong ..." NEWLINE); printf("Passed: %i, failed: %i" NEWLINE, pass, fail); + status = 5; // Set exit status 5 } } @@ -109,10 +112,14 @@ void TestProgram::PerformTest(const char* input, const char* result, bool show, if (buf->Is(result) || !check) { pass++; - printf("PASS: [%s]" NEWLINE, show ? result : input); + if (!silent) { + printf("PASS: [%s]" NEWLINE, show ? result : input); + } } else { fail++; - printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString()); + if (!silent) { + printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString()); + } } delete buf; @@ -332,16 +339,16 @@ void TestProgram::RunTestset4() void TestProgram::RunTestset5() { TestExecution("delete funtions"); - TestStatement("f(x)=x*2+1", ""); - TestStatement("g(y)=y^2+y*1.5+2", ""); - TestStatement("h(x)=x^3-2*x^2-16*x+6", ""); - TestStatement("a=2;b=3;c=a+b;", ""); + TestStatement("f(x)=x*2+1", EMPTYSTRING); + TestStatement("g(y)=y^2+y*1.5+2", EMPTYSTRING); + TestStatement("h(x)=x^3-2*x^2-16*x+6", EMPTYSTRING); + TestStatement("a=2;b=3;c=a+b;", EMPTYSTRING); TestStatement("vars", "a = 2" NEWLINE "b = 3" NEWLINE "c = 5"); TestStatement("funcs", "f(x)=x*2+1" NEWLINE "g(y)=y^2+y*1.5+2" NEWLINE "h(x)=x^3-2*x^2-16*x+6"); TestStatement("f(2.2)", "f(2.2) = 5.4"); TestStatement("h(8.3)", "h(8.3) = 307.207"); TestStatement("c+1.1", "c+1.1 = 6.1"); - TestStatement("d=1.1", ""); + TestStatement("d=1.1", EMPTYSTRING); TestStatement("eval d=d+1", "d=(d+1) = 2.1"); TestStatement("eval d=d+1", "d=(d+1) = 3.1"); TestStatement("eval d=d*2", "d=(d*2) = 6.2"); diff --git a/app/system/program_test.h b/app/system/program_test.h index e1fa9dc4..4933ab30 100644 --- a/app/system/program_test.h +++ b/app/system/program_test.h @@ -41,13 +41,14 @@ */ class TestProgram : public Program { public: - TestProgram(); + TestProgram(bool silent); virtual ~TestProgram(); virtual void Initialize(int argc, char **argv); virtual void Run(); virtual void Exit(); private: + bool silent; int pass; int fail;