File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
src/testkit/scala/tools/testkit
test/junit/scala/collection Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -107,25 +107,24 @@ object AssertUtil {
107
107
*/
108
108
def assertNotReachable [A <: AnyRef ](a : => A , roots : AnyRef * )(body : => Unit ): Unit = {
109
109
val wkref = new WeakReference (a)
110
- def refs (root : AnyRef ): mutable.Set [AnyRef ] = {
110
+ // fail if following strong references from root discovers referent. Quit if ref is empty.
111
+ def assertNoRef (root : AnyRef ): Unit = {
111
112
val seen = new IdentityHashMap [AnyRef , Unit ]
112
113
def loop (o : AnyRef ): Unit =
113
114
if (wkref.nonEmpty && o != null && ! seen.containsKey(o)) {
114
115
seen.put(o, ())
116
+ assertTrue(s " Root $root held reference $o" , o ne wkref.get)
115
117
for {
116
118
f <- o.getClass.allFields
117
119
if ! Modifier .isStatic(f.getModifiers)
118
120
if ! f.getType.isPrimitive
119
121
if ! classOf [Reference [_]].isAssignableFrom(f.getType)
120
- } loop(f follow o )
122
+ } loop(f. follow(o) )
121
123
}
122
124
loop(root)
123
- seen.keySet.asScala
124
125
}
125
126
body
126
- for (r <- roots if wkref.nonEmpty) {
127
- assertFalse(s " Root $r held reference " , refs(r) contains wkref.get)
128
- }
127
+ roots.foreach(assertNoRef)
129
128
}
130
129
131
130
/** Assert no new threads, with some margin for arbitrary threads to exit. */
Original file line number Diff line number Diff line change @@ -652,7 +652,8 @@ class IteratorTest {
652
652
val it0 : Iterator [Int ] = Iterator (1 , 2 )
653
653
lazy val it : Iterator [String ] = it0.flatMap {
654
654
case 1 => Option (seq1.get).getOrElse(Nil )
655
- case _ => check(); seq2
655
+ case 2 => check(); seq2
656
+ case _ => ???
656
657
}
657
658
658
659
def check () = assertNotReachable(seq1.get, it)(())
You can’t perform that action at this time.
0 commit comments