Skip to content

Commit f4fe251

Browse files
add shortFailureText to be use
1 parent bd618c1 commit f4fe251

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

sqldev/src/main/java/org/utplsql/sqldev/model/runner/Expectation.xtend

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.utplsql.sqldev.model.runner
1717

18+
import java.util.regex.Pattern
1819
import org.eclipse.xtend.lib.annotations.Accessors
1920
import org.utplsql.sqldev.model.AbstractModel
2021

@@ -30,4 +31,18 @@ class Expectation extends AbstractModel {
3031
«caller.trim»
3132
'''.toString.trim
3233
}
34+
35+
def getShortFailureText() {
36+
return '''«IF description !== null»«description» (line «callerLine»)«ELSE»Line «callerLine»«ENDIF»'''.toString
37+
}
38+
39+
def getCallerLine() {
40+
var Integer line = null
41+
val p = Pattern.compile("(?i)\"[^\\\"]+\",\\s+line\\s*([0-9]+)")
42+
val m = p.matcher(caller)
43+
if (m.find) {
44+
line = Integer.valueOf(m.group(1))
45+
}
46+
return line
47+
}
3348
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.utplsql.sqldev.test.runner
2+
3+
import org.junit.Assert
4+
import org.junit.Before
5+
import org.junit.Test
6+
import org.utplsql.sqldev.model.runner.Expectation
7+
8+
class ExpectationTest {
9+
var Expectation exceptionWithDescription
10+
var Expectation exceptionWithoutDescription
11+
12+
@Before
13+
def void setup() {
14+
exceptionWithDescription = new Expectation
15+
exceptionWithDescription.description = '''This assert must fail'''
16+
exceptionWithDescription.message = '''at: 1 (number) was expected to equal: 2 (number)'''
17+
exceptionWithDescription.caller = '''"SCOTT.JUNIT_UTPLSQL_TEST1_PKG.TEST_2_NOK", line 14 ut.expect(1, 'This assert must fail').to_equal(2);'''
18+
exceptionWithoutDescription = new Expectation
19+
exceptionWithoutDescription.message = exceptionWithDescription.message
20+
exceptionWithoutDescription.caller = exceptionWithDescription.caller
21+
exceptionWithoutDescription.message = '''at: 1 (number) was expected to equal: 2 (number)'''
22+
exceptionWithoutDescription.caller = '''"SCOTT.JUNIT_UTPLSQL_TEST1_PKG.TEST_3_NOK", line 42 ut.expect(1).to_equal(2);'''
23+
}
24+
25+
@Test
26+
def void failedExpectationCallerLine() {
27+
val actual = exceptionWithDescription.callerLine
28+
val expected = new Integer(14)
29+
Assert.assertEquals(expected, actual)
30+
}
31+
32+
@Test
33+
def void shortFailureTextWithDescription() {
34+
val actual = exceptionWithDescription.shortFailureText
35+
val expected = 'This assert must fail (line 14)'
36+
Assert.assertEquals(expected, actual)
37+
}
38+
39+
@Test
40+
def void shortFailureTextWithoutDescription() {
41+
val actual = exceptionWithoutDescription.shortFailureText
42+
val expected = 'Line 42'
43+
Assert.assertEquals(expected, actual)
44+
}
45+
46+
}

0 commit comments

Comments
 (0)