Skip to content

Commit

Permalink
PR review fixes - undoing fixes for #1772 & #1797 since we are going …
Browse files Browse the repository at this point in the history
…to tackle toString issue in a separate ticket
  • Loading branch information
fdodino committed Oct 5, 2019
1 parent c64e572 commit 788cf88
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ class WollokLauncher extends WollokChecker {

interpreter.interpret(filesToParse.parse(parameters), parameters.folder)
System.exit(0)
} catch (WollokTestsFailedException e) {
throw e
} catch (Exception e) {
if (e instanceof WollokTestsFailedException) {
throw e
}
System.exit(-1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import static org.fusesource.jansi.Ansi.*
import static org.fusesource.jansi.Ansi.Color.*

import static extension org.uqbar.project.wollok.errorHandling.WollokExceptionExtensions.*
import static extension org.uqbar.project.wollok.utils.StringUtils.*

/**
* Logs the events to the console output.
Expand Down Expand Up @@ -39,7 +40,7 @@ class WollokConsoleTestsReporter extends DefaultWollokTestsReporter {
if (suiteName ?: '' !== '') {
println('''Running all tests from describe «suiteName»''')
} else {
println('''Running «tests.size» test«if (tests.size !== 1) "s"»...''')
println('''Running «tests.size.singularOrPlural("test")» ...''')
}
testsRun += tests.size
testsGroupRun += tests.size
Expand Down Expand Up @@ -126,9 +127,9 @@ class WollokConsoleTestsReporter extends DefaultWollokTestsReporter {
println(ansi
.fg(STATUS)
.bold
.a(totalTests).a(if (totalTests == 1) " test, " else " tests, ")
.a(failedTests).a(if (failedTests == 1) " failure and " else " failures and ")
.a(erroredTests).a(if (erroredTests == 1) " error" else " errors")
.a(totalTests.singularOrPlural("test")).a(", ")
.a(failedTests.singularOrPlural("failure")).a(" and ")
.a(erroredTests.singularOrPlural("error"))
.a("\n")
.a("Total time: ").a(millisecondsElapsed).a("ms")
.a("\n")
Expand Down
7 changes: 3 additions & 4 deletions org.uqbar.project.wollok.lib/src/wollok/lang.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ class Object {

/** @private */
method internalToSmartString(alreadyShown) {
const hasInstanceVariables = !self.instanceVariables().isEmpty()
return self.kindName() + (if (hasInstanceVariables) "<" else "")
return self.kindName() + "["
+ self.instanceVariables().map { v =>
v.name() + "=" + v.valueToSmartString(alreadyShown)
}.join(', ')
+ (if (hasInstanceVariables) ">" else "")
}.join(', ')
+ "]"
}

/** @private */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class ExceptionTestCase extends AbstractWollokInterpreterTestCase {
}
catch e : MessageNotUnderstoodException {
// ok !
assert.equals("a A does not understand m2()", e.message())
assert.equals("a A[] does not understand m2()", e.message())
}
}
'''.interpretPropagatingErrors
Expand All @@ -200,7 +200,7 @@ class ExceptionTestCase extends AbstractWollokInterpreterTestCase {
}
catch e : MessageNotUnderstoodException {
// ok !
assert.equals("a A does not understand m1(). However other methods exist with different argument count: m1(a)", e.message())
assert.equals("a A[] does not understand m1(). However other methods exist with different argument count: m1(a)", e.message())
}
}
'''.interpretPropagatingErrors
Expand All @@ -225,7 +225,8 @@ class ExceptionTestCase extends AbstractWollokInterpreterTestCase {
}
catch e : MessageNotUnderstoodException {
// ok !
assert.equals("a A does not understand M1(param1). However other similar methods exist: m1(a)", e.message())
assert.equals("a A[] does not understand M1(param1). However other similar methods exist: m1(a)", e.message())
// assert.equals("Wrong case-sensitive message M1(param1) sent to a A[]. Use m1(a)", e.message())
}
}
'''.interpretPropagatingErrors
Expand All @@ -250,7 +251,7 @@ class ExceptionTestCase extends AbstractWollokInterpreterTestCase {
}
catch e : MessageNotUnderstoodException {
// ok !
assert.equals("a A does not understand m1(param1, param2). However other methods exist with different argument count: m1(a)", e.message())
assert.equals("a A[] does not understand m1(param1, param2). However other methods exist with different argument count: m1(a)", e.message())
}
}
'''.interpretPropagatingErrors
Expand Down Expand Up @@ -313,7 +314,7 @@ class ExceptionTestCase extends AbstractWollokInterpreterTestCase {
}
catch e : MessageNotUnderstoodException {
// ok !
assert.equals("a A does not understand m2(param1, param2)", e.message())
assert.equals("a A[] does not understand m2(param1, param2)", e.message())
}
}
'''.interpretPropagatingErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ListTestCase extends CollectionTestCase {
)
*/
assert.throwsExceptionWithMessage(
"Expected [[a]] but found [[a B]]",
"Expected [[a[]]] but found [[a B[]]]",
{ assert.equals([ a ], [ new B() ]) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class PropertiesTestCase extends AbstractWollokInterpreterTestCase {
try {
pepita.energia(10, "hola")
} catch e : Exception {
assert.equals("pepita<energia=0> does not understand energia(param1, param2)", e.message())
assert.equals("pepita[energia=0] does not understand energia(param1, param2)", e.message())
}
}
'''.interpretPropagatingErrorsWithoutStaticChecks
Expand Down Expand Up @@ -183,7 +183,7 @@ class PropertiesTestCase extends AbstractWollokInterpreterTestCase {
try {
pepita.energia(10, [21, 1])
} catch e : Exception {
assert.equals("a Ave<energia=0> does not understand energia(param1, param2)", e.message())
assert.equals("a Ave[energia=0] does not understand energia(param1, param2)", e.message())
}
}
'''.interpretPropagatingErrorsWithoutStaticChecks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RecursiveToStringTestCase extends AbstractWollokInterpreterTestCase {
obj2.setY(obj1)
obj1.addX(new Prb())
assert.equals('obj2<y=obj1<x=[obj2, a Prb]>>', obj2.toString())
assert.equals('obj2[y=obj1[x=[obj2, a Prb[]]]]', obj2.toString())
}
'''.interpretPropagatingErrors
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class RecursiveToStringTestCase extends AbstractWollokInterpreterTestCase {
cuenta.duenios().add(duenio)
cuenta.metodoInexistente()
} catch e {
assert.equals("a Cuenta<duenios=[a Duenio<cuentas=[a Cuenta]>]> does not understand metodoInexistente()", e.message())
assert.equals("a Cuenta[duenios=[a Duenio[cuentas=[a Cuenta]]]] does not understand metodoInexistente()", e.message())
}
}
'''.interpretPropagatingErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class SetTestCase extends CollectionTestCase {
)
*/
assert.throwsExceptionWithMessage(
"Expected [#{a}] but found [#{a B}]",
"Expected [#{a[]}] but found [#{a B[]}]",
{ assert.equals(#{a}, #{new B()}) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import static extension org.uqbar.project.wollok.errorHandling.WollokExceptionEx

/**
* @author tesonep
* @author jfernades
* @author jfernandes
*/
class TestTestCase extends AbstractWollokInterpreterTestCase {

Expand Down Expand Up @@ -157,7 +157,7 @@ class TestTestCase extends AbstractWollokInterpreterTestCase {
assert.throwsExceptionLike(new BusinessException("chau"), { => throw new BusinessException("hola") })
}
catch ex {
assert.equals(ex.message(), 'The Exception expected was a BusinessException<message="chau", cause=null> but got a BusinessException<message="hola", cause=null>')
assert.equals(ex.message(), 'The Exception expected was a BusinessException[message="chau", cause=null] but got a BusinessException[message="hola", cause=null]')
}
}
'''.interpretPropagatingErrors
Expand All @@ -177,7 +177,7 @@ class TestTestCase extends AbstractWollokInterpreterTestCase {
assert.throwsExceptionLike(new BusinessException(), { => throw new OtherBusinessException() })
}
catch ex {
assert.equals(ex.message(), "The Exception expected was a BusinessException<message=null, cause=null> but got a OtherBusinessException<message=null, cause=null>")
assert.equals(ex.message(), "The Exception expected was a BusinessException[message=null, cause=null] but got a OtherBusinessException[message=null, cause=null]")
}
}
'''.interpretPropagatingErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ class MixinsTestCase extends AbstractWollokInterpreterTestCase {
t.dehydratate()
}
catch e:MessageNotUnderstoodException {
assert.equals("a Tomato (WollokObject) does not understand dehydratate()", e.message())
assert.equals("wollok.lang.MessageNotUnderstoodException: a Tomato (WollokObject) does not understand dehydratate()
assert.equals("a Tomato[] (WollokObject) does not understand dehydratate()", e.message())
assert.equals("wollok.lang.MessageNotUnderstoodException: a Tomato[] (WollokObject) does not understand dehydratate()
at __synthetic0.Organic.dehydratate() [__synthetic0.wpgm]
at [__synthetic0.wpgm]
", e.getStackTraceAsString())
Expand Down Expand Up @@ -539,7 +539,7 @@ class MixinsTestCase extends AbstractWollokInterpreterTestCase {
«toStringFixture»
test "toString de un mixed method container con 1 mixin" {
const pm = new Persona() with EnvejeceDoble
assert.equals(pm.toString(), "Persona with EnvejeceDoble<edad=10>")
assert.equals(pm.toString(), "Persona with EnvejeceDoble[edad=10]")
}
'''.interpretPropagatingErrors
}
Expand All @@ -550,7 +550,7 @@ class MixinsTestCase extends AbstractWollokInterpreterTestCase {
«toStringFixture»
test "toString de un mixed method container con 2 mixins" {
const pm = new Persona() with EnvejeceDoble with EnvejeceTriple
assert.equals(pm.toString(), "Persona with EnvejeceDoble with EnvejeceTriple<edad=10>")
assert.equals(pm.toString(), "Persona with EnvejeceDoble with EnvejeceTriple[edad=10]")
}
'''.interpretPropagatingErrors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class GameTest extends AbstractWollokInterpreterTestCase {
def void addSameObjectToGameShouldFail() {
'''
«position(0,0)».drawElement(myVisual)
assert.throwsExceptionWithMessage("myVisual is already in the game.", { «position(1,1)».drawElement(myVisual) })
assert.throwsExceptionWithMessage("myVisual[] is already in the game.", { «position(1,1)».drawElement(myVisual) })
'''.gameTest
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class ObjectTest extends AbstractWollokInterpreterTestCase {
program p {
const perro = new Perro()
assert.equals('a Perro<nombre="Colita", edad=7>', perro.toString())
assert.equals('casa<direccion="San Juan 1234", ambientes=3>', casa.toString())
assert.equals('a Perro[nombre="Colita", edad=7]', perro.toString())
assert.equals('casa[direccion="San Juan 1234", ambientes=3]', casa.toString())
const anonymousObject = object {
var edad = 23
var altura = 2
}
assert.equals("an Object<edad=23, altura=2>", anonymousObject.toString())
assert.equals("an Object[edad=23, altura=2]", anonymousObject.toString())
}
'''.interpretPropagatingErrors
}
Expand All @@ -48,7 +48,7 @@ class ObjectTest extends AbstractWollokInterpreterTestCase {
}
program p {
assert.equals("persona<edad=23, altura=1.7>", persona.toString())
assert.equals("persona[edad=23, altura=1.7]", persona.toString())
}
'''.interpretPropagatingErrors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PositionTest extends AbstractWollokParameterizedInterpreterTest {
}
program p {
assert.throwsExceptionWithMessage("visual<position=a Position<x=0, y=0>> does not understand position()", { game.addVisual(visual) })
assert.throwsExceptionWithMessage("visual[position=a Position[x=0, y=0]] does not understand position()", { game.addVisual(visual) })
}'''.interpretPropagatingErrors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ class StringUtils {
val float seconds = milliseconds / 1000f
new DecimalFormat("##########.###").format(seconds)
}

static def singularOrPlural(int amount, String text) {
"" + amount + " " + amount.singularOrPlural(text, text + "s")
}

static def singularOrPlural(int amount, String text, String pluralText) {
if (amount === 1) text else pluralText
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ class WollokDslValidator extends AbstractConfigurableDslValidator {
@DefaultSeverity(WARN)
@CheckGroup(WollokCheckGroup.POTENTIAL_DESIGN_PROBLEM)
def testWithEmptyDescription(WTest it) {
if ((name ?: "").equals(""))
if (name.nullOr[equals("")])
report(WollokDslValidator_TEST_WITH_EMPTY_DESCRIPTION, it, WTEST__NAME)
}

Expand Down

0 comments on commit 788cf88

Please sign in to comment.