New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad assertion message when using multi-line string literals with escaped initial new-line in assertion block #737

Closed
ddimtirov opened this Issue Jun 4, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@ddimtirov

ddimtirov commented Jun 4, 2017

Issue description

See the test case in this gist - there are 3 identical tests comparing strings. All tests are working, as in failing and passing when they should.

The problem is that the assertion messages are bad for the variants that have a multi-line string literal with escaped initial new-line in the assertion block (regardless whether using expect or then block).

The gist also has example of a good and bad assertion messages.

Additional Environment information

dkhamitov added a commit to dkhamitov/spock that referenced this issue Jun 24, 2017

@dkhamitov

This comment has been minimized.

Show comment
Hide comment
@dkhamitov

dkhamitov Jun 24, 2017

Contributor

The problem is that unit.parse()(at

) fails to parse the expression because it meets a single backslash (not followed by a new line, neither escaped). The purpose of a backslash here is to strip a new line, given that it is followed by a newline character. The possible solution (not the best, I suspect) is that If we can see this is the case in a spec, then we can just remove that single backslash and pass the safe expression to unit.parse(). Here is an example of failure:

def unit = SourceUnit.create("Spec expression", '"""foo""" == """\\bar"""')
unit.parse() //fails
Contributor

dkhamitov commented Jun 24, 2017

The problem is that unit.parse()(at

) fails to parse the expression because it meets a single backslash (not followed by a new line, neither escaped). The purpose of a backslash here is to strip a new line, given that it is followed by a newline character. The possible solution (not the best, I suspect) is that If we can see this is the case in a spec, then we can just remove that single backslash and pass the safe expression to unit.parse(). Here is an example of failure:

def unit = SourceUnit.create("Spec expression", '"""foo""" == """\\bar"""')
unit.parse() //fails

dkhamitov added a commit to dkhamitov/spock that referenced this issue Aug 5, 2017

Issue-737 Bad assertion message when using string literals with newli…
…ne escapes (spockframework#737)

* do not allocate redundant string
* make tenary more readable

dkhamitov added a commit to dkhamitov/spock that referenced this issue Aug 5, 2017

Issue-737 Bad assertion message when using string literals with newli…
…ne escapes (spockframework#737)

* rename captured groups in regexp
* simplify regexp

dkhamitov added a commit to dkhamitov/spock that referenced this issue Aug 6, 2017

Issue-737 Bad assertion message when using string literals with newli…
…ne escapes (spockframework#737)

* add a test on long text broken over multiple lines

dkhamitov added a commit to dkhamitov/spock that referenced this issue Aug 6, 2017

dkhamitov added a commit to dkhamitov/spock that referenced this issue Aug 7, 2017

leonard84 added a commit that referenced this issue Aug 8, 2017

@leonard84

This comment has been minimized.

Show comment
Hide comment
@leonard84

leonard84 Jul 7, 2018

Member

PR was merged closing

Member

leonard84 commented Jul 7, 2018

PR was merged closing

@leonard84 leonard84 closed this Jul 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment