-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix-type-system-issues
- Loading branch information
Showing
21 changed files
with
404 additions
and
81 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...wollok.launch/src/org/uqbar/project/wollok/interpreter/listeners/WollokTestListener.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.uqbar.project.wollok.interpreter.listeners | ||
|
||
import org.eclipse.emf.ecore.EObject | ||
import org.uqbar.project.wollok.interpreter.api.XInterpreterListener | ||
import org.uqbar.project.wollok.sdk.WollokSDK | ||
import org.uqbar.project.wollok.wollokDsl.WBlockExpression | ||
import org.uqbar.project.wollok.wollokDsl.WMemberFeatureCall | ||
|
||
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.* | ||
|
||
class WollokTestListener implements XInterpreterListener { | ||
int messagesToAssert = 0 | ||
|
||
override started() { | ||
} | ||
|
||
override terminated() { | ||
} | ||
|
||
override aboutToEvaluate(EObject element) { | ||
} | ||
|
||
override evaluated(EObject element) { | ||
if (element.hasMessageToAssert) messagesToAssert++ | ||
} | ||
|
||
def dispatch static boolean hasMessageToAssert(EObject e) { false } | ||
|
||
def dispatch static boolean hasMessageToAssert(WMemberFeatureCall call) { | ||
call.memberCallTarget.receiver.equals(WollokSDK.ASSERT_WKO) | ||
} | ||
|
||
def dispatch static boolean hasMessageToAssert(WBlockExpression block) { | ||
block.expressions.exists [ hasMessageToAssert ] | ||
} | ||
|
||
def hasNoAssertions() { | ||
messagesToAssert === 0 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
org.uqbar.project.wollok.launch/src/org/uqbar/project/wollok/launch/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...ar.project.wollok.tests/src/org/uqbar/project/wollok/tests/assertions/AssertionTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.uqbar.project.wollok.tests.assertions | ||
|
||
import org.junit.Test | ||
import org.uqbar.project.wollok.tests.interpreter.AbstractWollokInterpreterTestCase | ||
|
||
/** | ||
* | ||
* @author dodain | ||
*/ | ||
class AssertionTest extends AbstractWollokInterpreterTestCase { | ||
|
||
def shouldFailTestForAssertObject(CharSequence test) { | ||
try { | ||
test.interpretPropagatingErrorsWithoutStaticChecks | ||
fail("Test should have failed") | ||
} catch (Exception e) { | ||
assertEquals(e.cause.message, "No message to 'assert' object was sent") | ||
} | ||
} | ||
|
||
@Test | ||
def void testWithNoAssertShouldFail() { | ||
''' | ||
test "should fail a test with no assert" { | ||
} | ||
'''.shouldFailTestForAssertObject | ||
} | ||
|
||
@Test | ||
def void testUsingAssertButNotSendingAnyMessageShouldFail() { | ||
''' | ||
test "should fail a test using assert but calling no method" { | ||
assert | ||
} | ||
'''.shouldFailTestForAssertObject | ||
} | ||
|
||
@Test | ||
def void testNotCallingAssertInElseShouldFail() { | ||
''' | ||
test "should fail avoid calling assert inside if" { | ||
var a = 5 | ||
if (a > 1) a = 10 else assert.equals(1, 1) | ||
} | ||
'''.shouldFailTestForAssertObject | ||
} | ||
|
||
@Test | ||
def void testNotCallingAssertInIfShouldFail() { | ||
''' | ||
test "should fail avoid calling assert inside else" { | ||
var a = 5 | ||
if (a < 5) assert.equals(1, 1) else a = 10 | ||
} | ||
'''.shouldFailTestForAssertObject | ||
} | ||
|
||
@Test | ||
def void testNotCallingAssertInTryShouldFail() { | ||
''' | ||
test "should fail avoid calling assert inside try" { | ||
try { | ||
} catch e : Exception { | ||
assert.equals(1, 1) | ||
} | ||
} | ||
'''.shouldFailTestForAssertObject | ||
} | ||
|
||
def void testNotCallingAssertInCatchShouldPass() { | ||
''' | ||
test "should fail avoid calling assert inside try" { | ||
try { | ||
1 / 0 | ||
assert.equals(1, 1) | ||
} catch e : Exception { | ||
} | ||
} | ||
'''.interpretPropagatingErrors | ||
} | ||
|
||
@Test | ||
def void testCallingAssertInThenAlwaysShouldNotFail() { | ||
''' | ||
test "should not fail calling assert in then always only" { | ||
try { | ||
1 / 0 | ||
} catch e : Exception { | ||
} then always { | ||
assert.equals(1, 1) | ||
} | ||
} | ||
'''.interpretPropagatingErrorsWithoutStaticChecks | ||
} | ||
|
||
@Test | ||
def void testCallingAssertInBlockShouldNotFail() { | ||
''' | ||
test "should not fail calling assert inside block" { | ||
{ value => assert.equals(value, 1) }.apply(1) | ||
} | ||
'''.interpretPropagatingErrorsWithoutStaticChecks | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ describe "without fixture" { | |
test "test in suite" { | ||
// XPECT type at y --> String | ||
var y = s | ||
assert.that(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/xpect/TestAsserts.wtest.xt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* 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 "testOkTryAndCatchWithAssert" { | ||
try { | ||
assert.equals(1, 1) | ||
} catch e : Exception { | ||
assert.equals(2, 2) | ||
} | ||
} | ||
|
||
test "testOkThenAlwaysWithAssert" { | ||
var a = 0 | ||
try { | ||
a = 1 | ||
} catch e : Exception { | ||
a = 2 | ||
} then always { | ||
assert.equals(1, a) | ||
} | ||
} | ||
|
||
test "testOkTryCatchWithAssertAndThenAlwaysWithoutAssert" { | ||
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 ""testTryCatchWithoutAssert"" | ||
test "testTryCatchWithoutAssert" { | ||
try { | ||
1 / 0 | ||
} catch e : Exception { | ||
1 + 1 | ||
} | ||
} | ||
|
||
test "testCatchWithoutAssert" { | ||
try { | ||
1 / 0 | ||
} catch e : Exception { | ||
assert.equals(1, 1) | ||
1 + 1 | ||
} | ||
} | ||
|
||
test "testTryWithoutAssert" { | ||
try { | ||
assert.equals(1, 1) | ||
1 / 0 | ||
} catch e : Exception { | ||
1 + 1 | ||
} | ||
} | ||
|
||
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testTryCatchThenAlwaysWithoutAssert"" | ||
test "testTryCatchThenAlwaysWithoutAssert" { | ||
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 ""testElseWithoutAssert"" | ||
test "testElseWithoutAssert" { | ||
const a = 1 | ||
if (a > 0) assert.equals(a, 1) | ||
} | ||
|
||
// XPECT warnings --> "Tests must send at least one message to assert object" at ""testIfWithoutAssert"" | ||
test "testIfWithoutAssert" { | ||
var a = 1 | ||
if (a > 0) a = 2 else assert.equals(a, 1) | ||
} |
Oops, something went wrong.