/** Compile and run */ int runTests() { // Compile, abort on errors if (verbose) Timer.showStdErr("Parsing"); if (!compile()) { // Show errors and warnings, if any if (!CompilerMessages.get().isEmpty()) System.err.println("Compiler messages:\n" + CompilerMessages.get()); return 1; } if (verbose) Timer.showStdErr("Initializing"); initializeArgs(); // Run the program BdsThread bdsThread = new BdsThread(programUnit, config); if (verbose) Timer.showStdErr("Process ID: " + bdsThread.getBdsThreadId()); if (verbose) Timer.showStdErr("Running tests"); ProgramUnit pu = bdsThread.getProgramUnit(); List<FunctionDeclaration> testFuncs = pu.testsFunctions(); // For each test function, create a thread that executes the function's body int exitCode = 0; int testOk = 0, testError = 0; for (FunctionDeclaration testFunc : testFuncs) { System.out.println(""); BdsThread bdsTestThread = new BdsThread( testFunc.getStatement(), bdsThread); // Note: We execute the function's body (not the function declaration) int exitValTest = runThread(bdsTestThread); // Show test result if (exitValTest == 0) { Timer.show("Test '" + testFunc.getFunctionName() + "': OK"); testOk++; } else { Timer.show("Test '" + testFunc.getFunctionName() + "': FAIL"); exitCode = 1; testError++; } } // Show results System.out.println(""); Timer.show( "Totals" // + "\n OK : " + testOk // + "\n ERROR : " + testError // ); return exitCode; }