module Development.Bake.Server.Property(
rejectable, plausible, mergeable,
extendActive, restrictActive
) where
import Development.Bake.Server.Memory
import Development.Bake.Server.Store
import qualified Data.Set as Set
import qualified Data.Map as Map
import Development.Bake.Core.Type
import Data.Maybe
import General.Extra
import Data.List
rejectable :: Memory -> [(Patch, Maybe Test)]
rejectable Memory{..} =
[(last ps, t)
| ps <- tail $ inits $ snd active
, let me = storePoint store (fst active, ps)
, let prev = if length ps == 1 then piState else storePoint store (fst active, init ps)
, t <- failed
, poTest me t == Just False && poTest prev t == Just True]
where
piState = PointInfo (Just Set.empty) (Set.singleton Nothing) Set.empty
failed = Set.toList $ poFail $ storePoint store active
plausible :: Memory -> Bool
plausible Memory{..}
| all (isNothing . paReject . storePatch store) $ snd active
, PointInfo{..} <- storePoint store active
, Just tests <- poTodo
, Set.null poFail
, tests `Set.isSubsetOf` Set.union (storeSupersetPass store active) (catMaybesSet poPass)
= True
plausible _ = False
mergeable :: Memory -> Bool
mergeable mem@Memory{..}
| plausible mem
, PointInfo{..} <- storePoint store active
, Just tests <- poTodo
, tests == catMaybesSet poPass
= True
mergeable _ = False
extendActive :: Memory -> Bool
extendActive Memory{..} = all (isJust . paPlausible . storePatch store) $ snd active
restrictActive :: Memory -> Bool
restrictActive Memory{..}
| Nothing `Set.member` rejectedTests = True
| not $ Set.null rejectedTests
, PointInfo{..} <- storePoint store active
, Just tests <- poTodo
, let pass = Set.union (storeSupersetPass store active) $ catMaybesSet $ poPass `Set.difference` poFail
, flip all (Set.toList tests) $ \t ->
t `Set.member` pass || any (flip Set.member rejectedTests . Just) (transitiveClosure (testDepend . ovenTestInfo oven) [t]) = True
| otherwise = False
where
rejectedTests = Set.unions $ mapMaybe (fmap (Map.keysSet . snd) . paReject . storePatch store) $ snd active