Skip to content

Commit

Permalink
Fix #1223 - const initialization in a fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Sep 15, 2017
1 parent dac2825 commit eb13c3b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ class WollokLauncherInterpreterEvaluator extends WollokInterpreterEvaluator {
// If in a suite, we should create a suite wko so this will be our current context to eval the tests
try {
val suiteObject = new SuiteBuilder(suite, interpreter).forTest(test).build
if (suite.fixture !== null) {
suite.fixture.elements.forEach [ element |
interpreter.performOnStack(test, suiteObject, [|element.eval])
]
}
interpreter.performOnStack(test, suiteObject, [ | test.eval])
} catch (Exception e) {
handleExceptionInTest(e, test)
Expand Down Expand Up @@ -132,9 +127,16 @@ class SuiteBuilder {
suite.members.forEach [ member |
suiteObject.addMember(member)
]
if (suite.fixture !== null) {
suite.fixture.elements.forEach [ element |
interpreter.performOnStack(test, suiteObject, [| interpreter.eval(element) ])
]
}
if (test !== null) {
// Now, declaring test local variables as suite wko instance variables
test.variableDeclarations.forEach[variable|suiteObject.addMember(variable)]
test.variableDeclarations.forEach[ variable |
suiteObject.addMember(variable)
]
}
suiteObject
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,37 @@ class TestDescribeTestCase extends AbstractWollokInterpreterTestCase {
}
'''.interpretPropagatingErrors
}

@Test
def void testIssue1221NPEForConstDefinedInFixtures() {
'''
class Enfermo {}
class Doctor {
var calidad = 0
method calidad() = calidad
method calidad(_calidad) { calidad = _calidad }
method cura(alguien) { calidad = calidad + 1 }
}
describe "issue 1223" {
var unDoctorCualquiera
var enfermo
fixture {
enfermo = new Enfermo()
unDoctorCualquiera = new Doctor()
unDoctorCualquiera.calidad(2)
}
test "si un doctor cura a un enfermo, la calidad del doctor aumenta" {
const calidadInicial = unDoctorCualquiera.calidad()
unDoctorCualquiera.cura(enfermo)
const calidadFinal = unDoctorCualquiera.calidad()
assert.that(calidadFinal > calidadInicial)
}
}
'''.interpretPropagatingErrors
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>

def dispatch evaluate(WSuite it) {
tests.fold(null) [ a, test |
it.members.forEach[m|evaluate(m)]
members.forEach[m|evaluate(m)]
fixture.elements.forEach [ evaluate ]
test.eval
]
}
Expand Down Expand Up @@ -359,7 +360,7 @@ class WollokInterpreterEvaluator implements XInterpreterEvaluator<WollokObject>

def createCollection(String collectionName, List<WExpression> elements) {
newInstance(collectionName) => [
elements.forEach [ e |
elements.forEach [ e |
call("add", e.eval)
]
]
Expand Down

0 comments on commit eb13c3b

Please sign in to comment.