Skip to content
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

Make Pretty.break tail recursive #476

Closed

Conversation

GytisZ
Copy link

@GytisZ GytisZ commented May 27, 2019

Hi, we have a rather large test, that would trigger stack overflow from Prettybreak. This should fix it.

Tried to keep to similar style. The only functional change is the added requirement for lead.length.

No tests submitted, since it seems util.Pretty is not tested a lot. I'm leaning towards adding them, but don't want change too much, so waiting for yay/nay whether to do it.

@ashawley
Copy link
Contributor

Hi, we have a rather large test, that would trigger stack overflow from Prettybreak.

Do you have an example of a failing test?

@GytisZ
Copy link
Author

GytisZ commented Jun 6, 2019

Not in a form I could share easily. In short it's a org.scalacheck.commands.Commands test that tests some stateful storage and generates lists of messages to write / read.

A bit longer story is that while the commands themselves are short

case class WriteMessages(content: String, numberOfCopies: Int)

val exampleCommand = WriteMessages('foobar', 5)

all the messages are kept in State written out

val s: State = ???
s.currentMessages = List('foobar', 'foobar', 'foobar', 'foobar', 'foobar')

and thus a lot longer when written out as a String .

scalacheck is writing out these states upon test failure, which then causes StackOverflow

This might be a rare occurrence, and maybe our tests are badly designed, but regardless, I think it shouldn't end in a StackOverflow from the framework.

@ashawley ashawley mentioned this pull request Jun 24, 2019
18 tasks
non added a commit to non/scalacheck that referenced this pull request Aug 7, 2019
The motivation for this is typelevel#476. I wanted to ensure we had stronger
tests for Pretty.break before refactoring it, and also thought that
this implementation was a little bit nicer.

This PR includes a test for stack-safety, a test to ensure we never
create lines longer than the maximum allowed, and that we can
reassemble the original string from the output. The old code passed
all of these (apart from the stack safety test which it failed), which
helps give confidence and that the new implementation is equivalent.

It also includes a Scaladoc method to explain what the method does.

Thanks to @GytisZ for reporting the issue and providing an initial PR.
@non
Copy link
Contributor

non commented Aug 7, 2019

I ended up writing some tests to nail down the break behavior, and ended up with a slightly different stack-safe refactor:

#495

@non
Copy link
Contributor

non commented Aug 7, 2019

Closing this because we merged #495.

@GytisZ thanks for your PR and I'm sorry it didn't get more attention sooner.

@non non closed this Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants