uqbar-project / wollok

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

[repl] Generate assert statements when exporting REPL session as wollok test #384

Open javierfernandes opened 9 years ago

javierfernandes commented 9 years ago

Currently it just generates code based on the "inputs" the user wrote on the REPL.

For example: this session

Wollok interactive console (type "quit" to quit): 
>>> pepe
pepe[categoria=null]
>>> pepe.setCategoria(categoria.gerente())>>> 
>>> 
>>> pepe.sueldoBase()
2500
>>> pepe.setCategoria(categoria.cadete())
>>> pepe.sueldoBase()
2700
>>> pepe.setCategoria(categoria.jefe
())>>> pepe.sueldoBase()
2600
>>> 

The exported test is

test "exported test from REPL session" {
    pepe.setCategoria(categoria.gerente())
    pepe.sueldoBase()
    pepe.setCategoria(categoria.cadete())
    pepe.sueldoBase()
    pepe.setCategoria(categoria.jefe())
    pepe.sueldoBase()

}

As one can see there are no assert statements, because it is only the input lines. Usually when using the REPL we mentally do the assert by looking at the output.

So two options here. Generate the asserts automatically based on the output

test "exported test from REPL session" {
    pepe.setCategoria(categoria.gerente())
    assert.equals(2500, pepe.sueldoBase())

    pepe.setCategoria(categoria.cadete())
    assert.equals(2700, pepe.sueldoBase())

    pepe.setCategoria(categoria.jefe())
    assert.equals(2600, pepe.sueldoBase())

}

The other option is to assume that we cannot be such smart to generate that (2700 in this case should be a string comparisson ?) and at least generate the output as comments for each line

test "exported test from REPL session" {
    pepe.setCategoria(categoria.gerente())
    pepe.sueldoBase() // 2500

    pepe.setCategoria(categoria.cadete())
    pepe.sueldoBase() // 2700

    pepe.setCategoria(categoria.jefe())
    pepe.sueldoBase() // 2600

}
npasserini commented 9 years ago

Crazy idea, why not have REPL not be only text? What if the result of executing an expression can be shown as a smarter component?

Regarding this particular issue, this means that you remember in the repl that "pepe.sueldoBase()" returned a number, and not just "that it printed 2700"

But going further, we could have smarter visualizations for the results of the repl expressions, which would be great because showing the "toString" always confuses students!

On Thu, Nov 12, 2015 at 11:18 AM, javierfernandes notifications@github.com wrote:

Currently it just generates code based on the "inputs" the user wrote on the REPL.

For example: this session

Wollok interactive console (type "quit" to quit): �[m �[36m>>> �[mpepe �[34mpepe[categoria=null]�[m �[36m>>> �[mpepe.setCategoria(categoria.gerente())�[36m>>> �[m �[36m>>> �[m �[36m>>> �[mpepe.sueldoBase() �[34m2500�[m �[36m>>> �[mpepe.setCategoria(categoria.cadete()) �[36m>>> �[mpepe.sueldoBase() �[34m2700�[m �[36m>>> �[mpepe.setCategoria(categoria.jefe ())�[36m>>> �[mpepe.sueldoBase() �[34m2600�[m �[36m>>> �[m

The exported test is

test "exported test from REPL session" { pepe.setCategoria(categoria.gerente()) pepe.sueldoBase() pepe.setCategoria(categoria.cadete()) pepe.sueldoBase() pepe.setCategoria(categoria.jefe()) pepe.sueldoBase()

}

As one can see there are no assert statements, because it is only the input lines. Usually when using the REPL we mentally do the assert by looking at the output.

So two options here. Generate the asserts automatically based on the output

test "exported test from REPL session" { pepe.setCategoria(categoria.gerente()) assert.equals(2500, pepe.sueldoBase())

pepe.setCategoria(categoria.cadete())
assert.equals(2700, pepe.sueldoBase())

pepe.setCategoria(categoria.jefe())
assert.equals(2600, pepe.sueldoBase())

}

The other option is to assume that we cannot be such smart to generate that (2700 in this case should be a string comparisson ?) and at least generate the output as comments for each line

test "exported test from REPL session" { pepe.setCategoria(categoria.gerente()) pepe.sueldoBase() // 2500

pepe.setCategoria(categoria.cadete())
pepe.sueldoBase() // 2700

pepe.setCategoria(categoria.jefe())
pepe.sueldoBase() // 2600

}

— Reply to this email directly or view it on GitHub https://github.com/uqbar-project/wollok/issues/384.