use of org.ballerinalang.compiler.plugins.CompilerPlugin in project ballerina by ballerina-lang.
the class BTestRunner method runTest.
/**
* Executes a given set of ballerina program files.
*
* @param sourceRoot source root
* @param sourceFilePaths List of @{@link Path} of ballerina files
* @param groups List of groups to be included/excluded
* @param shouldIncludeGroups flag to specify whether to include or exclude provided groups
*/
public void runTest(String sourceRoot, Path[] sourceFilePaths, List<String> groups, boolean shouldIncludeGroups) {
outStream.println("---------------------------------------------------------------------------");
outStream.println(" T E S T S");
outStream.println("---------------------------------------------------------------------------");
TesterinaRegistry.getInstance().setGroups(groups);
TesterinaRegistry.getInstance().setShouldIncludeGroups(shouldIncludeGroups);
Arrays.stream(sourceFilePaths).forEach(sourcePackage -> {
// compile
CompileResult compileResult = BCompileUtil.compile(sourceRoot == null ? programDirPath.toString() : sourceRoot, sourcePackage.toString(), CompilerPhase.CODE_GEN);
// print errors
for (Diagnostic diagnostic : compileResult.getDiagnostics()) {
errStream.println(diagnostic.getKind() + ": " + diagnostic.getPosition() + " " + diagnostic.getMessage());
}
if (compileResult.getDiagnostics().length > 0) {
throw new BallerinaException("[ERROR] Compilation failed.");
}
// set the debugger
ProgramFile programFile = compileResult.getProgFile();
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
TesterinaRegistry.getInstance().addProgramFile(programFile);
// process the compiled files
ServiceLoader<CompilerPlugin> processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
processorServiceLoader.forEach(plugin -> {
if (plugin instanceof TestAnnotationProcessor) {
try {
((TestAnnotationProcessor) plugin).packageProcessed(programFile);
} catch (Exception e) {
errStream.println("[ERROR] Validation failed. Cause: " + e.getMessage());
throw new BallerinaException(e);
}
}
});
});
// execute the test programs
execute();
// print the report
tReport.printSummary();
}
Aggregations