{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia        #-}
{-# LANGUAGE FlexibleContexts   #-}
{-# LANGUAGE GADTs              #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE TemplateHaskell    #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module PlutusTx.Coverage ( CoverageAnnotation(..)
                         , CoverageIndex(..)
                         , CoverageMetadata(..)
                         , Metadata(..)
                         , CoverageData(..)
                         , CoverageReport(..)
                         , CovLoc(..)
                         , covLocFile
                         , covLocStartLine
                         , covLocEndLine
                         , covLocStartCol
                         , covLocEndCol
                         , metadataSet
                         , coverageAnnotations
                         , ignoredAnnotations
                         , coverageMetadata
                         , coveredAnnotations
                         , addCoverageMetadata
                         , addLocationToCoverageIndex
                         , addBoolCaseToCoverageIndex
                         , coverageDataFromLogMsg
                         ) where

import Control.Lens

import Codec.Serialise

import PlutusCore.Flat

import Control.DeepSeq
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
import Data.Foldable
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set)
import Data.Set qualified as Set
import Data.String
import Text.Read

import Control.Monad.Writer

import Prettyprinter

import Prelude

import Flat hiding (to)

{- Note [Coverage annotations]
   During compilation we can insert coverage annotations in `trace` calls in
   the PIR code that are tracked in the relevant downstream code by looking at
   the logs. For example, the `LocationCoverage` option piggy-backs on the GHC
   source location annotations (in the form of `Tick`s) and insert `CoverageAnnLocation`
   annotations in the PIR that match the source location in the `Tick`.
-}

{- Note [Adding more coverage annotations]
   To add more coverage annotations we need to:
   1. Add a constructor to `CoverageType`
   2. Add option parsing to the function `parsePluginArgs`
   3. Add a coverage annotation to `CoverageAnn`
   4. Make any necessary modifications to `CoverageIndex`
   5. Add code to the compiler (e.g. in `compileExpr`) to insert
      the `CoverageAnn` and meta-data in the index
-}

-- | A source location for coverage
data CovLoc = CovLoc { CovLoc -> String
_covLocFile      :: String
                     , CovLoc -> Int
_covLocStartLine :: Int
                     , CovLoc -> Int
_covLocEndLine   :: Int
                     , CovLoc -> Int
_covLocStartCol  :: Int
                     , CovLoc -> Int
_covLocEndCol    :: Int }
  deriving stock (Eq CovLoc
Eq CovLoc
-> (CovLoc -> CovLoc -> Ordering)
-> (CovLoc -> CovLoc -> Bool)
-> (CovLoc -> CovLoc -> Bool)
-> (CovLoc -> CovLoc -> Bool)
-> (CovLoc -> CovLoc -> Bool)
-> (CovLoc -> CovLoc -> CovLoc)
-> (CovLoc -> CovLoc -> CovLoc)
-> Ord CovLoc
CovLoc -> CovLoc -> Bool
CovLoc -> CovLoc -> Ordering
CovLoc -> CovLoc -> CovLoc
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CovLoc -> CovLoc -> CovLoc
$cmin :: CovLoc -> CovLoc -> CovLoc
max :: CovLoc -> CovLoc -> CovLoc
$cmax :: CovLoc -> CovLoc -> CovLoc
>= :: CovLoc -> CovLoc -> Bool
$c>= :: CovLoc -> CovLoc -> Bool
> :: CovLoc -> CovLoc -> Bool
$c> :: CovLoc -> CovLoc -> Bool
<= :: CovLoc -> CovLoc -> Bool
$c<= :: CovLoc -> CovLoc -> Bool
< :: CovLoc -> CovLoc -> Bool
$c< :: CovLoc -> CovLoc -> Bool
compare :: CovLoc -> CovLoc -> Ordering
$ccompare :: CovLoc -> CovLoc -> Ordering
$cp1Ord :: Eq CovLoc
Ord, CovLoc -> CovLoc -> Bool
(CovLoc -> CovLoc -> Bool)
-> (CovLoc -> CovLoc -> Bool) -> Eq CovLoc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CovLoc -> CovLoc -> Bool
$c/= :: CovLoc -> CovLoc -> Bool
== :: CovLoc -> CovLoc -> Bool
$c== :: CovLoc -> CovLoc -> Bool
Eq, Int -> CovLoc -> ShowS
[CovLoc] -> ShowS
CovLoc -> String
(Int -> CovLoc -> ShowS)
-> (CovLoc -> String) -> ([CovLoc] -> ShowS) -> Show CovLoc
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CovLoc] -> ShowS
$cshowList :: [CovLoc] -> ShowS
show :: CovLoc -> String
$cshow :: CovLoc -> String
showsPrec :: Int -> CovLoc -> ShowS
$cshowsPrec :: Int -> CovLoc -> ShowS
Show, ReadPrec [CovLoc]
ReadPrec CovLoc
Int -> ReadS CovLoc
ReadS [CovLoc]
(Int -> ReadS CovLoc)
-> ReadS [CovLoc]
-> ReadPrec CovLoc
-> ReadPrec [CovLoc]
-> Read CovLoc
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CovLoc]
$creadListPrec :: ReadPrec [CovLoc]
readPrec :: ReadPrec CovLoc
$creadPrec :: ReadPrec CovLoc
readList :: ReadS [CovLoc]
$creadList :: ReadS [CovLoc]
readsPrec :: Int -> ReadS CovLoc
$creadsPrec :: Int -> ReadS CovLoc
Read, (forall x. CovLoc -> Rep CovLoc x)
-> (forall x. Rep CovLoc x -> CovLoc) -> Generic CovLoc
forall x. Rep CovLoc x -> CovLoc
forall x. CovLoc -> Rep CovLoc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CovLoc x -> CovLoc
$cfrom :: forall x. CovLoc -> Rep CovLoc x
Generic)
  deriving anyclass ([CovLoc] -> Encoding
CovLoc -> Encoding
(CovLoc -> Encoding)
-> (forall s. Decoder s CovLoc)
-> ([CovLoc] -> Encoding)
-> (forall s. Decoder s [CovLoc])
-> Serialise CovLoc
forall s. Decoder s [CovLoc]
forall s. Decoder s CovLoc
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [CovLoc]
$cdecodeList :: forall s. Decoder s [CovLoc]
encodeList :: [CovLoc] -> Encoding
$cencodeList :: [CovLoc] -> Encoding
decode :: Decoder s CovLoc
$cdecode :: forall s. Decoder s CovLoc
encode :: CovLoc -> Encoding
$cencode :: CovLoc -> Encoding
Serialise)
  deriving Get CovLoc
CovLoc -> Encoding
CovLoc -> Int -> Int
(CovLoc -> Encoding)
-> Get CovLoc -> (CovLoc -> Int -> Int) -> Flat CovLoc
forall a. (a -> Encoding) -> Get a -> (a -> Int -> Int) -> Flat a
size :: CovLoc -> Int -> Int
$csize :: CovLoc -> Int -> Int
decode :: Get CovLoc
$cdecode :: Get CovLoc
encode :: CovLoc -> Encoding
$cencode :: CovLoc -> Encoding
Flat via (AsSerialize CovLoc)
  deriving anyclass (CovLoc -> ()
(CovLoc -> ()) -> NFData CovLoc
forall a. (a -> ()) -> NFData a
rnf :: CovLoc -> ()
$crnf :: CovLoc -> ()
NFData, [CovLoc] -> Encoding
[CovLoc] -> Value
CovLoc -> Encoding
CovLoc -> Value
(CovLoc -> Value)
-> (CovLoc -> Encoding)
-> ([CovLoc] -> Value)
-> ([CovLoc] -> Encoding)
-> ToJSON CovLoc
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CovLoc] -> Encoding
$ctoEncodingList :: [CovLoc] -> Encoding
toJSONList :: [CovLoc] -> Value
$ctoJSONList :: [CovLoc] -> Value
toEncoding :: CovLoc -> Encoding
$ctoEncoding :: CovLoc -> Encoding
toJSON :: CovLoc -> Value
$ctoJSON :: CovLoc -> Value
ToJSON, Value -> Parser [CovLoc]
Value -> Parser CovLoc
(Value -> Parser CovLoc)
-> (Value -> Parser [CovLoc]) -> FromJSON CovLoc
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CovLoc]
$cparseJSONList :: Value -> Parser [CovLoc]
parseJSON :: Value -> Parser CovLoc
$cparseJSON :: Value -> Parser CovLoc
FromJSON)

makeLenses ''CovLoc

instance Pretty CovLoc where
  pretty :: CovLoc -> Doc ann
pretty (CovLoc String
file Int
l1 Int
l2 Int
c1 Int
c2) =
    [Doc ann] -> Doc ann
forall a. Monoid a => [a] -> a
mconcat [ String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty String
file, Doc ann
":", Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
l1, Doc ann
",", Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
c1, Doc ann
"-",  Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
l2, Doc ann
",", Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
c2]

data CoverageAnnotation = CoverLocation CovLoc
                        | CoverBool CovLoc Bool
                        deriving stock (Eq CoverageAnnotation
Eq CoverageAnnotation
-> (CoverageAnnotation -> CoverageAnnotation -> Ordering)
-> (CoverageAnnotation -> CoverageAnnotation -> Bool)
-> (CoverageAnnotation -> CoverageAnnotation -> Bool)
-> (CoverageAnnotation -> CoverageAnnotation -> Bool)
-> (CoverageAnnotation -> CoverageAnnotation -> Bool)
-> (CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation)
-> (CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation)
-> Ord CoverageAnnotation
CoverageAnnotation -> CoverageAnnotation -> Bool
CoverageAnnotation -> CoverageAnnotation -> Ordering
CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation
$cmin :: CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation
max :: CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation
$cmax :: CoverageAnnotation -> CoverageAnnotation -> CoverageAnnotation
>= :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c>= :: CoverageAnnotation -> CoverageAnnotation -> Bool
> :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c> :: CoverageAnnotation -> CoverageAnnotation -> Bool
<= :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c<= :: CoverageAnnotation -> CoverageAnnotation -> Bool
< :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c< :: CoverageAnnotation -> CoverageAnnotation -> Bool
compare :: CoverageAnnotation -> CoverageAnnotation -> Ordering
$ccompare :: CoverageAnnotation -> CoverageAnnotation -> Ordering
$cp1Ord :: Eq CoverageAnnotation
Ord, CoverageAnnotation -> CoverageAnnotation -> Bool
(CoverageAnnotation -> CoverageAnnotation -> Bool)
-> (CoverageAnnotation -> CoverageAnnotation -> Bool)
-> Eq CoverageAnnotation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c/= :: CoverageAnnotation -> CoverageAnnotation -> Bool
== :: CoverageAnnotation -> CoverageAnnotation -> Bool
$c== :: CoverageAnnotation -> CoverageAnnotation -> Bool
Eq, Int -> CoverageAnnotation -> ShowS
[CoverageAnnotation] -> ShowS
CoverageAnnotation -> String
(Int -> CoverageAnnotation -> ShowS)
-> (CoverageAnnotation -> String)
-> ([CoverageAnnotation] -> ShowS)
-> Show CoverageAnnotation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageAnnotation] -> ShowS
$cshowList :: [CoverageAnnotation] -> ShowS
show :: CoverageAnnotation -> String
$cshow :: CoverageAnnotation -> String
showsPrec :: Int -> CoverageAnnotation -> ShowS
$cshowsPrec :: Int -> CoverageAnnotation -> ShowS
Show, ReadPrec [CoverageAnnotation]
ReadPrec CoverageAnnotation
Int -> ReadS CoverageAnnotation
ReadS [CoverageAnnotation]
(Int -> ReadS CoverageAnnotation)
-> ReadS [CoverageAnnotation]
-> ReadPrec CoverageAnnotation
-> ReadPrec [CoverageAnnotation]
-> Read CoverageAnnotation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CoverageAnnotation]
$creadListPrec :: ReadPrec [CoverageAnnotation]
readPrec :: ReadPrec CoverageAnnotation
$creadPrec :: ReadPrec CoverageAnnotation
readList :: ReadS [CoverageAnnotation]
$creadList :: ReadS [CoverageAnnotation]
readsPrec :: Int -> ReadS CoverageAnnotation
$creadsPrec :: Int -> ReadS CoverageAnnotation
Read, (forall x. CoverageAnnotation -> Rep CoverageAnnotation x)
-> (forall x. Rep CoverageAnnotation x -> CoverageAnnotation)
-> Generic CoverageAnnotation
forall x. Rep CoverageAnnotation x -> CoverageAnnotation
forall x. CoverageAnnotation -> Rep CoverageAnnotation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageAnnotation x -> CoverageAnnotation
$cfrom :: forall x. CoverageAnnotation -> Rep CoverageAnnotation x
Generic)
                        deriving anyclass ([CoverageAnnotation] -> Encoding
CoverageAnnotation -> Encoding
(CoverageAnnotation -> Encoding)
-> (forall s. Decoder s CoverageAnnotation)
-> ([CoverageAnnotation] -> Encoding)
-> (forall s. Decoder s [CoverageAnnotation])
-> Serialise CoverageAnnotation
forall s. Decoder s [CoverageAnnotation]
forall s. Decoder s CoverageAnnotation
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [CoverageAnnotation]
$cdecodeList :: forall s. Decoder s [CoverageAnnotation]
encodeList :: [CoverageAnnotation] -> Encoding
$cencodeList :: [CoverageAnnotation] -> Encoding
decode :: Decoder s CoverageAnnotation
$cdecode :: forall s. Decoder s CoverageAnnotation
encode :: CoverageAnnotation -> Encoding
$cencode :: CoverageAnnotation -> Encoding
Serialise)
                        deriving Get CoverageAnnotation
CoverageAnnotation -> Encoding
CoverageAnnotation -> Int -> Int
(CoverageAnnotation -> Encoding)
-> Get CoverageAnnotation
-> (CoverageAnnotation -> Int -> Int)
-> Flat CoverageAnnotation
forall a. (a -> Encoding) -> Get a -> (a -> Int -> Int) -> Flat a
size :: CoverageAnnotation -> Int -> Int
$csize :: CoverageAnnotation -> Int -> Int
decode :: Get CoverageAnnotation
$cdecode :: Get CoverageAnnotation
encode :: CoverageAnnotation -> Encoding
$cencode :: CoverageAnnotation -> Encoding
Flat via (AsSerialize CoverageAnnotation)
                        deriving anyclass (CoverageAnnotation -> ()
(CoverageAnnotation -> ()) -> NFData CoverageAnnotation
forall a. (a -> ()) -> NFData a
rnf :: CoverageAnnotation -> ()
$crnf :: CoverageAnnotation -> ()
NFData, [CoverageAnnotation] -> Encoding
[CoverageAnnotation] -> Value
CoverageAnnotation -> Encoding
CoverageAnnotation -> Value
(CoverageAnnotation -> Value)
-> (CoverageAnnotation -> Encoding)
-> ([CoverageAnnotation] -> Value)
-> ([CoverageAnnotation] -> Encoding)
-> ToJSON CoverageAnnotation
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CoverageAnnotation] -> Encoding
$ctoEncodingList :: [CoverageAnnotation] -> Encoding
toJSONList :: [CoverageAnnotation] -> Value
$ctoJSONList :: [CoverageAnnotation] -> Value
toEncoding :: CoverageAnnotation -> Encoding
$ctoEncoding :: CoverageAnnotation -> Encoding
toJSON :: CoverageAnnotation -> Value
$ctoJSON :: CoverageAnnotation -> Value
ToJSON, Value -> Parser [CoverageAnnotation]
Value -> Parser CoverageAnnotation
(Value -> Parser CoverageAnnotation)
-> (Value -> Parser [CoverageAnnotation])
-> FromJSON CoverageAnnotation
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CoverageAnnotation]
$cparseJSONList :: Value -> Parser [CoverageAnnotation]
parseJSON :: Value -> Parser CoverageAnnotation
$cparseJSON :: Value -> Parser CoverageAnnotation
FromJSON, ToJSONKeyFunction [CoverageAnnotation]
ToJSONKeyFunction CoverageAnnotation
ToJSONKeyFunction CoverageAnnotation
-> ToJSONKeyFunction [CoverageAnnotation]
-> ToJSONKey CoverageAnnotation
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [CoverageAnnotation]
$ctoJSONKeyList :: ToJSONKeyFunction [CoverageAnnotation]
toJSONKey :: ToJSONKeyFunction CoverageAnnotation
$ctoJSONKey :: ToJSONKeyFunction CoverageAnnotation
ToJSONKey, FromJSONKeyFunction [CoverageAnnotation]
FromJSONKeyFunction CoverageAnnotation
FromJSONKeyFunction CoverageAnnotation
-> FromJSONKeyFunction [CoverageAnnotation]
-> FromJSONKey CoverageAnnotation
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [CoverageAnnotation]
$cfromJSONKeyList :: FromJSONKeyFunction [CoverageAnnotation]
fromJSONKey :: FromJSONKeyFunction CoverageAnnotation
$cfromJSONKey :: FromJSONKeyFunction CoverageAnnotation
FromJSONKey)

instance Pretty CoverageAnnotation where
  pretty :: CoverageAnnotation -> Doc ann
pretty (CoverLocation CovLoc
loc) = CovLoc -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty CovLoc
loc
  pretty (CoverBool CovLoc
loc Bool
b)   = CovLoc -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty CovLoc
loc Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"=" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Bool -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Bool
b

data Metadata = ApplicationHeadSymbol String
              | IgnoredAnnotation
                -- ^ Location that is not interesting to cover. This is not generated by the
                --   compiler, but can be added later using `addCoverageMetadata`.
    deriving stock (Eq Metadata
Eq Metadata
-> (Metadata -> Metadata -> Ordering)
-> (Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Metadata)
-> (Metadata -> Metadata -> Metadata)
-> Ord Metadata
Metadata -> Metadata -> Bool
Metadata -> Metadata -> Ordering
Metadata -> Metadata -> Metadata
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Metadata -> Metadata -> Metadata
$cmin :: Metadata -> Metadata -> Metadata
max :: Metadata -> Metadata -> Metadata
$cmax :: Metadata -> Metadata -> Metadata
>= :: Metadata -> Metadata -> Bool
$c>= :: Metadata -> Metadata -> Bool
> :: Metadata -> Metadata -> Bool
$c> :: Metadata -> Metadata -> Bool
<= :: Metadata -> Metadata -> Bool
$c<= :: Metadata -> Metadata -> Bool
< :: Metadata -> Metadata -> Bool
$c< :: Metadata -> Metadata -> Bool
compare :: Metadata -> Metadata -> Ordering
$ccompare :: Metadata -> Metadata -> Ordering
$cp1Ord :: Eq Metadata
Ord, Metadata -> Metadata -> Bool
(Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool) -> Eq Metadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metadata -> Metadata -> Bool
$c/= :: Metadata -> Metadata -> Bool
== :: Metadata -> Metadata -> Bool
$c== :: Metadata -> Metadata -> Bool
Eq, Int -> Metadata -> ShowS
[Metadata] -> ShowS
Metadata -> String
(Int -> Metadata -> ShowS)
-> (Metadata -> String) -> ([Metadata] -> ShowS) -> Show Metadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metadata] -> ShowS
$cshowList :: [Metadata] -> ShowS
show :: Metadata -> String
$cshow :: Metadata -> String
showsPrec :: Int -> Metadata -> ShowS
$cshowsPrec :: Int -> Metadata -> ShowS
Show, (forall x. Metadata -> Rep Metadata x)
-> (forall x. Rep Metadata x -> Metadata) -> Generic Metadata
forall x. Rep Metadata x -> Metadata
forall x. Metadata -> Rep Metadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metadata x -> Metadata
$cfrom :: forall x. Metadata -> Rep Metadata x
Generic)
    deriving anyclass ([Metadata] -> Encoding
Metadata -> Encoding
(Metadata -> Encoding)
-> (forall s. Decoder s Metadata)
-> ([Metadata] -> Encoding)
-> (forall s. Decoder s [Metadata])
-> Serialise Metadata
forall s. Decoder s [Metadata]
forall s. Decoder s Metadata
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [Metadata]
$cdecodeList :: forall s. Decoder s [Metadata]
encodeList :: [Metadata] -> Encoding
$cencodeList :: [Metadata] -> Encoding
decode :: Decoder s Metadata
$cdecode :: forall s. Decoder s Metadata
encode :: Metadata -> Encoding
$cencode :: Metadata -> Encoding
Serialise)
    deriving Get Metadata
Metadata -> Encoding
Metadata -> Int -> Int
(Metadata -> Encoding)
-> Get Metadata -> (Metadata -> Int -> Int) -> Flat Metadata
forall a. (a -> Encoding) -> Get a -> (a -> Int -> Int) -> Flat a
size :: Metadata -> Int -> Int
$csize :: Metadata -> Int -> Int
decode :: Get Metadata
$cdecode :: Get Metadata
encode :: Metadata -> Encoding
$cencode :: Metadata -> Encoding
Flat via (AsSerialize Metadata)
    deriving anyclass (Metadata -> ()
(Metadata -> ()) -> NFData Metadata
forall a. (a -> ()) -> NFData a
rnf :: Metadata -> ()
$crnf :: Metadata -> ()
NFData, [Metadata] -> Encoding
[Metadata] -> Value
Metadata -> Encoding
Metadata -> Value
(Metadata -> Value)
-> (Metadata -> Encoding)
-> ([Metadata] -> Value)
-> ([Metadata] -> Encoding)
-> ToJSON Metadata
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Metadata] -> Encoding
$ctoEncodingList :: [Metadata] -> Encoding
toJSONList :: [Metadata] -> Value
$ctoJSONList :: [Metadata] -> Value
toEncoding :: Metadata -> Encoding
$ctoEncoding :: Metadata -> Encoding
toJSON :: Metadata -> Value
$ctoJSON :: Metadata -> Value
ToJSON, Value -> Parser [Metadata]
Value -> Parser Metadata
(Value -> Parser Metadata)
-> (Value -> Parser [Metadata]) -> FromJSON Metadata
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Metadata]
$cparseJSONList :: Value -> Parser [Metadata]
parseJSON :: Value -> Parser Metadata
$cparseJSON :: Value -> Parser Metadata
FromJSON)

instance Pretty Metadata where
  pretty :: Metadata -> Doc ann
pretty = Metadata -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow

newtype CoverageMetadata = CoverageMetadata { CoverageMetadata -> Set Metadata
_metadataSet :: Set Metadata }
    deriving stock (Eq CoverageMetadata
Eq CoverageMetadata
-> (CoverageMetadata -> CoverageMetadata -> Ordering)
-> (CoverageMetadata -> CoverageMetadata -> Bool)
-> (CoverageMetadata -> CoverageMetadata -> Bool)
-> (CoverageMetadata -> CoverageMetadata -> Bool)
-> (CoverageMetadata -> CoverageMetadata -> Bool)
-> (CoverageMetadata -> CoverageMetadata -> CoverageMetadata)
-> (CoverageMetadata -> CoverageMetadata -> CoverageMetadata)
-> Ord CoverageMetadata
CoverageMetadata -> CoverageMetadata -> Bool
CoverageMetadata -> CoverageMetadata -> Ordering
CoverageMetadata -> CoverageMetadata -> CoverageMetadata
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
$cmin :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
max :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
$cmax :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
>= :: CoverageMetadata -> CoverageMetadata -> Bool
$c>= :: CoverageMetadata -> CoverageMetadata -> Bool
> :: CoverageMetadata -> CoverageMetadata -> Bool
$c> :: CoverageMetadata -> CoverageMetadata -> Bool
<= :: CoverageMetadata -> CoverageMetadata -> Bool
$c<= :: CoverageMetadata -> CoverageMetadata -> Bool
< :: CoverageMetadata -> CoverageMetadata -> Bool
$c< :: CoverageMetadata -> CoverageMetadata -> Bool
compare :: CoverageMetadata -> CoverageMetadata -> Ordering
$ccompare :: CoverageMetadata -> CoverageMetadata -> Ordering
$cp1Ord :: Eq CoverageMetadata
Ord, CoverageMetadata -> CoverageMetadata -> Bool
(CoverageMetadata -> CoverageMetadata -> Bool)
-> (CoverageMetadata -> CoverageMetadata -> Bool)
-> Eq CoverageMetadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageMetadata -> CoverageMetadata -> Bool
$c/= :: CoverageMetadata -> CoverageMetadata -> Bool
== :: CoverageMetadata -> CoverageMetadata -> Bool
$c== :: CoverageMetadata -> CoverageMetadata -> Bool
Eq, Int -> CoverageMetadata -> ShowS
[CoverageMetadata] -> ShowS
CoverageMetadata -> String
(Int -> CoverageMetadata -> ShowS)
-> (CoverageMetadata -> String)
-> ([CoverageMetadata] -> ShowS)
-> Show CoverageMetadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageMetadata] -> ShowS
$cshowList :: [CoverageMetadata] -> ShowS
show :: CoverageMetadata -> String
$cshow :: CoverageMetadata -> String
showsPrec :: Int -> CoverageMetadata -> ShowS
$cshowsPrec :: Int -> CoverageMetadata -> ShowS
Show, (forall x. CoverageMetadata -> Rep CoverageMetadata x)
-> (forall x. Rep CoverageMetadata x -> CoverageMetadata)
-> Generic CoverageMetadata
forall x. Rep CoverageMetadata x -> CoverageMetadata
forall x. CoverageMetadata -> Rep CoverageMetadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageMetadata x -> CoverageMetadata
$cfrom :: forall x. CoverageMetadata -> Rep CoverageMetadata x
Generic)
    deriving anyclass ([CoverageMetadata] -> Encoding
CoverageMetadata -> Encoding
(CoverageMetadata -> Encoding)
-> (forall s. Decoder s CoverageMetadata)
-> ([CoverageMetadata] -> Encoding)
-> (forall s. Decoder s [CoverageMetadata])
-> Serialise CoverageMetadata
forall s. Decoder s [CoverageMetadata]
forall s. Decoder s CoverageMetadata
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [CoverageMetadata]
$cdecodeList :: forall s. Decoder s [CoverageMetadata]
encodeList :: [CoverageMetadata] -> Encoding
$cencodeList :: [CoverageMetadata] -> Encoding
decode :: Decoder s CoverageMetadata
$cdecode :: forall s. Decoder s CoverageMetadata
encode :: CoverageMetadata -> Encoding
$cencode :: CoverageMetadata -> Encoding
Serialise, CoverageMetadata -> ()
(CoverageMetadata -> ()) -> NFData CoverageMetadata
forall a. (a -> ()) -> NFData a
rnf :: CoverageMetadata -> ()
$crnf :: CoverageMetadata -> ()
NFData, [CoverageMetadata] -> Encoding
[CoverageMetadata] -> Value
CoverageMetadata -> Encoding
CoverageMetadata -> Value
(CoverageMetadata -> Value)
-> (CoverageMetadata -> Encoding)
-> ([CoverageMetadata] -> Value)
-> ([CoverageMetadata] -> Encoding)
-> ToJSON CoverageMetadata
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CoverageMetadata] -> Encoding
$ctoEncodingList :: [CoverageMetadata] -> Encoding
toJSONList :: [CoverageMetadata] -> Value
$ctoJSONList :: [CoverageMetadata] -> Value
toEncoding :: CoverageMetadata -> Encoding
$ctoEncoding :: CoverageMetadata -> Encoding
toJSON :: CoverageMetadata -> Value
$ctoJSON :: CoverageMetadata -> Value
ToJSON, Value -> Parser [CoverageMetadata]
Value -> Parser CoverageMetadata
(Value -> Parser CoverageMetadata)
-> (Value -> Parser [CoverageMetadata])
-> FromJSON CoverageMetadata
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CoverageMetadata]
$cparseJSONList :: Value -> Parser [CoverageMetadata]
parseJSON :: Value -> Parser CoverageMetadata
$cparseJSON :: Value -> Parser CoverageMetadata
FromJSON)
    deriving newtype (b -> CoverageMetadata -> CoverageMetadata
NonEmpty CoverageMetadata -> CoverageMetadata
CoverageMetadata -> CoverageMetadata -> CoverageMetadata
(CoverageMetadata -> CoverageMetadata -> CoverageMetadata)
-> (NonEmpty CoverageMetadata -> CoverageMetadata)
-> (forall b.
    Integral b =>
    b -> CoverageMetadata -> CoverageMetadata)
-> Semigroup CoverageMetadata
forall b. Integral b => b -> CoverageMetadata -> CoverageMetadata
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> CoverageMetadata -> CoverageMetadata
$cstimes :: forall b. Integral b => b -> CoverageMetadata -> CoverageMetadata
sconcat :: NonEmpty CoverageMetadata -> CoverageMetadata
$csconcat :: NonEmpty CoverageMetadata -> CoverageMetadata
<> :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
$c<> :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
Semigroup, Semigroup CoverageMetadata
CoverageMetadata
Semigroup CoverageMetadata
-> CoverageMetadata
-> (CoverageMetadata -> CoverageMetadata -> CoverageMetadata)
-> ([CoverageMetadata] -> CoverageMetadata)
-> Monoid CoverageMetadata
[CoverageMetadata] -> CoverageMetadata
CoverageMetadata -> CoverageMetadata -> CoverageMetadata
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [CoverageMetadata] -> CoverageMetadata
$cmconcat :: [CoverageMetadata] -> CoverageMetadata
mappend :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
$cmappend :: CoverageMetadata -> CoverageMetadata -> CoverageMetadata
mempty :: CoverageMetadata
$cmempty :: CoverageMetadata
$cp1Monoid :: Semigroup CoverageMetadata
Monoid)
    deriving Get CoverageMetadata
CoverageMetadata -> Encoding
CoverageMetadata -> Int -> Int
(CoverageMetadata -> Encoding)
-> Get CoverageMetadata
-> (CoverageMetadata -> Int -> Int)
-> Flat CoverageMetadata
forall a. (a -> Encoding) -> Get a -> (a -> Int -> Int) -> Flat a
size :: CoverageMetadata -> Int -> Int
$csize :: CoverageMetadata -> Int -> Int
decode :: Get CoverageMetadata
$cdecode :: Get CoverageMetadata
encode :: CoverageMetadata -> Encoding
$cencode :: CoverageMetadata -> Encoding
Flat via (AsSerialize CoverageMetadata)

makeLenses ''CoverageMetadata

instance Pretty CoverageMetadata where
  pretty :: CoverageMetadata -> Doc ann
pretty (CoverageMetadata Set Metadata
s) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann)
-> (Set Metadata -> [Doc ann]) -> Set Metadata -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Metadata -> Doc ann) -> [Metadata] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Metadata -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([Metadata] -> [Doc ann])
-> (Set Metadata -> [Metadata]) -> Set Metadata -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Metadata -> [Metadata]
forall a. Set a -> [a]
Set.toList (Set Metadata -> Doc ann) -> Set Metadata -> Doc ann
forall a b. (a -> b) -> a -> b
$ Set Metadata
s

-- | This type keeps track of all coverage annotations and where they have been inserted / what
-- annotations are expected to be found when executing a piece of code.
data CoverageIndex = CoverageIndex { CoverageIndex -> Map CoverageAnnotation CoverageMetadata
_coverageMetadata :: Map CoverageAnnotation CoverageMetadata }
                      deriving stock (Eq CoverageIndex
Eq CoverageIndex
-> (CoverageIndex -> CoverageIndex -> Ordering)
-> (CoverageIndex -> CoverageIndex -> Bool)
-> (CoverageIndex -> CoverageIndex -> Bool)
-> (CoverageIndex -> CoverageIndex -> Bool)
-> (CoverageIndex -> CoverageIndex -> Bool)
-> (CoverageIndex -> CoverageIndex -> CoverageIndex)
-> (CoverageIndex -> CoverageIndex -> CoverageIndex)
-> Ord CoverageIndex
CoverageIndex -> CoverageIndex -> Bool
CoverageIndex -> CoverageIndex -> Ordering
CoverageIndex -> CoverageIndex -> CoverageIndex
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CoverageIndex -> CoverageIndex -> CoverageIndex
$cmin :: CoverageIndex -> CoverageIndex -> CoverageIndex
max :: CoverageIndex -> CoverageIndex -> CoverageIndex
$cmax :: CoverageIndex -> CoverageIndex -> CoverageIndex
>= :: CoverageIndex -> CoverageIndex -> Bool
$c>= :: CoverageIndex -> CoverageIndex -> Bool
> :: CoverageIndex -> CoverageIndex -> Bool
$c> :: CoverageIndex -> CoverageIndex -> Bool
<= :: CoverageIndex -> CoverageIndex -> Bool
$c<= :: CoverageIndex -> CoverageIndex -> Bool
< :: CoverageIndex -> CoverageIndex -> Bool
$c< :: CoverageIndex -> CoverageIndex -> Bool
compare :: CoverageIndex -> CoverageIndex -> Ordering
$ccompare :: CoverageIndex -> CoverageIndex -> Ordering
$cp1Ord :: Eq CoverageIndex
Ord, CoverageIndex -> CoverageIndex -> Bool
(CoverageIndex -> CoverageIndex -> Bool)
-> (CoverageIndex -> CoverageIndex -> Bool) -> Eq CoverageIndex
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageIndex -> CoverageIndex -> Bool
$c/= :: CoverageIndex -> CoverageIndex -> Bool
== :: CoverageIndex -> CoverageIndex -> Bool
$c== :: CoverageIndex -> CoverageIndex -> Bool
Eq, Int -> CoverageIndex -> ShowS
[CoverageIndex] -> ShowS
CoverageIndex -> String
(Int -> CoverageIndex -> ShowS)
-> (CoverageIndex -> String)
-> ([CoverageIndex] -> ShowS)
-> Show CoverageIndex
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageIndex] -> ShowS
$cshowList :: [CoverageIndex] -> ShowS
show :: CoverageIndex -> String
$cshow :: CoverageIndex -> String
showsPrec :: Int -> CoverageIndex -> ShowS
$cshowsPrec :: Int -> CoverageIndex -> ShowS
Show, (forall x. CoverageIndex -> Rep CoverageIndex x)
-> (forall x. Rep CoverageIndex x -> CoverageIndex)
-> Generic CoverageIndex
forall x. Rep CoverageIndex x -> CoverageIndex
forall x. CoverageIndex -> Rep CoverageIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageIndex x -> CoverageIndex
$cfrom :: forall x. CoverageIndex -> Rep CoverageIndex x
Generic)
                      deriving anyclass ([CoverageIndex] -> Encoding
CoverageIndex -> Encoding
(CoverageIndex -> Encoding)
-> (forall s. Decoder s CoverageIndex)
-> ([CoverageIndex] -> Encoding)
-> (forall s. Decoder s [CoverageIndex])
-> Serialise CoverageIndex
forall s. Decoder s [CoverageIndex]
forall s. Decoder s CoverageIndex
forall a.
(a -> Encoding)
-> (forall s. Decoder s a)
-> ([a] -> Encoding)
-> (forall s. Decoder s [a])
-> Serialise a
decodeList :: Decoder s [CoverageIndex]
$cdecodeList :: forall s. Decoder s [CoverageIndex]
encodeList :: [CoverageIndex] -> Encoding
$cencodeList :: [CoverageIndex] -> Encoding
decode :: Decoder s CoverageIndex
$cdecode :: forall s. Decoder s CoverageIndex
encode :: CoverageIndex -> Encoding
$cencode :: CoverageIndex -> Encoding
Serialise)
                      deriving Get CoverageIndex
CoverageIndex -> Encoding
CoverageIndex -> Int -> Int
(CoverageIndex -> Encoding)
-> Get CoverageIndex
-> (CoverageIndex -> Int -> Int)
-> Flat CoverageIndex
forall a. (a -> Encoding) -> Get a -> (a -> Int -> Int) -> Flat a
size :: CoverageIndex -> Int -> Int
$csize :: CoverageIndex -> Int -> Int
decode :: Get CoverageIndex
$cdecode :: Get CoverageIndex
encode :: CoverageIndex -> Encoding
$cencode :: CoverageIndex -> Encoding
Flat via (AsSerialize CoverageIndex)
                      deriving anyclass (CoverageIndex -> ()
(CoverageIndex -> ()) -> NFData CoverageIndex
forall a. (a -> ()) -> NFData a
rnf :: CoverageIndex -> ()
$crnf :: CoverageIndex -> ()
NFData, [CoverageIndex] -> Encoding
[CoverageIndex] -> Value
CoverageIndex -> Encoding
CoverageIndex -> Value
(CoverageIndex -> Value)
-> (CoverageIndex -> Encoding)
-> ([CoverageIndex] -> Value)
-> ([CoverageIndex] -> Encoding)
-> ToJSON CoverageIndex
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CoverageIndex] -> Encoding
$ctoEncodingList :: [CoverageIndex] -> Encoding
toJSONList :: [CoverageIndex] -> Value
$ctoJSONList :: [CoverageIndex] -> Value
toEncoding :: CoverageIndex -> Encoding
$ctoEncoding :: CoverageIndex -> Encoding
toJSON :: CoverageIndex -> Value
$ctoJSON :: CoverageIndex -> Value
ToJSON, Value -> Parser [CoverageIndex]
Value -> Parser CoverageIndex
(Value -> Parser CoverageIndex)
-> (Value -> Parser [CoverageIndex]) -> FromJSON CoverageIndex
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CoverageIndex]
$cparseJSONList :: Value -> Parser [CoverageIndex]
parseJSON :: Value -> Parser CoverageIndex
$cparseJSON :: Value -> Parser CoverageIndex
FromJSON)

makeLenses ''CoverageIndex

coverageAnnotations :: Getter CoverageIndex (Set CoverageAnnotation)
coverageAnnotations :: (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> CoverageIndex -> f CoverageIndex
coverageAnnotations = (Map CoverageAnnotation CoverageMetadata
 -> f (Map CoverageAnnotation CoverageMetadata))
-> CoverageIndex -> f CoverageIndex
Iso' CoverageIndex (Map CoverageAnnotation CoverageMetadata)
coverageMetadata ((Map CoverageAnnotation CoverageMetadata
  -> f (Map CoverageAnnotation CoverageMetadata))
 -> CoverageIndex -> f CoverageIndex)
-> ((Set CoverageAnnotation -> f (Set CoverageAnnotation))
    -> Map CoverageAnnotation CoverageMetadata
    -> f (Map CoverageAnnotation CoverageMetadata))
-> (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> CoverageIndex
-> f CoverageIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map CoverageAnnotation CoverageMetadata -> Set CoverageAnnotation)
-> (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> Map CoverageAnnotation CoverageMetadata
-> f (Map CoverageAnnotation CoverageMetadata)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to Map CoverageAnnotation CoverageMetadata -> Set CoverageAnnotation
forall k a. Map k a -> Set k
Map.keysSet

ignoredAnnotations :: Getter CoverageIndex (Set CoverageAnnotation)
ignoredAnnotations :: (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> CoverageIndex -> f CoverageIndex
ignoredAnnotations = (Map CoverageAnnotation CoverageMetadata
 -> f (Map CoverageAnnotation CoverageMetadata))
-> CoverageIndex -> f CoverageIndex
Iso' CoverageIndex (Map CoverageAnnotation CoverageMetadata)
coverageMetadata
                   ((Map CoverageAnnotation CoverageMetadata
  -> f (Map CoverageAnnotation CoverageMetadata))
 -> CoverageIndex -> f CoverageIndex)
-> ((Set CoverageAnnotation -> f (Set CoverageAnnotation))
    -> Map CoverageAnnotation CoverageMetadata
    -> f (Map CoverageAnnotation CoverageMetadata))
-> (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> CoverageIndex
-> f CoverageIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map CoverageAnnotation CoverageMetadata -> Set CoverageAnnotation)
-> (Set CoverageAnnotation -> f (Set CoverageAnnotation))
-> Map CoverageAnnotation CoverageMetadata
-> f (Map CoverageAnnotation CoverageMetadata)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (Map CoverageAnnotation CoverageMetadata -> Set CoverageAnnotation
forall k a. Map k a -> Set k
Map.keysSet (Map CoverageAnnotation CoverageMetadata -> Set CoverageAnnotation)
-> (Map CoverageAnnotation CoverageMetadata
    -> Map CoverageAnnotation CoverageMetadata)
-> Map CoverageAnnotation CoverageMetadata
-> Set CoverageAnnotation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CoverageMetadata -> Bool)
-> Map CoverageAnnotation CoverageMetadata
-> Map CoverageAnnotation CoverageMetadata
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Metadata -> Set Metadata -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member Metadata
IgnoredAnnotation (Set Metadata -> Bool)
-> (CoverageMetadata -> Set Metadata) -> CoverageMetadata -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoverageMetadata -> Set Metadata
_metadataSet))

instance Semigroup CoverageIndex where
  CoverageIndex
ci <> :: CoverageIndex -> CoverageIndex -> CoverageIndex
<> CoverageIndex
ci' = Map CoverageAnnotation CoverageMetadata -> CoverageIndex
CoverageIndex ((CoverageMetadata -> CoverageMetadata -> CoverageMetadata)
-> Map CoverageAnnotation CoverageMetadata
-> Map CoverageAnnotation CoverageMetadata
-> Map CoverageAnnotation CoverageMetadata
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith CoverageMetadata -> CoverageMetadata -> CoverageMetadata
forall a. Semigroup a => a -> a -> a
(<>) (CoverageIndex -> Map CoverageAnnotation CoverageMetadata
_coverageMetadata CoverageIndex
ci) (CoverageIndex -> Map CoverageAnnotation CoverageMetadata
_coverageMetadata CoverageIndex
ci'))

instance Monoid CoverageIndex where
  mempty :: CoverageIndex
mempty = Map CoverageAnnotation CoverageMetadata -> CoverageIndex
CoverageIndex Map CoverageAnnotation CoverageMetadata
forall k a. Map k a
Map.empty

-- | Include a location coverage annotation in the index
addLocationToCoverageIndex :: MonadWriter CoverageIndex m => CovLoc -> m CoverageAnnotation
addLocationToCoverageIndex :: CovLoc -> m CoverageAnnotation
addLocationToCoverageIndex CovLoc
src = do
  let ann :: CoverageAnnotation
ann = CovLoc -> CoverageAnnotation
CoverLocation CovLoc
src
  CoverageIndex -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell (CoverageIndex -> m ()) -> CoverageIndex -> m ()
forall a b. (a -> b) -> a -> b
$ Map CoverageAnnotation CoverageMetadata -> CoverageIndex
CoverageIndex (Map CoverageAnnotation CoverageMetadata -> CoverageIndex)
-> Map CoverageAnnotation CoverageMetadata -> CoverageIndex
forall a b. (a -> b) -> a -> b
$ CoverageAnnotation
-> CoverageMetadata -> Map CoverageAnnotation CoverageMetadata
forall k a. k -> a -> Map k a
Map.singleton CoverageAnnotation
ann CoverageMetadata
forall a. Monoid a => a
mempty
  CoverageAnnotation -> m CoverageAnnotation
forall (f :: * -> *) a. Applicative f => a -> f a
pure CoverageAnnotation
ann

-- | Include a boolean coverage annotation in the index
addBoolCaseToCoverageIndex :: MonadWriter CoverageIndex m => CovLoc -> Bool -> CoverageMetadata -> m CoverageAnnotation
addBoolCaseToCoverageIndex :: CovLoc -> Bool -> CoverageMetadata -> m CoverageAnnotation
addBoolCaseToCoverageIndex CovLoc
src Bool
b CoverageMetadata
meta = do
  let ann :: CoverageAnnotation
ann = CovLoc -> Bool -> CoverageAnnotation
boolCaseCoverageAnn CovLoc
src Bool
b
  CoverageIndex -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell (CoverageIndex -> m ()) -> CoverageIndex -> m ()
forall a b. (a -> b) -> a -> b
$ Map CoverageAnnotation CoverageMetadata -> CoverageIndex
CoverageIndex (CoverageAnnotation
-> CoverageMetadata -> Map CoverageAnnotation CoverageMetadata
forall k a. k -> a -> Map k a
Map.singleton CoverageAnnotation
ann CoverageMetadata
meta)
  CoverageAnnotation -> m CoverageAnnotation
forall (f :: * -> *) a. Applicative f => a -> f a
pure CoverageAnnotation
ann

-- | Add metadata to a coverage annotation. Does nothing if the annotation is not in the index.
addCoverageMetadata :: CoverageAnnotation -> Metadata -> CoverageIndex -> CoverageIndex
addCoverageMetadata :: CoverageAnnotation -> Metadata -> CoverageIndex -> CoverageIndex
addCoverageMetadata CoverageAnnotation
ann Metadata
meta CoverageIndex
idx = CoverageIndex
idx CoverageIndex -> (CoverageIndex -> CoverageIndex) -> CoverageIndex
forall a b. a -> (a -> b) -> b
& (Map CoverageAnnotation CoverageMetadata
 -> Identity (Map CoverageAnnotation CoverageMetadata))
-> CoverageIndex -> Identity CoverageIndex
Iso' CoverageIndex (Map CoverageAnnotation CoverageMetadata)
coverageMetadata ((Map CoverageAnnotation CoverageMetadata
  -> Identity (Map CoverageAnnotation CoverageMetadata))
 -> CoverageIndex -> Identity CoverageIndex)
-> ((Set Metadata -> Identity (Set Metadata))
    -> Map CoverageAnnotation CoverageMetadata
    -> Identity (Map CoverageAnnotation CoverageMetadata))
-> (Set Metadata -> Identity (Set Metadata))
-> CoverageIndex
-> Identity CoverageIndex
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Map CoverageAnnotation CoverageMetadata)
-> Lens'
     (Map CoverageAnnotation CoverageMetadata)
     (Maybe (IxValue (Map CoverageAnnotation CoverageMetadata)))
forall m. At m => Index m -> Lens' m (Maybe (IxValue m))
at Index (Map CoverageAnnotation CoverageMetadata)
CoverageAnnotation
ann ((Maybe CoverageMetadata -> Identity (Maybe CoverageMetadata))
 -> Map CoverageAnnotation CoverageMetadata
 -> Identity (Map CoverageAnnotation CoverageMetadata))
-> ((Set Metadata -> Identity (Set Metadata))
    -> Maybe CoverageMetadata -> Identity (Maybe CoverageMetadata))
-> (Set Metadata -> Identity (Set Metadata))
-> Map CoverageAnnotation CoverageMetadata
-> Identity (Map CoverageAnnotation CoverageMetadata)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CoverageMetadata -> Identity CoverageMetadata)
-> Maybe CoverageMetadata -> Identity (Maybe CoverageMetadata)
forall a b. Prism (Maybe a) (Maybe b) a b
_Just ((CoverageMetadata -> Identity CoverageMetadata)
 -> Maybe CoverageMetadata -> Identity (Maybe CoverageMetadata))
-> ((Set Metadata -> Identity (Set Metadata))
    -> CoverageMetadata -> Identity CoverageMetadata)
-> (Set Metadata -> Identity (Set Metadata))
-> Maybe CoverageMetadata
-> Identity (Maybe CoverageMetadata)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set Metadata -> Identity (Set Metadata))
-> CoverageMetadata -> Identity CoverageMetadata
Iso' CoverageMetadata (Set Metadata)
metadataSet ((Set Metadata -> Identity (Set Metadata))
 -> CoverageIndex -> Identity CoverageIndex)
-> (Set Metadata -> Set Metadata) -> CoverageIndex -> CoverageIndex
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Metadata -> Set Metadata -> Set Metadata
forall a. Ord a => a -> Set a -> Set a
Set.insert Metadata
meta

{-# INLINE boolCaseCoverageAnn #-}
boolCaseCoverageAnn :: CovLoc -> Bool -> CoverageAnnotation
boolCaseCoverageAnn :: CovLoc -> Bool -> CoverageAnnotation
boolCaseCoverageAnn CovLoc
src Bool
b = CovLoc -> Bool -> CoverageAnnotation
CoverBool CovLoc
src Bool
b

newtype CoverageData = CoverageData { CoverageData -> Set CoverageAnnotation
_coveredAnnotations :: Set CoverageAnnotation }
  deriving stock (Eq CoverageData
Eq CoverageData
-> (CoverageData -> CoverageData -> Ordering)
-> (CoverageData -> CoverageData -> Bool)
-> (CoverageData -> CoverageData -> Bool)
-> (CoverageData -> CoverageData -> Bool)
-> (CoverageData -> CoverageData -> Bool)
-> (CoverageData -> CoverageData -> CoverageData)
-> (CoverageData -> CoverageData -> CoverageData)
-> Ord CoverageData
CoverageData -> CoverageData -> Bool
CoverageData -> CoverageData -> Ordering
CoverageData -> CoverageData -> CoverageData
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CoverageData -> CoverageData -> CoverageData
$cmin :: CoverageData -> CoverageData -> CoverageData
max :: CoverageData -> CoverageData -> CoverageData
$cmax :: CoverageData -> CoverageData -> CoverageData
>= :: CoverageData -> CoverageData -> Bool
$c>= :: CoverageData -> CoverageData -> Bool
> :: CoverageData -> CoverageData -> Bool
$c> :: CoverageData -> CoverageData -> Bool
<= :: CoverageData -> CoverageData -> Bool
$c<= :: CoverageData -> CoverageData -> Bool
< :: CoverageData -> CoverageData -> Bool
$c< :: CoverageData -> CoverageData -> Bool
compare :: CoverageData -> CoverageData -> Ordering
$ccompare :: CoverageData -> CoverageData -> Ordering
$cp1Ord :: Eq CoverageData
Ord, CoverageData -> CoverageData -> Bool
(CoverageData -> CoverageData -> Bool)
-> (CoverageData -> CoverageData -> Bool) -> Eq CoverageData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageData -> CoverageData -> Bool
$c/= :: CoverageData -> CoverageData -> Bool
== :: CoverageData -> CoverageData -> Bool
$c== :: CoverageData -> CoverageData -> Bool
Eq, Int -> CoverageData -> ShowS
[CoverageData] -> ShowS
CoverageData -> String
(Int -> CoverageData -> ShowS)
-> (CoverageData -> String)
-> ([CoverageData] -> ShowS)
-> Show CoverageData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageData] -> ShowS
$cshowList :: [CoverageData] -> ShowS
show :: CoverageData -> String
$cshow :: CoverageData -> String
showsPrec :: Int -> CoverageData -> ShowS
$cshowsPrec :: Int -> CoverageData -> ShowS
Show, (forall x. CoverageData -> Rep CoverageData x)
-> (forall x. Rep CoverageData x -> CoverageData)
-> Generic CoverageData
forall x. Rep CoverageData x -> CoverageData
forall x. CoverageData -> Rep CoverageData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageData x -> CoverageData
$cfrom :: forall x. CoverageData -> Rep CoverageData x
Generic)
  deriving newtype (b -> CoverageData -> CoverageData
NonEmpty CoverageData -> CoverageData
CoverageData -> CoverageData -> CoverageData
(CoverageData -> CoverageData -> CoverageData)
-> (NonEmpty CoverageData -> CoverageData)
-> (forall b. Integral b => b -> CoverageData -> CoverageData)
-> Semigroup CoverageData
forall b. Integral b => b -> CoverageData -> CoverageData
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> CoverageData -> CoverageData
$cstimes :: forall b. Integral b => b -> CoverageData -> CoverageData
sconcat :: NonEmpty CoverageData -> CoverageData
$csconcat :: NonEmpty CoverageData -> CoverageData
<> :: CoverageData -> CoverageData -> CoverageData
$c<> :: CoverageData -> CoverageData -> CoverageData
Semigroup, Semigroup CoverageData
CoverageData
Semigroup CoverageData
-> CoverageData
-> (CoverageData -> CoverageData -> CoverageData)
-> ([CoverageData] -> CoverageData)
-> Monoid CoverageData
[CoverageData] -> CoverageData
CoverageData -> CoverageData -> CoverageData
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [CoverageData] -> CoverageData
$cmconcat :: [CoverageData] -> CoverageData
mappend :: CoverageData -> CoverageData -> CoverageData
$cmappend :: CoverageData -> CoverageData -> CoverageData
mempty :: CoverageData
$cmempty :: CoverageData
$cp1Monoid :: Semigroup CoverageData
Monoid)
  deriving anyclass (CoverageData -> ()
(CoverageData -> ()) -> NFData CoverageData
forall a. (a -> ()) -> NFData a
rnf :: CoverageData -> ()
$crnf :: CoverageData -> ()
NFData, [CoverageData] -> Encoding
[CoverageData] -> Value
CoverageData -> Encoding
CoverageData -> Value
(CoverageData -> Value)
-> (CoverageData -> Encoding)
-> ([CoverageData] -> Value)
-> ([CoverageData] -> Encoding)
-> ToJSON CoverageData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CoverageData] -> Encoding
$ctoEncodingList :: [CoverageData] -> Encoding
toJSONList :: [CoverageData] -> Value
$ctoJSONList :: [CoverageData] -> Value
toEncoding :: CoverageData -> Encoding
$ctoEncoding :: CoverageData -> Encoding
toJSON :: CoverageData -> Value
$ctoJSON :: CoverageData -> Value
ToJSON, Value -> Parser [CoverageData]
Value -> Parser CoverageData
(Value -> Parser CoverageData)
-> (Value -> Parser [CoverageData]) -> FromJSON CoverageData
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CoverageData]
$cparseJSONList :: Value -> Parser [CoverageData]
parseJSON :: Value -> Parser CoverageData
$cparseJSON :: Value -> Parser CoverageData
FromJSON)

makeLenses ''CoverageData

data CoverageReport = CoverageReport { CoverageReport -> CoverageIndex
_coverageIndex :: CoverageIndex
                                     , CoverageReport -> CoverageData
_coverageData  :: CoverageData }
  deriving stock (Eq CoverageReport
Eq CoverageReport
-> (CoverageReport -> CoverageReport -> Ordering)
-> (CoverageReport -> CoverageReport -> Bool)
-> (CoverageReport -> CoverageReport -> Bool)
-> (CoverageReport -> CoverageReport -> Bool)
-> (CoverageReport -> CoverageReport -> Bool)
-> (CoverageReport -> CoverageReport -> CoverageReport)
-> (CoverageReport -> CoverageReport -> CoverageReport)
-> Ord CoverageReport
CoverageReport -> CoverageReport -> Bool
CoverageReport -> CoverageReport -> Ordering
CoverageReport -> CoverageReport -> CoverageReport
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CoverageReport -> CoverageReport -> CoverageReport
$cmin :: CoverageReport -> CoverageReport -> CoverageReport
max :: CoverageReport -> CoverageReport -> CoverageReport
$cmax :: CoverageReport -> CoverageReport -> CoverageReport
>= :: CoverageReport -> CoverageReport -> Bool
$c>= :: CoverageReport -> CoverageReport -> Bool
> :: CoverageReport -> CoverageReport -> Bool
$c> :: CoverageReport -> CoverageReport -> Bool
<= :: CoverageReport -> CoverageReport -> Bool
$c<= :: CoverageReport -> CoverageReport -> Bool
< :: CoverageReport -> CoverageReport -> Bool
$c< :: CoverageReport -> CoverageReport -> Bool
compare :: CoverageReport -> CoverageReport -> Ordering
$ccompare :: CoverageReport -> CoverageReport -> Ordering
$cp1Ord :: Eq CoverageReport
Ord, CoverageReport -> CoverageReport -> Bool
(CoverageReport -> CoverageReport -> Bool)
-> (CoverageReport -> CoverageReport -> Bool) -> Eq CoverageReport
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CoverageReport -> CoverageReport -> Bool
$c/= :: CoverageReport -> CoverageReport -> Bool
== :: CoverageReport -> CoverageReport -> Bool
$c== :: CoverageReport -> CoverageReport -> Bool
Eq, Int -> CoverageReport -> ShowS
[CoverageReport] -> ShowS
CoverageReport -> String
(Int -> CoverageReport -> ShowS)
-> (CoverageReport -> String)
-> ([CoverageReport] -> ShowS)
-> Show CoverageReport
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CoverageReport] -> ShowS
$cshowList :: [CoverageReport] -> ShowS
show :: CoverageReport -> String
$cshow :: CoverageReport -> String
showsPrec :: Int -> CoverageReport -> ShowS
$cshowsPrec :: Int -> CoverageReport -> ShowS
Show, (forall x. CoverageReport -> Rep CoverageReport x)
-> (forall x. Rep CoverageReport x -> CoverageReport)
-> Generic CoverageReport
forall x. Rep CoverageReport x -> CoverageReport
forall x. CoverageReport -> Rep CoverageReport x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CoverageReport x -> CoverageReport
$cfrom :: forall x. CoverageReport -> Rep CoverageReport x
Generic)
  deriving anyclass (CoverageReport -> ()
(CoverageReport -> ()) -> NFData CoverageReport
forall a. (a -> ()) -> NFData a
rnf :: CoverageReport -> ()
$crnf :: CoverageReport -> ()
NFData, [CoverageReport] -> Encoding
[CoverageReport] -> Value
CoverageReport -> Encoding
CoverageReport -> Value
(CoverageReport -> Value)
-> (CoverageReport -> Encoding)
-> ([CoverageReport] -> Value)
-> ([CoverageReport] -> Encoding)
-> ToJSON CoverageReport
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [CoverageReport] -> Encoding
$ctoEncodingList :: [CoverageReport] -> Encoding
toJSONList :: [CoverageReport] -> Value
$ctoJSONList :: [CoverageReport] -> Value
toEncoding :: CoverageReport -> Encoding
$ctoEncoding :: CoverageReport -> Encoding
toJSON :: CoverageReport -> Value
$ctoJSON :: CoverageReport -> Value
ToJSON, Value -> Parser [CoverageReport]
Value -> Parser CoverageReport
(Value -> Parser CoverageReport)
-> (Value -> Parser [CoverageReport]) -> FromJSON CoverageReport
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CoverageReport]
$cparseJSONList :: Value -> Parser [CoverageReport]
parseJSON :: Value -> Parser CoverageReport
$cparseJSON :: Value -> Parser CoverageReport
FromJSON)

makeLenses ''CoverageReport

instance Semigroup CoverageReport where
  CoverageReport CoverageIndex
i1 CoverageData
d1 <> :: CoverageReport -> CoverageReport -> CoverageReport
<> CoverageReport CoverageIndex
i2 CoverageData
d2 = CoverageIndex -> CoverageData -> CoverageReport
CoverageReport (CoverageIndex
i1 CoverageIndex -> CoverageIndex -> CoverageIndex
forall a. Semigroup a => a -> a -> a
<> CoverageIndex
i2) (CoverageData
d1 CoverageData -> CoverageData -> CoverageData
forall a. Semigroup a => a -> a -> a
<> CoverageData
d2)

instance Monoid CoverageReport where
  mempty :: CoverageReport
mempty  = CoverageIndex -> CoverageData -> CoverageReport
CoverageReport CoverageIndex
forall a. Monoid a => a
mempty CoverageData
forall a. Monoid a => a
mempty
  mappend :: CoverageReport -> CoverageReport -> CoverageReport
mappend = CoverageReport -> CoverageReport -> CoverageReport
forall a. Semigroup a => a -> a -> a
(<>)

coverageDataFromLogMsg :: String -> CoverageData
coverageDataFromLogMsg :: String -> CoverageData
coverageDataFromLogMsg = (CoverageAnnotation -> CoverageData)
-> Maybe CoverageAnnotation -> CoverageData
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Set CoverageAnnotation -> CoverageData
CoverageData (Set CoverageAnnotation -> CoverageData)
-> (CoverageAnnotation -> Set CoverageAnnotation)
-> CoverageAnnotation
-> CoverageData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CoverageAnnotation -> Set CoverageAnnotation
forall a. a -> Set a
Set.singleton) (Maybe CoverageAnnotation -> CoverageData)
-> (String -> Maybe CoverageAnnotation) -> String -> CoverageData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe CoverageAnnotation
forall a. Read a => String -> Maybe a
readMaybe

instance Pretty CoverageReport where
  pretty :: CoverageReport -> Doc ann
pretty CoverageReport
report =
    [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann
"=========[COVERED]=========="] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++
           [ Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
4 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep (CoverageAnnotation -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty CoverageAnnotation
ann Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: ((Metadata -> Doc ann) -> [Metadata] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Metadata -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([Metadata] -> [Doc ann])
-> (Maybe CoverageMetadata -> [Metadata])
-> Maybe CoverageMetadata
-> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Metadata -> [Metadata]
forall a. Set a -> [a]
Set.toList (Set Metadata -> [Metadata])
-> (Maybe CoverageMetadata -> Set Metadata)
-> Maybe CoverageMetadata
-> [Metadata]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CoverageMetadata -> Set Metadata)
-> Maybe CoverageMetadata -> Set Metadata
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap CoverageMetadata -> Set Metadata
_metadataSet (Maybe CoverageMetadata -> [Doc ann])
-> Maybe CoverageMetadata -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ CoverageAnnotation -> Maybe CoverageMetadata
metadata CoverageAnnotation
ann))
           | CoverageAnnotation
ann <- Set CoverageAnnotation -> [CoverageAnnotation]
forall a. Set a -> [a]
Set.toList (Set CoverageAnnotation -> [CoverageAnnotation])
-> Set CoverageAnnotation -> [CoverageAnnotation]
forall a b. (a -> b) -> a -> b
$ Set CoverageAnnotation
allAnns Set CoverageAnnotation
-> Set CoverageAnnotation -> Set CoverageAnnotation
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set CoverageAnnotation
coveredAnns ] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++
           [Doc ann
"========[UNCOVERED]========="] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++
           ((CoverageAnnotation -> Doc ann)
-> [CoverageAnnotation] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map CoverageAnnotation -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([CoverageAnnotation] -> [Doc ann])
-> (Set CoverageAnnotation -> [CoverageAnnotation])
-> Set CoverageAnnotation
-> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set CoverageAnnotation -> [CoverageAnnotation]
forall a. Set a -> [a]
Set.toList (Set CoverageAnnotation -> [Doc ann])
-> Set CoverageAnnotation -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ Set CoverageAnnotation
uncoveredAnns) [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++
           [Doc ann
"=========[IGNORED]=========="] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. [a] -> [a] -> [a]
++
           ((CoverageAnnotation -> Doc ann)
-> [CoverageAnnotation] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map CoverageAnnotation -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([CoverageAnnotation] -> [Doc ann])
-> (Set CoverageAnnotation -> [CoverageAnnotation])
-> Set CoverageAnnotation
-> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set CoverageAnnotation -> [CoverageAnnotation]
forall a. Set a -> [a]
Set.toList (Set CoverageAnnotation -> [Doc ann])
-> Set CoverageAnnotation -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ Set CoverageAnnotation
ignoredAnns Set CoverageAnnotation
-> Set CoverageAnnotation -> Set CoverageAnnotation
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ Set CoverageAnnotation
coveredAnns)
    where
      allAnns :: Set CoverageAnnotation
allAnns       = CoverageReport
report CoverageReport
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
-> Set CoverageAnnotation
forall s a. s -> Getting a s a -> a
^. (CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
-> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport
Lens' CoverageReport CoverageIndex
coverageIndex ((CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
 -> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport)
-> ((Set CoverageAnnotation
     -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
    -> CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set CoverageAnnotation
 -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
-> CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex
Getter CoverageIndex (Set CoverageAnnotation)
coverageAnnotations
      coveredAnns :: Set CoverageAnnotation
coveredAnns   = CoverageReport
report CoverageReport
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
-> Set CoverageAnnotation
forall s a. s -> Getting a s a -> a
^. (CoverageData -> Const (Set CoverageAnnotation) CoverageData)
-> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport
Lens' CoverageReport CoverageData
coverageData  ((CoverageData -> Const (Set CoverageAnnotation) CoverageData)
 -> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport)
-> ((Set CoverageAnnotation
     -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
    -> CoverageData -> Const (Set CoverageAnnotation) CoverageData)
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set CoverageAnnotation
 -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
-> CoverageData -> Const (Set CoverageAnnotation) CoverageData
Iso' CoverageData (Set CoverageAnnotation)
coveredAnnotations
      ignoredAnns :: Set CoverageAnnotation
ignoredAnns   = CoverageReport
report CoverageReport
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
-> Set CoverageAnnotation
forall s a. s -> Getting a s a -> a
^. (CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
-> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport
Lens' CoverageReport CoverageIndex
coverageIndex ((CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
 -> CoverageReport -> Const (Set CoverageAnnotation) CoverageReport)
-> ((Set CoverageAnnotation
     -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
    -> CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex)
-> Getting
     (Set CoverageAnnotation) CoverageReport (Set CoverageAnnotation)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set CoverageAnnotation
 -> Const (Set CoverageAnnotation) (Set CoverageAnnotation))
-> CoverageIndex -> Const (Set CoverageAnnotation) CoverageIndex
Getter CoverageIndex (Set CoverageAnnotation)
ignoredAnnotations
      uncoveredAnns :: Set CoverageAnnotation
uncoveredAnns = Set CoverageAnnotation
allAnns Set CoverageAnnotation
-> Set CoverageAnnotation -> Set CoverageAnnotation
forall a. Ord a => Set a -> Set a -> Set a
Set.\\ (Set CoverageAnnotation
coveredAnns Set CoverageAnnotation
-> Set CoverageAnnotation -> Set CoverageAnnotation
forall a. Semigroup a => a -> a -> a
<> Set CoverageAnnotation
ignoredAnns)

      metadata :: CoverageAnnotation -> Maybe CoverageMetadata
metadata CoverageAnnotation
ann = CoverageAnnotation
-> Map CoverageAnnotation CoverageMetadata
-> Maybe CoverageMetadata
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup CoverageAnnotation
ann (CoverageReport
report CoverageReport
-> Getting
     (Map CoverageAnnotation CoverageMetadata)
     CoverageReport
     (Map CoverageAnnotation CoverageMetadata)
-> Map CoverageAnnotation CoverageMetadata
forall s a. s -> Getting a s a -> a
^. (CoverageIndex
 -> Const (Map CoverageAnnotation CoverageMetadata) CoverageIndex)
-> CoverageReport
-> Const (Map CoverageAnnotation CoverageMetadata) CoverageReport
Lens' CoverageReport CoverageIndex
coverageIndex ((CoverageIndex
  -> Const (Map CoverageAnnotation CoverageMetadata) CoverageIndex)
 -> CoverageReport
 -> Const (Map CoverageAnnotation CoverageMetadata) CoverageReport)
-> ((Map CoverageAnnotation CoverageMetadata
     -> Const
          (Map CoverageAnnotation CoverageMetadata)
          (Map CoverageAnnotation CoverageMetadata))
    -> CoverageIndex
    -> Const (Map CoverageAnnotation CoverageMetadata) CoverageIndex)
-> Getting
     (Map CoverageAnnotation CoverageMetadata)
     CoverageReport
     (Map CoverageAnnotation CoverageMetadata)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map CoverageAnnotation CoverageMetadata
 -> Const
      (Map CoverageAnnotation CoverageMetadata)
      (Map CoverageAnnotation CoverageMetadata))
-> CoverageIndex
-> Const (Map CoverageAnnotation CoverageMetadata) CoverageIndex
Iso' CoverageIndex (Map CoverageAnnotation CoverageMetadata)
coverageMetadata)