Skip to content

Simple check leads to infinite loop #244

@danielkarch

Description

@danielkarch

Hi,

I just started playing around with ScalaCheck and encountered a problem. The following does not terminate on my machine with ScalaCheck 1.13.[0|1]:

import org.scalacheck.Properties
import org.scalacheck.Prop.forAll

object HelloSpec extends Properties("Hello") {

  def replaceLettersWithX(str: String) = {

    def replaceLetter(ch: Char): Char = {
      if (ch.isLetter) {
        'X'
      } else {
        ch
      }
    }

    str map replaceLetter
  }

  property("is actually the identity function") = forAll { (str: String) =>
    val withX: String = replaceLettersWithX(str)
    withX == str
  }

}

With version 1.12.5, a counter-example is produced quickly. With the newer versions, it gets stuck in an infinite loop. I tried to debug it and it seems like once ScalaCheck has found a counter-example, it is trying to shrink it. The shrinking however only keeps replacing one 1-character string with another.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions