-
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.
Prevent nesting properties or otherwise adding properties during execution.
- Loading branch information
Showing
2 changed files
with
43 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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
/*-------------------------------------------------------------------------*\ | ||
** 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 | ||
} | ||
} | ||
|
||
p.freeze() // don't have a good way of testing how sbt does this | ||
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 | ||
} | ||
} |