From cb9e7c3d99980a6347f169bf07c2c64906ee03c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20K=C3=B6lker?= Date: Tue, 22 Dec 2020 18:45:01 +0100 Subject: [PATCH 1/2] Enable customization of `Commands.Command` shrinking The `Commands` user can either specify a `Shrink[Command]`, in which case the default `List` shrinker will be used to shrink sequential and parallel commands, or the user can specify those shrinks directly, or a mix (e.g. `Shrink[Command]` and `Shrink[List[List[Command]]]`). --- .../org/scalacheck/commands/Commands.scala | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/scalacheck/commands/Commands.scala b/src/main/scala/org/scalacheck/commands/Commands.scala index 1327de7ff..9f14b5523 100644 --- a/src/main/scala/org/scalacheck/commands/Commands.scala +++ b/src/main/scala/org/scalacheck/commands/Commands.scala @@ -262,6 +262,24 @@ trait Commands { * [[State]]. By default no shrinking is done for [[State]]. */ def shrinkState: Shrink[State] = implicitly + /** Override this to provide a custom Shrinker for your internal + * [[Command]]. By default no shrinking is done for [[Command]]. */ + def shrinkCommand: Shrink[Command] = implicitly + + /** Override this to provide a custom Shrinker of sequential [[Command]]s. + * By default, the implicit List shrinker is used with [[shrinkCommand]]. */ + def shrinkSequentialCommands: Shrink[List[Command]] = { + implicit val commandShrinker = shrinkCommand + implicitly + } + + /** Override this to provide a custom Shrinker of parallel [[Command]]s. + * By default, the implict List shrinker is used with [[shrinkCommand]]. */ + def shrinkParallelCommands: Shrink[List[List[Command]]] = { + implicit val commandShrinker = shrinkCommand + implicitly + } + // Private methods // private type Commands = List[Command] @@ -270,9 +288,12 @@ trait Commands { ) private implicit val shrinkActions: Shrink[Actions] = Shrink[Actions] { as => + val shrinkSeq = shrinkSequentialCommands + val shrinkPar = shrinkParallelCommands + val shrinkedCmds: Stream[Actions] = - Shrink.shrink(as.seqCmds).map(cs => as.copy(seqCmds = cs)) append - Shrink.shrink(as.parCmds).map(cs => as.copy(parCmds = cs)) + shrinkSeq.shrink(as.seqCmds).map(cs => as.copy(seqCmds = cs)) append + shrinkPar.shrink(as.parCmds).map(cs => as.copy(parCmds = cs)) Shrink.shrinkWithOrig[State](as.s)(shrinkState) flatMap { state => shrinkedCmds.map(_.copy(s = state)) From 12a1a478ab8002c8d448a8bd0085889acb47bb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20K=C3=B6lker?= Date: Tue, 22 Dec 2020 18:53:33 +0100 Subject: [PATCH 2/2] Add new methods to MiMa's newMethods, supressing a warning --- project/MimaSettings.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project/MimaSettings.scala b/project/MimaSettings.scala index d094ec82c..432e77db4 100644 --- a/project/MimaSettings.scala +++ b/project/MimaSettings.scala @@ -16,6 +16,9 @@ object MimaSettings { ) private def newMethods = Seq( + "org.scalacheck.commands.Commands.shrinkCommand", + "org.scalacheck.commands.Commands.shrinkSequentialCommands", + "org.scalacheck.commands.Commands.shrinkParallelCommands", ) private def removedPrivateMethods = Seq(