use of org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider in project n4js by eclipse.
the class XpectConfigurationDelegate method execute.
/**
* Runs provided File in Engine. Returns output of execution.
*/
public void execute(ILaunch launch, XpectRunConfiguration runConfiguration) throws RuntimeException {
Job job = new Job(launch.getLaunchConfiguration().getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
XpectRunner xr;
try {
xr = new XpectRunner(N4IDEXpectTestClass.class);
} catch (InitializationError e) {
N4IDEXpectUIPlugin.logError("cannot initialize xpect runner", e);
return Status.CANCEL_STATUS;
}
// TODO support multiple selection
/*
* if Project provided, or package files should be discovered there. Also multiple selected files
*/
String testFileLocation = runConfiguration.getXtFileToRun();
IXpectURIProvider uriprov = xr.getUriProvider();
if (uriprov instanceof N4IDEXpectTestURIProvider) {
((N4IDEXpectTestURIProvider) uriprov).addTestFileLocation(testFileLocation);
}
Result result = new Result();
RunNotifier notifier = new RunNotifier();
RunListener listener = result.createListener();
N4IDEXpectRunListener n4Listener = new N4IDEXpectRunListener();
notifier.addFirstListener(listener);
notifier.addListener(n4Listener);
try {
notifier.fireTestRunStarted(xr.getDescription());
xr.run(notifier);
notifier.fireTestRunFinished(result);
} finally {
notifier.removeListener(n4Listener);
notifier.removeListener(listener);
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
use of org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider in project n4js by eclipse.
the class XpectCompareCommandHandler method displayComparisonView.
/**
* Display comparison view of test file with expected and actual xpect expectation
*/
private void displayComparisonView(ComparisonFailure cf, Description desc) {
IXpectURIProvider uriProfider = XpectRunner.INSTANCE.getUriProvider();
IFile fileTest = null;
if (uriProfider instanceof N4IDEXpectTestURIProvider) {
N4IDEXpectTestURIProvider fileCollector = (N4IDEXpectTestURIProvider) uriProfider;
fileTest = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(fileCollector.findRawLocation(desc)));
}
if (fileTest != null && fileTest.isAccessible()) {
N4IDEXpectCompareEditorInput inp = new N4IDEXpectCompareEditorInput(fileTest, cf);
CompareUI.openCompareEditor(inp);
} else {
throw new RuntimeException("paths in descriptions changed!");
}
}
use of org.eclipse.n4js.xpect.ui.runner.N4IDEXpectTestFilesCollector.N4IDEXpectTestURIProvider in project n4js by eclipse.
the class XpectFileContentsUtil method getXpectFileContentAccess.
/**
* Create instance of {@link XpectFileContentAccess} for given {@link Description}. If xpect file cannot be accessed
* or resolved from provided description returns empty {@link Optional}
*
* @return {@link Optional}<{@link XpectFileContentAccess}>
*/
public static Optional<XpectFileContentAccess> getXpectFileContentAccess(Description description) {
String contents = "";
boolean containsFixme = false;
IXpectURIProvider xpectUriProvider = XpectRunner.INSTANCE.getUriProvider();
if (xpectUriProvider instanceof N4IDEXpectTestURIProvider) {
N4IDEXpectTestURIProvider n4XpectUriProvider = (N4IDEXpectTestURIProvider) xpectUriProvider;
String rawFileLocation = n4XpectUriProvider.findRawLocation(description);
try {
contents = new String(Files.readAllBytes(Paths.get(rawFileLocation)));
} catch (IOException e) {
N4IDEXpectUIPlugin.logError("cannot read contents of test file", e);
e.printStackTrace();
return Optional.empty();
}
}
containsFixme = contents.split("XPECT\\sFIXME").length > 1;
XpectFileContentAccess xpectFileContetnsAccess = new XpectFileContentAccess(contents, containsFixme);
return Optional.of(xpectFileContetnsAccess);
}
Aggregations