File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed
io-sim/test/Test/Control/Monad Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change 1+ {-# LANGUAGE BangPatterns #-}
12{-# LANGUAGE CPP #-}
23{-# LANGUAGE DeriveGeneric #-}
34{-# LANGUAGE FlexibleContexts #-}
@@ -434,15 +435,31 @@ doit n = do
434435 threadDelay 1
435436 readTVarIO r
436437
437-
438- traceNoDuplicates :: (Testable prop1 , Show a1 ) => ((a1 -> a2 -> a2 ) -> prop1 ) -> Property
439- traceNoDuplicates k = r `pseq` (k addTrace .&&. maximum (traceCounts () ) == 1 )
438+ traceNoDuplicates :: forall a b .
439+ (Show a )
440+ => ((a -> b -> b ) -> Property )
441+ -> Property
442+ -- this NOINLINE pragma is useful for debugging if `r` didn't flow outside of
443+ -- `traceNoDuplicate`.
444+ {-# NOINLINE traceNoDuplicates #-}
445+ traceNoDuplicates k = unsafePerformIO $ do
446+ r <- newIORef (Map. empty :: Map String Int )
447+ return $ r `pseq`
448+ (k (addTrace r) .&&. counterexample " trace counts" (maximum (Map. elems (traceCounts r)) === 1 ))
440449 where
441- r = unsafePerformIO $ newIORef (Map. empty :: Map String Int )
442- addTrace t x = unsafePerformIO $ do
443- atomicModifyIORef r (\ m-> (Map. insertWith (+) (show t) 1 m,() ))
450+ addTrace :: IORef (Map String Int ) -> a -> b -> b
451+ addTrace r t x = unsafePerformIO $ do
452+ let s = show t
453+ atomicModifyIORef r
454+ (\ m->
455+ let m' = Map. insertWith (+) s 1 m
456+ in (m', () )
457+ )
444458 return x
445- traceCounts () = unsafePerformIO $ Map. elems <$> readIORef r
459+
460+ traceCounts :: IORef (Map String Int ) -> Map String Int
461+ traceCounts r = unsafePerformIO $ readIORef r
462+
446463
447464-- | Checks that IOSimPOR is capable of analysing an infinite simulation
448465-- lazily.
You can’t perform that action at this time.
0 commit comments