-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from NthPortal/topic/no-nested-properties/PR
Prevent nesting properties
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/scala/org/scalacheck/NoPropertyNestingSpecification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*-------------------------------------------------------------------------*\ | ||
** ScalaCheck ** | ||
** Copyright (c) 2007-2019 Rickard Nilsson. All rights reserved. ** | ||
** http://www.scalacheck.org ** | ||
** ** | ||
** This software is released under the terms of the Revised BSD License. ** | ||
** There is NO WARRANTY. See the file LICENSE for the full text. ** | ||
\*------------------------------------------------------------------------ */ | ||
|
||
package org.scalacheck | ||
|
||
object NoPropertyNestingSpecification extends Properties("Properties.no nesting") { | ||
property("no nested properties") = { | ||
var thrown = false | ||
|
||
val p = new Properties("P") { | ||
property("outer") = { | ||
property("inner") = true // not allowed! | ||
true | ||
} | ||
} | ||
|
||
val results = for ((name, prop) <- p.properties) yield prop(Gen.Parameters.default) | ||
results match { | ||
case collection.Seq(res) => res.status match { | ||
case Prop.Exception(e: IllegalStateException) => | ||
if (e.getMessage contains "nest") thrown = true | ||
else throw new Exception("exception message did not reference nesting") | ||
case _ => throw new Exception("did not get IllegalStateException") | ||
} | ||
case _ => throw new Exception("more than one property, somehow") | ||
} | ||
|
||
thrown == true | ||
} | ||
} |