Search in sources :

Example 1 with ABSTestRunnerGenerator

use of abs.backend.tests.ABSTestRunnerGenerator in project abstools by abstools.

the class ABSUnitTestExecutionJob method generateTestRunner.

/**
 * Generate an ABS file from an ABS project that can be used to execute unit tests
 * @throws ParseException Is thrown, if the project which is compiled has parse errors
 * @throws TypeCheckerException Is thrown, if the project which is compiled has type errors
 * @throws DeltaModellingException
 * @throws WrongProgramArgumentException
 */
private void generateTestRunner(IProgressMonitor monitor, AbsNature nature) throws CoreException, IOException, ParseException, TypeCheckerException {
    PrintStream ps = null;
    FileInputStream fis = null;
    try {
        // find a way to change
        String path = Constants.DEFAULT_MAVEN_TARGET_ABS_PATH;
        IFolder folder = project.getFolder(path);
        MaudeJob.prepareFolder(monitor, folder);
        String fileName = "runner.abs";
        final IFile wspaceFile = folder.getFile(fileName);
        /* generateMaude only knows how to fill PrintStreams */
        final File tmpFile = File.createTempFile(fileName, null);
        ps = new PrintStream(tmpFile);
        // Get model, check for errors and throw respective exception
        Model model = nature.getCompleteModel();
        if (model.hasParserErrors()) {
            throw new ParseException(model.getParserErrors());
        }
        if (model.hasTypeErrors()) {
            throw new TypeCheckerException(model.typeCheck());
        }
        String mb = abs.backend.tests.ABSTestRunnerGenerator.RUNNER_MAIN;
        ABSTestRunnerGenerator gen = new ASTBasedABSTestRunnerGenerator(model);
        gen.generateTestRunner(ps);
        ps.close();
        fis = new FileInputStream(tmpFile);
        if (wspaceFile.exists())
            wspaceFile.setContents(fis, true, false, monitor);
        else
            wspaceFile.create(fis, true, monitor);
        fis.close();
        tmpFile.delete();
        destFile = new File(project.getLocation().append(path).toFile(), fileName);
    } finally {
        if (ps != null) {
            ps.flush();
            ps.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
}
Also used : ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) PrintStream(java.io.PrintStream) IFile(org.eclipse.core.resources.IFile) TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) ASTBasedABSTestRunnerGenerator(abs.backend.tests.ASTBasedABSTestRunnerGenerator) ABSTestRunnerGenerator(abs.backend.tests.ABSTestRunnerGenerator) Model(abs.frontend.ast.Model) ParseException(org.absmodels.abs.plugin.exceptions.ParseException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ABSTestRunnerGenerator (abs.backend.tests.ABSTestRunnerGenerator)1 ASTBasedABSTestRunnerGenerator (abs.backend.tests.ASTBasedABSTestRunnerGenerator)1 Model (abs.frontend.ast.Model)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 PrintStream (java.io.PrintStream)1 ParseException (org.absmodels.abs.plugin.exceptions.ParseException)1 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1