use of org.ballerinalang.util.debugger.Debugger in project ballerina by ballerina-lang.
the class BRunUtil method invoke.
/**
* Invoke a ballerina function given context.
*
* @param compileResult CompileResult instance.
* @param initFuncInfo Function to invoke.
* @param context invocation context.
*/
public static void invoke(CompileResult compileResult, FunctionInfo initFuncInfo, WorkerExecutionContext context) {
Debugger debugger = new Debugger(compileResult.getProgFile());
compileResult.getProgFile().setDebugger(debugger);
BLangFunctions.invokeCallable(initFuncInfo, context);
}
use of org.ballerinalang.util.debugger.Debugger in project ballerina by ballerina-lang.
the class BRunUtil method invokeFunction.
/**
* Invoke a ballerina function to get BReference Value Objects.
*
* @param compileResult CompileResult instance
* @param functionName Name of the function to invoke
* @param args Input parameters for the function
* @return return values of the function
*/
public static BValue[] invokeFunction(CompileResult compileResult, String functionName, BValue[] args) {
if (compileResult.getErrorCount() > 0) {
throw new IllegalStateException(compileResult.toString());
}
ProgramFile programFile = compileResult.getProgFile();
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
BValue[] response = BLangFunctions.invokeEntrypointCallable(programFile, programFile.getEntryPkgName(), functionName, args);
return response;
}
use of org.ballerinalang.util.debugger.Debugger in project ballerina by ballerina-lang.
the class BRunUtil method invokeStateful.
/**
* Invoke a ballerina function with state. Need to use compileAndSetup method in BCompileUtil to use this.
*
* @param compileResult CompileResult instance
* @param packageName Name of the package to invoke
* @param functionName Name of the function to invoke
* @param args Input parameters for the function
* @return return values of the function
*/
public static BValue[] invokeStateful(CompileResult compileResult, String packageName, String functionName, BValue[] args) {
if (compileResult.getErrorCount() > 0) {
throw new IllegalStateException(compileResult.toString());
}
ProgramFile programFile = compileResult.getProgFile();
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
PackageInfo packageInfo = programFile.getPackageInfo(packageName);
FunctionInfo functionInfo = packageInfo.getFunctionInfo(functionName);
if (functionInfo == null) {
throw new RuntimeException("Function '" + functionName + "' is not defined");
}
if (functionInfo.getParamTypes().length != args.length) {
throw new RuntimeException("Size of input argument arrays is not equal to size of function parameters");
}
BValue[] response = BLangFunctions.invokeCallable(functionInfo, compileResult.getContext(), args);
return spreadToBValueArray(response);
}
use of org.ballerinalang.util.debugger.Debugger in project ballerina by ballerina-lang.
the class BRunUtil method invoke.
/**
* Invoke a ballerina function.
*
* @param compileResult CompileResult instance
* @param functionName Name of the function to invoke
* @param args Input parameters for the function
* @return return values of the function
*/
public static BValue[] invoke(CompileResult compileResult, String functionName, BValue[] args) {
if (compileResult.getErrorCount() > 0) {
throw new IllegalStateException(compileResult.toString());
}
ProgramFile programFile = compileResult.getProgFile();
Debugger debugger = new Debugger(programFile);
programFile.setDebugger(debugger);
BValue[] response = BLangFunctions.invokeEntrypointCallable(programFile, programFile.getEntryPkgName(), functionName, args);
return spreadToBValueArray(response);
}
use of org.ballerinalang.util.debugger.Debugger 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