@@ -39,6 +39,7 @@ import System.Random(StdGen,randomR,mkStdGen)
3939import qualified Data.List.NonEmpty as NEL
4040import qualified Data.Map.Strict as Map
4141import Data.Time.Clock
42+import Data.List(sortOn)
4243
4344import Roboservant.Types.Breakdown
4445import Roboservant.Types
@@ -108,9 +109,6 @@ fuzz server Config{..} checker = handle (pure . Just . formatException) $ do
108109
109110
110111 deadline :: UTCTime <- addUTCTime (fromInteger $ maxRuntime * 1000000) <$> getCurrentTime
111− -- either we time out without finding an error, which is fine, or we find an error
112− -- and throw an exception that propagates through this.
113−
114112 (stopreason, fs ) <- runStateT
115113 (untilDone (maxReps, deadline) go <* (evaluateCoverage =<< get)) FuzzState{..}
116114 pure Nothing
@@ -122,13 +120,19 @@ fuzz server Config{..} checker = handle (pure . Just . formatException) $ do
122120 formatException r@(RoboservantException failureType exception _state) = Report
123121 (unlines [ show failureType , show exception ])
124122 r
125−
123+
124+ displayDiagnostics FuzzState{..} = liftIO $ do
125+ putStrLn "api endpoints covered"
126+ mapM_ print (Set.toList $ Set.fromList $ map apiOffset path)
127+ putStrLn ""
128+ putStrLn "types in stash"
129+ mapM_ print (map (\x -> (fst x, NEL.length (snd x))) . sortOn fst . Map.toList $ stash)
130+
126131 -- evaluateCoverage :: FuzzState -> m ()
127132 evaluateCoverage f@FuzzState{..}
128133 | coverage > coverageThreshold = pure ()
129134 | otherwise = do
130− liftIO $ do putStrLn "api endpoints covered"
131− mapM_ print (Set.toList $ Set.fromList $ map apiOffset path)
135+ displayDiagnostics f
132136 throw $ RoboservantException (InsufficientCoverage coverage) Nothing f
133137 where hitRoutes = (fromIntegral . Set.size . Set.fromList $ map apiOffset path)
134138 totalRoutes = (fromIntegral routeCount)
@@ -213,13 +217,15 @@ fuzz server Config{..} checker = handle (pure . Just . formatException) $ do
213217 fs { stash = addToStash (NEL.toList dyn) stash } )
214218 pure ()
215219
216− go :: (MonadState FuzzState m, MonadIO m, MonadBaseControl IO m)
217− => m ()
220+-- go :: (MonadState FuzzState m, MonadIO m, MonadBaseControl IO m)
221+-- => m ()
218222 go = do
219223 op <- genOp
220224 catches (execute op)
221225 [ Handler (\(e :: SomeAsyncException) -> throw e)
222− , Handler (\(e :: SomeException) -> throw . RoboservantException ServerCrashed (Just e) =<< get)
226+ , Handler (\(e :: SomeException) -> do
227+ displayDiagnostics =<< get
228+ throw . RoboservantException ServerCrashed (Just e) =<< get)
223229 ]
224230 catch (liftIO checker)
225231 (\(e :: SomeException) -> throw . RoboservantException CheckerFailed (Just e) =<< get)