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() + ": ");
}
}
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());
}
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());
}
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");
}
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());
}
Aggregations