Search in sources :

Example 6 with Debugger

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);
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger)

Example 7 with Debugger

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;
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) BValue(org.ballerinalang.model.values.BValue) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 8 with Debugger

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);
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) PackageInfo(org.ballerinalang.util.codegen.PackageInfo) BValue(org.ballerinalang.model.values.BValue) FunctionInfo(org.ballerinalang.util.codegen.FunctionInfo) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 9 with Debugger

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);
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) BValue(org.ballerinalang.model.values.BValue) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 10 with Debugger

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();
}
Also used : Debugger(org.ballerinalang.util.debugger.Debugger) CompilerPlugin(org.ballerinalang.compiler.plugins.CompilerPlugin) Diagnostic(org.ballerinalang.util.diagnostic.Diagnostic) CompileResult(org.ballerinalang.launcher.util.CompileResult) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Aggregations

Debugger (org.ballerinalang.util.debugger.Debugger)12 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)7 PackageInfo (org.ballerinalang.util.codegen.PackageInfo)5 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BValue (org.ballerinalang.model.values.BValue)3 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)2 FunctionInfo (org.ballerinalang.util.codegen.FunctionInfo)2 Diagnostic (org.ballerinalang.util.diagnostic.Diagnostic)2 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 CompileResult (org.ballerinalang.launcher.util.CompileResult)1 BBoolean (org.ballerinalang.model.values.BBoolean)1 LineNumberInfo (org.ballerinalang.util.codegen.LineNumberInfo)1 DebugContext (org.ballerinalang.util.debugger.DebugContext)1