running tests on module's classpath: SMTest

This commit is contained in:
Dmitry Avdeev
2010-06-01 12:34:22 +04:00
parent be35b620f9
commit 768db6edeb
4 changed files with 29 additions and 40 deletions
@@ -104,24 +104,25 @@ public class FileUrlProvider implements TestLocationProvider {
final int lineCount = doc.getLineCount();
final int lineStartOffset;
final int endOffset;
if (lineNum <= lineCount) {
lineStartOffset = doc.getLineStartOffset(lineNum - 1);
endOffset = doc.getLineEndOffset(lineNum - 1);
} else {
// unknown line
lineStartOffset = 0;
endOffset = doc.getTextLength();
}
PsiElement elementAtLine = psiFile.findElementAt(lineStartOffset);
if (elementAtLine != null) {
// skip whitespaces
while (elementAtLine instanceof PsiWhiteSpace) {
elementAtLine = elementAtLine.getNextSibling();
}
int offset = lineStartOffset;
PsiElement elementAtLine = null;
while (offset <= endOffset) {
elementAtLine = psiFile.findElementAt(offset);
if (!(elementAtLine instanceof PsiWhiteSpace)) break;
int length = elementAtLine.getTextLength();
offset += length > 1 ? length - 1 : 1;
}
final PsiElement leafPsiElementAtLine = elementAtLine == null
? null
: psiFile.findElementAt(elementAtLine.getTextOffset());
return PsiLocation.fromPsiElement(project, leafPsiElementAtLine != null ? leafPsiElementAtLine : psiFile);
return PsiLocation.fromPsiElement(project, elementAtLine != null ? elementAtLine : psiFile);
}
}
@@ -29,39 +29,16 @@ public class FileUrlLocationTest extends SMLightFixtureTestCase {
}
public void testSpecNavigation() throws Throwable {
createAndAddFile("my_example_spec.rb",
createAndAddFile("my_example_spec.xml",
"\n" +
"require \"spec\"\n" +
"\n" +
"describe \"Blabla\" do\n" +
"\n" +
" # Called before each example.\n" +
" before(:each) do\n" +
" # Do nothing\n" +
" end\n" +
"\n" +
" # Called after each example.\n" +
" after(:each) do\n" +
" # Do nothing\n" +
" end\n" +
"\n" +
" it \"should fail\" do\n" +
"\n" +
" #should pass\n" +
" true.should == false\n" +
" end\n" +
"\n" +
" it \"should pass\" do\n" +
"\n" +
" #should pass\n" +
" true.should == true\n" +
" end\n" +
"end");
"<describe>\n" +
" <a></a>\n" +
"</describe>\n" +
"\n");
final String path = myFixture.getFile().getVirtualFile().getPath();
doTest(17, "describe", path, 4);
doTest(189, "it", path, 16);
doTest(261, "it", path, 22);
doTest(1, "<", path, 2);
doTest(16, "<", path, 3);
}
private void doTest(final int expectedOffset, final String expectedStartsWith,
@@ -23,6 +23,7 @@ import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
@@ -37,6 +38,11 @@ import java.io.IOException;
* @author Roman.Chernyatchik
*/
public abstract class SMLightFixtureTestCase extends UsefulTestCase {
protected SMLightFixtureTestCase() {
PlatformTestCase.initPlatformLangPrefix();
}
protected static final LightProjectDescriptor ourDescriptor = new LightProjectDescriptor() {
public ModuleType getModuleType() {
return ModuleType.EMPTY;
@@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner;
import com.intellij.execution.configurations.RuntimeConfiguration;
import com.intellij.execution.testframework.TestConsoleProperties;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.PlatformTestCase;
/**
* @author Roman Chernyatchik
@@ -26,6 +27,10 @@ public abstract class BaseSMTRunnerTestCase extends LightPlatformTestCase {
protected SMTestProxy mySuite;
protected SMTestProxy mySimpleTest;
protected BaseSMTRunnerTestCase() {
PlatformTestCase.initPlatformLangPrefix();
}
@Override
protected void setUp() throws Exception {
super.setUp();