mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] spock: use real jar in tests
This commit is contained in:
@@ -1,43 +1,23 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.ext.spock
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiVariable
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import groovy.transform.CompileStatic
|
||||
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.declaration.GrMethodMayBeStaticInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
|
||||
import org.jetbrains.plugins.groovy.util.HighlightingTest
|
||||
import org.jetbrains.plugins.groovy.util.TypingTest
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
class SpockTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
super.setUp()
|
||||
|
||||
myFixture.addFileToProject("spock/lang/Specification.groovy", """
|
||||
package spock.lang;
|
||||
|
||||
class Specification {
|
||||
|
||||
}
|
||||
""")
|
||||
myFixture.addClass '''\
|
||||
package groovy.lang;
|
||||
public class Closure<T> {
|
||||
T call(Object ... args) { return null; }
|
||||
}
|
||||
'''
|
||||
}
|
||||
import static com.intellij.psi.CommonClassNames.JAVA_LANG_STRING
|
||||
|
||||
@CompileStatic
|
||||
class SpockTest extends SpockTestBase implements TypingTest, HighlightingTest {
|
||||
|
||||
@Test
|
||||
void testCompletion() {
|
||||
def file = myFixture.addFileToProject("FooSpec.groovy", """
|
||||
configureByText '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
expect:
|
||||
@@ -52,40 +32,37 @@ class FooSpec extends spock.lang.Specification {
|
||||
""|""|""||""
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
checkCompletionStatic(file, "varAssigment", "varShl", "varShl1", "varShl2", "varShl3", "varTable1", "varTable2", "varTable3", "varTable4")
|
||||
}
|
||||
|
||||
private void doTest(String expectedType, String text) {
|
||||
myFixture.configureByText("FooSpec.groovy", text)
|
||||
|
||||
def var = myFixture.elementAtCaret
|
||||
assertInstanceOf(var, PsiVariable)
|
||||
assertEquals(expectedType, ((PsiVariable)var).type.canonicalText)
|
||||
'''
|
||||
fixture.completeBasic()
|
||||
fixture.assertPreferredCompletionItems(
|
||||
0,
|
||||
"varAssigment", "varShl", "varShl1", "varShl2", "varShl3", "varTable1", "varTable2", "varTable3", "varTable4"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquals() {
|
||||
doTest(CommonClassNames.JAVA_LANG_STRING, """
|
||||
typingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
expect:
|
||||
name<caret>
|
||||
<caret>name
|
||||
|
||||
where:
|
||||
name = "xxx"
|
||||
}
|
||||
}
|
||||
""")
|
||||
''', JAVA_LANG_STRING
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTable() {
|
||||
doTest("java.util.List<? extends java.lang.Number>", """
|
||||
typingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
List<Byte> list = zzz()
|
||||
expect:
|
||||
name<caret>
|
||||
<caret>name
|
||||
|
||||
where:
|
||||
varTable1|varT.a.ble2|varTable3|name
|
||||
@@ -94,57 +71,61 @@ class FooSpec extends spock.lang.Specification {
|
||||
""|""|""|null
|
||||
}
|
||||
}
|
||||
""")
|
||||
''', 'java.util.List<? extends java.lang.Number>'
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShlSimple() {
|
||||
doTest(AbstractMap.name, """
|
||||
typingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
expect:
|
||||
name<caret>
|
||||
<caret>name
|
||||
|
||||
where:
|
||||
name << [new HashMap(), new TreeMap(), [aaa:1, bbb:2], null]
|
||||
}
|
||||
}
|
||||
""")
|
||||
''', '[java.util.AbstractMap,java.lang.Cloneable,java.io.Serializable]'
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShlMulti1() {
|
||||
doTest(CommonClassNames.JAVA_LANG_STRING, """
|
||||
typingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
def c = { return "1111" }
|
||||
|
||||
expect:
|
||||
name<caret>
|
||||
<caret>name
|
||||
|
||||
where:
|
||||
[x1, _, name] << [['x', 'y', c()], ['x', 'y', null]]
|
||||
}
|
||||
}
|
||||
""")
|
||||
''', JAVA_LANG_STRING
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShlMulti2() {
|
||||
doTest(CommonClassNames.JAVA_LANG_STRING, """
|
||||
typingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
def list = ["a", "b", "c"]
|
||||
|
||||
expect:
|
||||
name<caret>
|
||||
<caret>name
|
||||
|
||||
where:
|
||||
[x1, _, name] << [list, ['aaa', 'bbb', 'ccc']]
|
||||
}
|
||||
}
|
||||
""")
|
||||
''', JAVA_LANG_STRING
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRename() {
|
||||
myFixture.configureByText("FooSpec.groovy", """
|
||||
fixture.configureByText("FooSpec.groovy", """
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
@spock.lang.Unroll("xxx #name a #name #name #name")
|
||||
def "foo test"() {
|
||||
@@ -157,9 +138,9 @@ class FooSpec extends spock.lang.Specification {
|
||||
}
|
||||
""")
|
||||
|
||||
myFixture.renameElementAtCaret("n")
|
||||
fixture.renameElementAtCaret("n")
|
||||
|
||||
myFixture.checkResult("""
|
||||
fixture.checkResult("""
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
@spock.lang.Unroll("xxx #n a #n #n #n")
|
||||
def "foo test"() {
|
||||
@@ -172,9 +153,9 @@ class FooSpec extends spock.lang.Specification {
|
||||
}
|
||||
""")
|
||||
|
||||
myFixture.renameElementAtCaret("z1234567890")
|
||||
fixture.renameElementAtCaret("z1234567890")
|
||||
|
||||
myFixture.checkResult("""
|
||||
fixture.checkResult("""
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
@spock.lang.Unroll("xxx #z1234567890 a #z1234567890 #z1234567890 #z1234567890")
|
||||
def "foo test"() {
|
||||
@@ -186,45 +167,26 @@ class FooSpec extends spock.lang.Specification {
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
}
|
||||
|
||||
|
||||
void checkCompletionStatic(PsiFile file, String... expectedVariants) {
|
||||
myFixture.configureFromExistingVirtualFile(file.getVirtualFile())
|
||||
|
||||
LookupElement[] lookupElements = myFixture.completeBasic()
|
||||
|
||||
assertNotNull(lookupElements)
|
||||
|
||||
Set<String> missedVariants = ContainerUtil.newHashSet(expectedVariants)
|
||||
|
||||
for (LookupElement lookupElement : lookupElements) {
|
||||
missedVariants.remove(lookupElement.getLookupString())
|
||||
}
|
||||
|
||||
assertEmpty("Some completion variants are missed", missedVariants)
|
||||
}
|
||||
|
||||
@Ignore("unignore when IDEA-205861 is fixed")
|
||||
@Test
|
||||
void testVariable_resolved() {
|
||||
myFixture.enableInspections(GroovyAssignabilityCheckInspection, GrUnresolvedAccessInspection)
|
||||
|
||||
myFixture.configureByText("FooSpec.groovy", """\
|
||||
highlightingTest '''\
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
String subscriber = <warning descr="Cannot resolve symbol 'Mock'">Mock</warning>()
|
||||
String subscriber = Mock()
|
||||
then: (0.._) * subscriber.concat<weak_warning descr="Cannot infer argument types">(_)</weak_warning>
|
||||
subscriber.concat<weak_warning descr="Cannot infer argument types">(<warning descr="Cannot resolve symbol 'asdasdasd'">asdasdasd</warning>)</weak_warning>
|
||||
subscriber.concat<warning descr="'concat' in 'java.lang.String' cannot be applied to '(java.lang.Integer)'">(23)</warning>
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
myFixture.checkHighlighting(true, false, true)
|
||||
''', GroovyAssignabilityCheckInspection, GrUnresolvedAccessInspection
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVariable_NotExistingInCompletion() {
|
||||
myFixture.configureByText("FooSpec.groovy", """
|
||||
fixture.configureByText("FooSpec.groovy", """
|
||||
class FooSpec extends spock.lang.Specification {
|
||||
def "foo test"() {
|
||||
String subscriber = Mock()
|
||||
@@ -232,13 +194,17 @@ class FooSpec extends spock.lang.Specification {
|
||||
}
|
||||
}
|
||||
""")
|
||||
myFixture.completeBasic()
|
||||
def elements = myFixture.getLookupElementStrings()
|
||||
assert !elements.contains("_")
|
||||
fixture.completeBasic()
|
||||
def elements = fixture.getLookupElementStrings()
|
||||
assert elements.contains("_")
|
||||
}
|
||||
|
||||
@Ignore("see com.intellij.execution.junit2.inspection.JUnitCantBeStaticExtension")
|
||||
@Test
|
||||
void 'test method may be static'() {
|
||||
myFixture.configureByText 'specs.groovy', '''\
|
||||
def inspection = new GrMethodMayBeStaticInspection()
|
||||
inspection.myIgnoreEmptyMethods = false
|
||||
highlightingTest '''\
|
||||
class SomeSpec extends spock.lang.Specification {
|
||||
def cleanup() {}
|
||||
def setupSpec() {}
|
||||
@@ -247,10 +213,6 @@ class SomeSpec extends spock.lang.Specification {
|
||||
expect: 1 == 1
|
||||
}
|
||||
}
|
||||
'''
|
||||
def inspection = new GrMethodMayBeStaticInspection()
|
||||
inspection.myIgnoreEmptyMethods = false
|
||||
myFixture.enableInspections inspection
|
||||
myFixture.checkHighlighting()
|
||||
''', inspection
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.ext.spock
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.plugins.groovy.GroovyProjectDescriptors
|
||||
import org.jetbrains.plugins.groovy.LibraryLightProjectDescriptor
|
||||
import org.jetbrains.plugins.groovy.RepositoryTestLibrary
|
||||
import org.jetbrains.plugins.groovy.util.LightProjectTest
|
||||
|
||||
abstract class SpockTestBase extends LightProjectTest {
|
||||
|
||||
private static final LightProjectDescriptor SPOCK_PROJECT = new LibraryLightProjectDescriptor(
|
||||
GroovyProjectDescriptors.LIB_GROOVY_2_4 + new RepositoryTestLibrary("org.spockframework:spock-core:1.2-groovy-2.4")
|
||||
)
|
||||
|
||||
@Override
|
||||
final LightProjectDescriptor getProjectDescriptor() {
|
||||
SPOCK_PROJECT
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.util;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -26,9 +25,19 @@ public interface HighlightingTest extends BaseTest {
|
||||
getFixture().testHighlighting(getTestName() + ".groovy");
|
||||
}
|
||||
|
||||
default void highlightingTest(@Language("Groovy") String text) {
|
||||
default void highlightingTest(String text) {
|
||||
getFixture().enableInspections(getInspections());
|
||||
configureByText(text);
|
||||
getFixture().checkHighlighting();
|
||||
}
|
||||
|
||||
default void highlightingTest(String text, LocalInspectionTool... inspections) {
|
||||
getFixture().enableInspections(inspections);
|
||||
highlightingTest(text);
|
||||
}
|
||||
|
||||
default void highlightingTest(String text, Class<? extends LocalInspectionTool>... inspections) {
|
||||
getFixture().enableInspections(inspections);
|
||||
highlightingTest(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.plugins.groovy.util;
|
||||
|
||||
import org.intellij.lang.annotations.Language;
|
||||
@@ -14,6 +14,10 @@ public interface TypingTest extends BaseTest {
|
||||
typingTest(lastExpression(text), expectedType);
|
||||
}
|
||||
|
||||
default void typingTest(@NotNull String text, @Nullable String expectedType) {
|
||||
typingTest(elementUnderCaret(text, GrExpression.class), expectedType);
|
||||
}
|
||||
|
||||
default void typingTest(@NotNull String text, @NotNull Class<? extends GrExpression> clazz, @Nullable String expectedType) {
|
||||
typingTest(elementUnderCaret(text, clazz), expectedType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user