uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Assert enhancements #1982

Closed fdodino closed 3 years ago

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.002%) to 83.946% when pulling b8222503fbe5109c59b7afcb65036476150f8ddb on assert-enhancements into 3c785836cb99e91dcf7e7261df6492db00f55fe8 on dev.

fdodino commented 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.

fdodino commented 3 years ago

@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.

PalumboN commented 3 years ago

@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).

fdodino commented 3 years ago

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!

fdodino commented 3 years ago

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...