Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ValueRecorder reset() {
* Records and returns the specified value. Hence an expression can be replaced
* with record(expression) without impacting evaluation of the expression.
*/
public Object record(int index, Object value) {
public <T> T record(int index, T value) {
realizeNas(index + 1, null);
values.set(index, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,75 @@
package org.spockframework.smoke

import org.spockframework.EmbeddedSpecification
import org.spockframework.runtime.ConditionNotSatisfiedError

import spock.lang.Issue
import spock.lang.Specification

class StaticTypeChecking extends EmbeddedSpecification {

@Issue("https://github.com/spockframework/spock/issues/2343")
def "preserves receiver types in conditions"(String visibility, String condition) {
when:
runner.runWithImports("""
@groovy.transform.TypeChecked
class Example extends Specification {
$visibility String myField

def feature() {
$condition
}
}
""")

then:
noExceptionThrown()

where:
[visibility, condition] << [["", "public"], ["""
when:
this.myField = 'value'

then:
this.myField == 'value'
""", """
expect:
this.myField == null
""", """
when:
this.myField = 'value'
assert this.myField == 'value'

then:
true
"""]].combinations()
}

@Issue("https://github.com/spockframework/spock/issues/2343")
def "records values in failing type checked conditions"(String value) {
when:
runner.runWithImports("""
@groovy.transform.TypeChecked
class Example extends Specification {
String myField = $value

def feature() {
expect:
this.myField != $value
}
}
""")

then:
def error = thrown(ConditionNotSatisfiedError)
def values = error.condition.values
values[0] instanceof Specification
values[1] == values[0].myField
values[2..3] == [values[1], false]

where:
value << ["'value'", "null"]
}

def "correctly spelled setup compiles successfully"() {
when:
Expand Down