Closed fdodino closed 3 years ago
Uh, no me deja contestarte en la conversación @PalumboN . Lo de los ifs lo estoy viendo, pasa que arranqué UNSAM y eso me saca tiempo. Lo de no hacer el chequeo de cantidad de asserts en Wollok es porque efectivamente hay que chequear en varios métodos, ademaś de tener que resetear el contador en algún momento.
@PalumboN , fijate estos tests que estoy agregando, son validaciones estáticas
/* XPECT_SETUP org.uqbar.project.wollok.tests.xpect.WollokXPectTest END_SETUP */
import wollok.lib.assert
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testWithBinaryOperation""
test "testWithBinaryOperation" {
1 + 1
}
test "okTest" {
assert.equals(1, 1.0)
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testForVariable""
test "testForVariable" {
assert
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testForBinaryOperationForAssert""
test "testForBinaryOperationForAssert" {
assert + 1
}
test "testOkTryWithAssert" {
try {
assert.equals(1, 1)
} catch e : Exception {
assert.equals(2, 2)
}
}
test "testOkCatchWithAssert" {
try {
assert.equals(2, 2)
} catch e : Exception {
assert.equals(1, 1)
}
}
test "testOkTryThenAlwaysWithAssert" {
var a
try {
a = 0
assert.equals(2, 2)
} then always {
assert.equals(0, a)
}
}
test "testOkTryCatchThenAlwaysWithAssert" {
var a = 0
try {
a = 1
} catch e : Exception {
a = 2
} then always {
assert.equals(1, a)
}
}
test "testOkTryCatchThenAlwaysWithAssert2" {
try {
assert.equals(2, 2)
} catch e : Exception {
assert.equals(1, 1)
} then always {
}
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testNotOkIfWithAssertOnlyInThen""
test "testNotOkIfWithAssertOnlyInThen" {
const a = 1
if (a > 0) assert.equals(a, 1)
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testNotOkIfWithAssertOnlyInElse""
test "testNotOkIfWithAssertOnlyInElse" {
var a = 1
if (a > 0) { a = a + 1 } else assert.equals(a, 1)
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testBadTryCatchWithAssert""
test "testBadTryCatchWithAssert" {
try {
1 / 0
} catch e : Exception {
1 + 1
}
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testBadTryCatchThenAlwaysWithAssert""
test "testBadTryCatchThenAlwaysWithAssert" {
var a = 0
try {
a = 1
} catch e : Exception {
a = 2
} then always {
a = 3
}
}
test "testOkIfWithAssert" {
const a = 1
if (a > 0) assert.equals(a, 1) else assert.equals(2, 2)
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testBadIfWithAssert""
test "testBadIfWithAssert" {
const a = 1
if (a > 0) assert.equals(a, 1)
}
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testBadIfElseWithAssert""
test "testBadIfElseWithAssert" {
var a = 1
if (a > 0) a = 2 else assert.equals(a, 1)
}
me interesa cubrir los try/catch y los if/else en sus variantes. La del try/catch la pensé y recuerdo que me pasó armar mal el test con un falso positivo porque usaba un catch y el try no tenía el assert.fail
correspondiente. Me hubiera venido bien.
@fdodino ok con los tests!! No falta justo el caso que mencionás (try sin assert, catch sí)??
Lo de no hacer el chequeo de cantidad de asserts en Wollok es porque efectivamente hay que chequear en varios métodos, ademaś de tener que resetear el contador en algún momento.
Sí, lo de tocar varios métodos lo suponía. Igual no son muchos si comparamos por ejemplo con coerceToNumber
, es solo un objeto. Entiendo que el contado no habría que resetearlo porque los wko se reinician en cada test. Lo que sí había que hacer es mandar el mensaje assert.verifyCalled()
al final de cada test.
Igual si esto ya lo tenés andando mandale así, pero me gustaba esa implementación del lado de Wollok para no tener que poner esa lógica en la(s) VM(s).
Hola @PalumboN , ahí estuve puliendo un poco el tema de los tests de validación estático y también agregué tests de runtime, verificando que fallen los tests cuando los ejecutás. Esto lo tuve que hacer directamente en Wollok Xtext, porque no puedo armar un test que corra otro test esperando que falle (el nivel de metaprogramación me dio overflow en el bocho).
Creeeo que si no se me pasó nada estaría ya para mergear. Gracias por los comentarios!
Acá no falta un fail en el caso que no falle? Uf, qué bueno que estaría tener el feature que implementamos en los tests posta...
Coverage decreased (-0.002%) to 83.946% when pulling b8222503fbe5109c59b7afcb65036476150f8ddb on assert-enhancements into 3c785836cb99e91dcf7e7261df6492db00f55fe8 on dev.