You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Tommy Svensson <to...@natusoft.se> on 2024/05/13 16:45:30 UTC
String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
Here is a test I have been forced to comment out since it is 100% impossible to make work due to ' character keeps getting removed!
assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
No matter what you do here the result will be:
Assertion failed:
assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
| |
| 'LAZY DEVELOPER! This is a Test'
LAZY DEVELOPER! This is a Test
That is the "'" character will be removed in the constant comparison text
and thus the test will always fail, not matter what I do!!!
Any suggestions ?
I'm using release 21 of Groovy.
______________________
Tommy Svensson
tommy@natusoft.se
Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
Posted by Søren Berg Glasius <so...@glasius.dk>.
Hi Tommy,
This works:
class Library {
boolean someLibraryMethod() {
throw new RuntimeException("'" + "LAZY DEVELOPER! This is a test" + "'")
}
boolean someOtherLibraryMethod() {
throw new RuntimeException("'LAZY DEVELOPER! This is a test'")
}
}
class LibraryTest extends Specification {
def lib = new Library()
def "someLibraryMethod returns true"() {
when:
def result = lib.someLibraryMethod()
then:
def e = thrown(RuntimeException)
e.message == "'" + "LAZY DEVELOPER! This is a test" + "'"
e.message == "'LAZY DEVELOPER! This is a test'"
}
def "someOtherLibraryMethod returns true"() {
when:
def result = lib.someOtherLibraryMethod()
then:
def e = thrown(RuntimeException)
e.message == "'" + "LAZY DEVELOPER! This is a test" + "'"
e.message == "'LAZY DEVELOPER! This is a test'"
}
}
With Java 21 (21.0.3-tem) and Groovy 4.0.21
Look at this repo I've created for you
https://github.com/sbglasius/groovy-exception-experiment
Den man. 13. maj 2024 kl. 18.45 skrev Tommy Svensson <to...@natusoft.se>:
> Here is a test I have been forced to comment out since it is 100%
> impossible to make work due to ' character keeps getting removed!
>
> assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
>
>
> No matter what you do here the result will be:
>
> Assertion failed:
>
> assert se3.message == "'" +"LAZY DEVELOPER! This is a
> test" + "'"
> | |
> | 'LAZY DEVELOPER! This is a Test'
> LAZY DEVELOPER! This is a Test
>
> That is the "'" character will be removed in the constant
> comparison text
> and thus the test will always fail, not matter what I do!!!
>
> Any suggestions ?
>
> I'm using release 21 of Groovy.
>
> ______________________
>
> Tommy Svensson
>
> tommy@natusoft.se
>
>
>
>
--
Med venlig hilsen,
Søren Berg Glasius
Hedevej 1, Gl. Rye, 8680 Ry
Mobile: +45 40 44 91 88
--- Press ESC once to quit - twice to save the changes.
Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
Posted by OCsite <oc...@ocs.cz>.
Tommy,
I am afraid I do not quite follow you. The assert seems to work all right, far as I can say:
===
1029 ocs /tmp> <q.groovy
def msg="'LAZY DEVELOPER! This is a test'"
assert msg == "'" +"LAZY DEVELOPER! This is a test" + "'"
println 'all ok'
1030 ocs /tmp> /usr/local/groovy-4.0.21/bin/groovy q
all ok
1031 ocs /tmp>
===
Do I overlook something of importance here?
All the best,
OC
> On 13. 5. 2024, at 18:45, Tommy Svensson <to...@natusoft.se> wrote:
>
> Here is a test I have been forced to comment out since it is 100% impossible to make work due to ' character keeps getting removed!
>
> assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
>
>
> No matter what you do here the result will be:
>
> Assertion failed:
>
> assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
> | |
> | 'LAZY DEVELOPER! This is a Test'
> LAZY DEVELOPER! This is a Test
>
> That is the "'" character will be removed in the constant comparison text
> and thus the test will always fail, not matter what I do!!!
>
> Any suggestions ?
>
> I'm using release 21 of Groovy.
>
> ______________________
> Tommy Svensson
> tommy@natusoft.se <ma...@natusoft.se>
Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
Posted by Tommy Svensson <to...@natusoft.se>.
> While I don't know exactly what the se3 object is
A very good point! :-)
> The assert call does something a bit interesting with what it displays for the comparisons. For everything EXCEPT for the final object being compared, it does _NOT_ show single quotes around Strings.
Hmm, interesting! This really confused me!
Thanks!
______________________
Tommy Svensson
tommy@natusoft.se
Från: Spencer Allain via users <us...@groovy.apache.org>
Svara: users@groovy.apache.org <us...@groovy.apache.org>, Spencer Allain <sp...@yahoo.com>
Datum: 13 maj 2024 at 21:19:26
Till: users@groovy.apache.org <us...@groovy.apache.org>
Ämne: Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
While I don't know exactly what the se3 object is
Re: String comparison tests on exception messages keep failing due to >'< character keeps getting removed!
Posted by Spencer Allain via users <us...@groovy.apache.org>.
While I don't know exactly what the se3 object is, I suspect it has a String message property, and the toString() method displays the content of the String, such as below.
Object se3 = new Object() { String message String toString() { message }}
se3.message = 'LAZY DEVELOPER! This is a Test'
assert se3.message == "'LAZY DEVELOPER! This is a Test'"
Output:assert se3.message == "'LAZY DEVELOPER! This is a Test'"
| | | | | false | 'LAZY DEVELOPER! This is a Test' LAZY DEVELOPER! This is a Test
The assert call does something a bit interesting with what it displays for the comparisons. For everything EXCEPT for the final object being compared, it does _NOT_ show single quotes around Strings.
If you alter the assert to compare against an object instead of a constant, it might be more obvious what is happening:
Object se3 = new Object() { String message String toString() { message }}
se3.message = 'LAZY DEVELOPER! This is a Test'String testMessage = "'LAZY DEVELOPER! This is a Test'"
assert se3.message == testMessage
Output:assert se3.message == testMessage
| | | | | | | '\'LAZY DEVELOPER! This is a Test\'' | | false | 'LAZY DEVELOPER! This is a Test' LAZY DEVELOPER! This is a Test
-Spencer
On Monday, May 13, 2024 at 12:46:02 PM EDT, Tommy Svensson <to...@natusoft.se> wrote:
Here is a test I have been forced to comment out since it is 100% impossible to make work due to ' character keeps getting removed!
assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'"
No matter what you do here the result will be:
Assertion failed:
assert se3.message == "'" +"LAZY DEVELOPER! This is a test" + "'" | | | 'LAZY DEVELOPER! This is a Test' LAZY DEVELOPER! This is a Test
That is the "'" character will be removed in the constant comparison text and thus the test will always fail, not matter what I do!!!
Any suggestions ?
I'm using release 21 of Groovy.
______________________
Tommy Svensson
tommy@natusoft.se