Search in sources :

Example 1 with ProjectTester

use of aQute.bnd.build.ProjectTester in project bnd by bndtools.

the class bnd method runtTest.

/**
	 * Help function to run the tests
	 */
private int runtTest(File testFile, Workspace ws, File reportDir, Tag summary) throws Exception {
    File tmpDir = new File(reportDir, "tmp");
    IO.mkdirs(tmpDir);
    tmpDir.deleteOnExit();
    Tag test = new Tag(summary, "test");
    test.addAttribute("path", testFile.getAbsolutePath());
    if (!testFile.isFile()) {
        error("No bnd file: %s", testFile);
        test.addAttribute("exception", "No bnd file found");
        error("No bnd file found for %s", testFile.getAbsolutePath());
        return 1;
    }
    Project project = new Project(ws, testFile.getAbsoluteFile().getParentFile(), testFile.getAbsoluteFile());
    project.use(this);
    project.setProperty(NOBUNDLES, "true");
    ProjectTester tester = project.getProjectTester();
    if (!project.isOk()) {
        getInfo(project, project.toString() + ": " + testFile.getName() + ":");
        // Indicate failure but do not abort
        return 1;
    }
    tester.setContinuous(false);
    tester.setReportDir(tmpDir);
    test.addAttribute("title", project.toString());
    long start = System.currentTimeMillis();
    try {
        int errors = tester.test();
        Collection<File> reports = tester.getReports();
        for (File report : reports) {
            Tag bundle = new Tag(test, "bundle");
            File dest = new File(reportDir, report.getName());
            IO.rename(report, dest);
            bundle.addAttribute("file", dest.getAbsolutePath());
            doPerReport(bundle, dest);
        }
        switch(errors) {
            case ProjectLauncher.OK:
                return 0;
            case ProjectLauncher.CANCELED:
                test.addAttribute("failed", "canceled");
                return 1;
            case ProjectLauncher.DUPLICATE_BUNDLE:
                test.addAttribute("failed", "duplicate bundle");
                return 1;
            case ProjectLauncher.ERROR:
                test.addAttribute("failed", "unknown reason");
                return 1;
            case ProjectLauncher.RESOLVE_ERROR:
                test.addAttribute("failed", "resolve error");
                return 1;
            case ProjectLauncher.TIMEDOUT:
                test.addAttribute("failed", "timed out");
                return 1;
            case ProjectLauncher.WARNING:
                test.addAttribute("warning", "true");
                return 1;
            case ProjectLauncher.ACTIVATOR_ERROR:
                test.addAttribute("failed", "activator error");
                return 1;
            default:
                if (errors > 0) {
                    test.addAttribute("errors", errors);
                    return errors;
                }
                test.addAttribute("failed", "unknown reason");
                return errors;
        }
    } catch (Exception e) {
        test.addAttribute("failed", e);
        exception(e, "Exception in run %s", e);
        return 1;
    } finally {
        long duration = System.currentTimeMillis() - start;
        test.addAttribute("duration", (duration + 500) / 1000);
        getInfo(project, project.toString() + ": ");
    }
}
Also used : Project(aQute.bnd.build.Project) Tag(aQute.lib.tag.Tag) ProjectTester(aQute.bnd.build.ProjectTester) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException)

Example 2 with ProjectTester

use of aQute.bnd.build.ProjectTester in project bnd by bndtools.

the class LauncherTest method testUnresolved.

public void testUnresolved() throws Exception {
    Project project = getProject();
    project.clear();
    project.setProperty(Constants.RUNTRACE, "true");
    String mandatorynoversion = IO.getFile("jar/mandatorynoversion.jar").getAbsolutePath();
    String runbundles = project.getProperty(Constants.RUNBUNDLES);
    project.setProperty(Constants.RUNBUNDLES, runbundles + "," + mandatorynoversion + ";version=file");
    ProjectTester tester = project.getProjectTester();
    tester.prepare();
    ProjectLauncher l = tester.getProjectLauncher();
    l.addRunBundle(mandatorynoversion);
    l.setTimeout(25000, TimeUnit.MILLISECONDS);
    l.setTrace(true);
    assertEquals(1, l.launch());
}
Also used : Project(aQute.bnd.build.Project) ProjectLauncher(aQute.bnd.build.ProjectLauncher) ProjectTester(aQute.bnd.build.ProjectTester)

Example 3 with ProjectTester

use of aQute.bnd.build.ProjectTester in project bnd by bndtools.

the class LauncherTest method testTester.

public static void testTester() throws Exception {
    Project project = getProject();
    project.clear();
    project.build();
    ProjectTester pt = project.getProjectTester();
    pt.addTest("test.TestCase1");
    pt.addTest("test.TestCase2:m1");
    assertEquals(2, pt.test());
}
Also used : Project(aQute.bnd.build.Project) ProjectTester(aQute.bnd.build.ProjectTester)

Example 4 with ProjectTester

use of aQute.bnd.build.ProjectTester in project bnd by bndtools.

the class TestTask method executeProject.

private void executeProject(Project project) throws Exception {
    ProjectTester tester = project.getProjectTester();
    tester.setContinuous(continuous);
    if (dir != null)
        tester.setCwd(dir);
    tester.prepare();
    if (report(project))
        throw new BuildException("Failed to initialise for testing.");
    int errors = tester.test();
    if (errors == 0) {
        System.err.println("All tests passed");
    } else {
        if (errors > 0) {
            System.err.println(errors + " Error(s)");
        } else
            System.err.println("Error " + errors);
        throw new BuildException("Tests failed");
    }
    if (report(project))
        throw new BuildException("Tests failed");
}
Also used : ProjectTester(aQute.bnd.build.ProjectTester) BuildException(org.apache.tools.ant.BuildException)

Example 5 with ProjectTester

use of aQute.bnd.build.ProjectTester in project bnd by bndtools.

the class LauncherTest method testJunit4Tester.

/**
	 * junit 4 "unrooted" tests with parametrized tests #661
	 * 
	 * @throws Exception
	 */
public static void testJunit4Tester() throws Exception {
    Project project = getProject();
    project.clear();
    project.build();
    ProjectTester pt = project.getProjectTester();
    pt.addTest("test.Junit4TestCase");
    assertEquals(0, pt.test());
    assertTrue(project.check());
}
Also used : Project(aQute.bnd.build.Project) ProjectTester(aQute.bnd.build.ProjectTester)

Aggregations

ProjectTester (aQute.bnd.build.ProjectTester)6 Project (aQute.bnd.build.Project)5 Container (aQute.bnd.build.Container)1 ProjectLauncher (aQute.bnd.build.ProjectLauncher)1 Tag (aQute.lib.tag.Tag)1 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ZipException (java.util.zip.ZipException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 BuildException (org.apache.tools.ant.BuildException)1