-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | refining property sets for testing Haskell programs -- -- FitSpec provides automated assistance in the task of refining test -- properties for Haskell functions. -- -- FitSpec tests mutant variations of functions under test against a -- given property set, recording any surviving mutants that pass all -- tests. FitSpec then reports: -- -- @package fitspec @version 0.3.1 -- | Show mutant variations module Test.FitSpec.ShowMutable -- | Types that can have their mutation shown. Has only one function -- mutantS that returns a simple AST (MutantS) representing -- the mutant. A standard implementation of mutantS for Eq -- types is given by mutantSEq. class ShowMutable a mutantS :: ShowMutable a => a -> a -> MutantS -- | For a given type Type instance of Eq and -- Show, define the ShowMutable instance as: -- --
--   instance ShowMutable Type
--     where mutantS = mutantSEq
--   
mutantSEq :: (Eq a, Show a) => a -> a -> MutantS -- | Show a Mutant as a tuple of lambdas. -- --
--    > putStrLn $ showMutantAsTuple ["p && q","not p"] ((&&),not) ((||),id)
--    ( \p q -> case (p,q) of
--               (False,False) -> True
--               _ -> p && q
--   , \p -> case p of
--             False -> False
--             True -> True
--             _ -> not p )
--   
-- -- Can be easily copy pasted into an interactive session for -- manipulation. On GHCi, use :{ and :} to allow -- multi-line expressions and definitions. showMutantAsTuple :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as a tuple of nested lambdas. Very similar to -- showMutantAsTuple, but the underlying data structure is not -- flatten: so the output is as close as possible to the underlying -- representation. showMutantNested :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as a new complete top-level definition, with a prime -- appended to the name of the mutant. -- --
--   > putStrLn $ showMutantDefinition ["p && q","not p"] ((&&),not) ((==),id)
--   False &&- False = True
--   p     &&- q     = p && q
--   not' False = False
--   not' True  = True
--   not' p     = not p
--   
showMutantDefinition :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as the list of bindings that differ from the original -- function(s). -- --
--   > putStrLn $ showMutantBindings ["p && q","not p"] ((&&),not) ((==),id)
--   False && False = True
--   not False = False
--   not True  = True
--   
-- -- Can possibly be copied into the source of the original function for -- manipulation. showMutantBindings :: ShowMutable a => [String] -> a -> a -> String -- | (Show) Structure of a mutant. This format is intended for processing -- then pretty-printing. data MutantS mutantSTuple :: [MutantS] -> MutantS instance GHC.Show.Show Test.FitSpec.ShowMutable.MutantS instance Test.FitSpec.ShowMutable.ShowMutable () instance Test.FitSpec.ShowMutable.ShowMutable GHC.Types.Int instance Test.FitSpec.ShowMutable.ShowMutable GHC.Types.Char instance Test.FitSpec.ShowMutable.ShowMutable GHC.Types.Bool instance (GHC.Classes.Eq a, GHC.Show.Show a) => Test.FitSpec.ShowMutable.ShowMutable [a] instance (GHC.Classes.Eq a, GHC.Show.Show a) => Test.FitSpec.ShowMutable.ShowMutable (GHC.Base.Maybe a) instance (Test.LeanCheck.Core.Listable a, GHC.Show.Show a, Test.FitSpec.ShowMutable.ShowMutable b) => Test.FitSpec.ShowMutable.ShowMutable (a -> b) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b) => Test.FitSpec.ShowMutable.ShowMutable (a, b) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f) -- | ShowMutable instances: septuples up to 12-tuples -- -- This is partly a Hack that allows those instances to be hidden from -- Haddock. Otherwise Haddock documentation will look very ugly. It also -- makes Test.FitSpec.ShowMutable more readable. module Test.FitSpec.ShowMutable.Tuples instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, g) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g, Test.FitSpec.ShowMutable.ShowMutable h) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, g, h) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g, Test.FitSpec.ShowMutable.ShowMutable h, Test.FitSpec.ShowMutable.ShowMutable i) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, g, h, i) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g, Test.FitSpec.ShowMutable.ShowMutable h, Test.FitSpec.ShowMutable.ShowMutable i, Test.FitSpec.ShowMutable.ShowMutable j) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, h, g, i, j) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g, Test.FitSpec.ShowMutable.ShowMutable h, Test.FitSpec.ShowMutable.ShowMutable i, Test.FitSpec.ShowMutable.ShowMutable j, Test.FitSpec.ShowMutable.ShowMutable k) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, g, h, i, j, k) instance (Test.FitSpec.ShowMutable.ShowMutable a, Test.FitSpec.ShowMutable.ShowMutable b, Test.FitSpec.ShowMutable.ShowMutable c, Test.FitSpec.ShowMutable.ShowMutable d, Test.FitSpec.ShowMutable.ShowMutable e, Test.FitSpec.ShowMutable.ShowMutable f, Test.FitSpec.ShowMutable.ShowMutable g, Test.FitSpec.ShowMutable.ShowMutable h, Test.FitSpec.ShowMutable.ShowMutable i, Test.FitSpec.ShowMutable.ShowMutable j, Test.FitSpec.ShowMutable.ShowMutable k, Test.FitSpec.ShowMutable.ShowMutable l) => Test.FitSpec.ShowMutable.ShowMutable (a, b, c, d, e, f, g, h, i, j, k, l) -- | Enumeration of function mutations module Test.FitSpec.Mutable -- | This typeclass is similar to Listable. -- -- A type is Mutable when there exists a function that is able to -- list mutations of a value. Ideally: list all possible values without -- repetitions. -- -- Instances are usually defined by a mutiers function that given -- a value, returns tiers of mutants of that value: the first tier -- contains the equivalent mutant, of size 0, the second tier contains -- mutants of size 1, the third tier contains mutants of size 2, and so -- on. -- -- The equivalent mutant is the actual function without mutations. -- -- The size of a mutant is given by the sum of: the number of mutated -- points (relations) and the sizes of mutated arguments and results. -- -- To get only inequivalent mutants, just take the tail of either -- mutants or mutiers: -- --
--   tail mutants
--   
-- --
--   tail mutiers
--   
-- -- Given that the underlying Listable enumeration has no -- repetitions, parametric instances defined in this file will have no -- repeated mutants. class Mutable a where mutiers = map (: []) . mutants mutants = concat . mutiers mutiers :: Mutable a => a -> [[a]] mutants :: Mutable a => a -> [a] -- | Implementation of mutiers for non-functional data types. Use -- this to create instances for user-defined data types, e.g.: -- --
--   instance MyData
--     where mutiers = mutiersEq
--   
-- -- and for parametric datatypes: -- --
--   instance (Eq a, Eq b) => MyDt a b
--     where mutiers = mutiersEq
--   
-- -- Examples: -- --
--   mutiersEq True = [[True], [False]]
--   mutiersEq 2   = [[2], [0], [1], [], [3], [4], [5], [6], [7], [8], [9], ...]
--   mutiersEq [1] = [[[1]], [[]], [[0]], [[0,0]], [[0,0,0],[0,1],[1,0],[-1]], ...]
--   
mutiersEq :: (Listable a, Eq a) => a -> [[a]] instance Test.FitSpec.Mutable.Mutable () instance Test.FitSpec.Mutable.Mutable GHC.Types.Int instance Test.FitSpec.Mutable.Mutable GHC.Types.Char instance Test.FitSpec.Mutable.Mutable GHC.Types.Bool instance (GHC.Classes.Eq a, Test.LeanCheck.Core.Listable a) => Test.FitSpec.Mutable.Mutable [a] instance (GHC.Classes.Eq a, Test.LeanCheck.Core.Listable a) => Test.FitSpec.Mutable.Mutable (GHC.Base.Maybe a) instance (GHC.Classes.Eq a, Test.LeanCheck.Core.Listable a, Test.FitSpec.Mutable.Mutable b) => Test.FitSpec.Mutable.Mutable (a -> b) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b) => Test.FitSpec.Mutable.Mutable (a, b) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c) => Test.FitSpec.Mutable.Mutable (a, b, c) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d) => Test.FitSpec.Mutable.Mutable (a, b, c, d) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f) -- | Mutable instances: septuples up to 12-tuples -- -- This is partly a Hack that allows those instances to be hidden from -- Haddock. Otherwise Haddock documentation will look very ugly. It also -- makes Test.FitSpec.ShowMutable more readable. -- -- This module is already exported by Test.FitSpec, so it is not -- needed to import this explictly. module Test.FitSpec.Mutable.Tuples instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g, Test.FitSpec.Mutable.Mutable h) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g, h) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g, Test.FitSpec.Mutable.Mutable h, Test.FitSpec.Mutable.Mutable i) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g, h, i) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g, Test.FitSpec.Mutable.Mutable h, Test.FitSpec.Mutable.Mutable i, Test.FitSpec.Mutable.Mutable j) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g, h, i, j) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g, Test.FitSpec.Mutable.Mutable h, Test.FitSpec.Mutable.Mutable i, Test.FitSpec.Mutable.Mutable j, Test.FitSpec.Mutable.Mutable k) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g, h, i, j, k) instance (Test.FitSpec.Mutable.Mutable a, Test.FitSpec.Mutable.Mutable b, Test.FitSpec.Mutable.Mutable c, Test.FitSpec.Mutable.Mutable d, Test.FitSpec.Mutable.Mutable e, Test.FitSpec.Mutable.Mutable f, Test.FitSpec.Mutable.Mutable g, Test.FitSpec.Mutable.Mutable h, Test.FitSpec.Mutable.Mutable i, Test.FitSpec.Mutable.Mutable j, Test.FitSpec.Mutable.Mutable k, Test.FitSpec.Mutable.Mutable l) => Test.FitSpec.Mutable.Mutable (a, b, c, d, e, f, g, h, i, j, k, l) -- | Experimental module for deriving Mutable and ShowMutable -- instances -- -- Needs GHC and Template Haskell (tested on GHC 7.4, 7.6, 7.8, 7.10 and -- 8.0) -- -- Despite Mutable instances being actually very simple to write -- manually, this module can be used to derive those instances -- automatically. However, it will not work on all cases: when that -- happens, you should write your instances manually. -- -- If FitSpec does not compile under later GHCs, this module is probably -- the culprit. module Test.FitSpec.Derive -- | Derives Mutable, ShowMutable and (optionally) -- Listable instances for a given type Name. -- -- Consider the following Stack datatype: -- --
--   data Stack a = Stack a (Stack a) | Empty
--   
-- -- Writing -- --
--   deriveMutable ''Stack
--   
-- -- will automatically derive the following Listable, -- Mutable and ShowMutable instances: -- --
--   instance Listable a => Listable (Stack a) where
--     tiers = cons2 Stack \/ cons0 Empty
--   
--   instance (Eq a, Listable a) => Mutable a
--     where mutiers = mutiersEq
--   
--   instance (Eq a, Show a) => ShowMutable a
--     where mutantS = mutantSEq
--   
-- -- If a Listable instance already exists, it is not derived. (cf.: -- deriveListable) -- -- Needs the TemplateHaskell extension. deriveMutable :: Name -> DecsQ -- | Derives a Mutable instance for a given type Name using a given -- context for all type variables. deriveMutableE :: [Name] -> Name -> DecsQ -- | FitSpec: refining property-sets for functional testing -- -- This is the main engine, besides Test.FitSpec.Mutable. module Test.FitSpec.Engine -- | Given a Testable type (as defined by LeanCheck), returns -- a Property. -- -- This function should be used on every property to create a property -- list to be passed to report, reportWith, -- mainDefault or mainWith. -- --
--   property $ \x y -> x + y < y + (x::Int)
--   
property :: Testable a => a -> Property -- | An encoded representation of a property suitable for use by FitSpec. -- -- Each list of strings is a printable representation of one possible -- choice of argument values for the property. Each boolean indicate -- whether the property holds for this choice. type Property = [([String], Bool)] -- | Return minimality and completeness results. See report. getResults :: (Mutable a) => a -> (a -> [Property]) -> Int -> Int -> Results a getResultsExtra :: (Mutable a) => [a] -> a -> (a -> [Property]) -> Int -> Int -> Results a getResultsExtraTimeout :: (Mutable a) => Int -> [a] -> a -> (a -> [Property]) -> Int -> Int -> IO (Results a) -- | A line of result for a single equivalence class of properties with the -- exact same surviving mutants. data Result a Result :: [[Int]] -> [Int] -> [a] -> Maybe a -> Int -> Int -> Int -> Int -> Int -> Bool -> Result a -- | property-sets in the equivalence class [sets] :: Result a -> [[Int]] -- | properties implied by this class [implied] :: Result a -> [Int] -- | list of surviving mutants [survivors] :: Result a -> [a] -- | smallest surviving mutant, if any [smallestSurvivor] :: Result a -> Maybe a -- | number of surviving mutants [nSurvivors] :: Result a -> Int -- | number of killed mutants [nKilled] :: Result a -> Int -- | total number of mutants generated and tested [totalMutants] :: Result a -> Int -- | percentage of killed mutants, 0-100 [score] :: Result a -> Int -- | Requested number of tests (same for all rs.) [maxTests] :: Result a -> Int -- | mutants were exhausted [mutantsExhausted] :: Result a -> Bool type Results a = [Result a] propertiesNTests :: Int -> [Property] -> [Int] propertiesTestsExhausted :: Int -> [Property] -> [Bool] propertiesToMap :: [Property] -> Int -> [Bool] propertiesHold :: Int -> [Property] -> Bool propertiesCE :: Int -> [Property] -> Maybe String minimal :: Results a -> Bool complete :: Results a -> Bool reduceImplications :: [Result a] -> [Result a] filterNonCanon :: [Result a] -> [Result a] data Conjecture Conjecture :: Bool -> Bool -> [Int] -> [Int] -> Int -> Int -> Int -> Conjecture [isEq] :: Conjecture -> Bool [isIm] :: Conjecture -> Bool [cleft] :: Conjecture -> [Int] [cright] :: Conjecture -> [Int] [cscore] :: Conjecture -> Int [cnKilled] :: Conjecture -> Int [cnSurvivors] :: Conjecture -> Int conjectures :: [Result a] -> [Conjecture] instance GHC.Show.Show Test.FitSpec.Engine.Conjecture -- | Generate FitSpec reports. module Test.FitSpec.Report -- | Report results generated by FitSpec. Uses standard configuration (see -- args). Needs a function to be mutated and a property map. -- Example (specification of boolean negation): -- --
--   properties not =
--     [ property $ \p -> not (not p) == p
--     , property $ \p -> not (not (not p)) == not p
--     ]
--   
--   main = report not properties
--   
report :: (Mutable a, ShowMutable a) => a -> (a -> [Property]) -> IO () -- | Same as report but can be configured via Args -- (args or fixargs), e.g.: -- --
--   reportWith args { timeout = 10 } fun properties
--   
reportWith :: (Mutable a, ShowMutable a) => Args -> a -> (a -> [Property]) -> IO () -- | Same as reportWith, but accepts a list of manually defined -- (extra) mutants to be tested alongside those automatically generated. reportWithExtra :: (Mutable a, ShowMutable a) => [a] -> Args -> a -> (a -> [Property]) -> IO () -- | Extra arguments / configuration for reportWith. See args -- for default values. data Args Args :: Int -> Int -> Int -> [String] -> Bool -> ShowMutantAs -> Maybe Int -> [String] -> Args -- | (starting) number of function mutations [nMutants] :: Args -> Int -- | (starting) number of test values (for each prop.) [nTests] :: Args -> Int -- | timeout in seconds, 0 for just nTests * nMutants [timeout] :: Args -> Int -- | names of functions: ["foo x y","goo x y"] [names] :: Args -> [String] -- | whether to show detailed results [verbose] :: Args -> Bool -- | how to show mutants [showMutantAs] :: Args -> ShowMutantAs -- | number of surviving mutants to show [rows] :: Args -> Maybe Int -- | ignored argument (user defined meaning) [extra] :: Args -> [String] -- | Default arguments for reportWith: -- -- -- --
--   ["f x y z", "g x y z", "h x y z", ...]
--   
args :: Args -- | Non timed-out default arguments. Make conjectures based on a fixed -- number of mutants and tests, e.g.: -- --
--   reportWith (fixargs 100 200) f pmap
--   
-- -- This is just a shorthand, see: -- --
--   fixargs nm nt  =  args { nMutants = nm, nTests = nt, timeout = 0 }
--   
-- --
--   (fixargs nm nt) { nMutants = 500, nTests = 1000, timeout = 5 }  =  args
--   
fixargs :: Int -> Int -> Args -- | An encoded representation of a property suitable for use by FitSpec. -- -- Each list of strings is a printable representation of one possible -- choice of argument values for the property. Each boolean indicate -- whether the property holds for this choice. type Property = [([String], Bool)] -- | How to show mutants. Use this to fill showMutantAs. data ShowMutantAs Tuple :: ShowMutantAs NestedTuple :: ShowMutantAs Definition :: ShowMutantAs Bindings :: ShowMutantAs -- | Exports "main" functions for FitSpec. They work exactly by -- report and reportWith but can be customized by command -- line arguments. -- --
--   main = mainWith args { ... } functions properties
--   
module Test.FitSpec.Main -- | Same as reportWith, but allow overriding of configuration via -- command line arguments. mainWith :: (Mutable a, ShowMutable a) => Args -> a -> (a -> [Property]) -> IO () -- | Same as report, but allow configuration via command line -- arguments. defaultMain :: (Mutable a, ShowMutable a) => a -> (a -> [Property]) -> IO () getArgs :: IO Args getArgsWith :: Args -> IO Args instance Data.Data.Data Test.FitSpec.Report.ShowMutantAs instance Data.Data.Data Test.FitSpec.Report.Args -- | FitSpec's Test Types: Nat, Int2, Int3, -- Int4, UInt2, UInt3, UInt4. -- -- This module re-exports Test.LeanCheck.Utils.Types module and -- defines Mutable and ShowMutable instances for the types -- defined there. module Test.FitSpec.TestTypes instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Nat instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Int1 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Int2 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Int3 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Int4 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Word1 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Word2 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Word3 instance Test.FitSpec.Mutable.Mutable Test.LeanCheck.Utils.Types.Word4 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Nat instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Int1 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Int2 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Int3 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Int4 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Word1 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Word2 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Word3 instance Test.FitSpec.ShowMutable.ShowMutable Test.LeanCheck.Utils.Types.Word4 -- | FitSpec: refining property-sets for functional testing -- -- FitSpec provides automated assistance in the task of refining test -- properties for Haskell functions. FitSpec tests mutant variations of -- functions under test against a given property set, recording any -- surviving mutants that pass all tests. FitSpec then reports: -- -- -- -- Example, refining a sort specification: -- --
--   import Test.FitSpec
--   import Data.List (sort)
--   
--   properties sort =
--     [ property $ \xs   -> ordered (sort xs)
--     , property $ \xs   -> length (sort xs) == length xs
--     , property $ \x xs -> elem x (sort xs) == elem x xs
--     , property $ \x xs -> notElem x (sort xs) == notElem x xs
--     , property $ \x xs -> minimum (x:xs) == head (sort (x:xs))
--     ]
--     where
--     ordered (x:y:xs) = x <= y && ordered (y:xs)
--     ordered _        = True
--   
--   main = mainWith args { names = ["sort xs"]
--                        , nMutants = 4000
--                        , nTests   = 4000
--                        , timeout  = 0
--                        }
--                   (sort::[Word2]->[Word2])
--                   properties
--   
-- -- The above program reports the following: -- --
--   Apparent incomplete and non-minimal specification based on
--   4000 test cases for each of properties 1, 2, 3, 4 and 5
--   for each of 4000 mutant variations.
--   
--   3 survivors (99% killed), smallest:
--     \xs -> case xs of
--              [0,0,1] -> [0,1,1]
--              _ -> sort xs
--   
--   apparent minimal property subsets:  {1,2,3} {1,2,4}
--   conjectures:  {3}    =  {4}     96% killed (weak)
--                 {1,3} ==> {5}     98% killed (weak)
--   
module Test.FitSpec -- | An encoded representation of a property suitable for use by FitSpec. -- -- Each list of strings is a printable representation of one possible -- choice of argument values for the property. Each boolean indicate -- whether the property holds for this choice. type Property = [([String], Bool)] -- | Given a Testable type (as defined by LeanCheck), returns -- a Property. -- -- This function should be used on every property to create a property -- list to be passed to report, reportWith, -- mainDefault or mainWith. -- --
--   property $ \x y -> x + y < y + (x::Int)
--   
property :: Testable a => a -> Property -- | Extra arguments / configuration for reportWith. See args -- for default values. data Args Args :: Int -> Int -> Int -> [String] -> Bool -> ShowMutantAs -> Maybe Int -> [String] -> Args -- | (starting) number of function mutations [nMutants] :: Args -> Int -- | (starting) number of test values (for each prop.) [nTests] :: Args -> Int -- | timeout in seconds, 0 for just nTests * nMutants [timeout] :: Args -> Int -- | names of functions: ["foo x y","goo x y"] [names] :: Args -> [String] -- | whether to show detailed results [verbose] :: Args -> Bool -- | how to show mutants [showMutantAs] :: Args -> ShowMutantAs -- | number of surviving mutants to show [rows] :: Args -> Maybe Int -- | ignored argument (user defined meaning) [extra] :: Args -> [String] -- | How to show mutants. Use this to fill showMutantAs. data ShowMutantAs Tuple :: ShowMutantAs NestedTuple :: ShowMutantAs Definition :: ShowMutantAs Bindings :: ShowMutantAs -- | Default arguments for reportWith: -- -- -- --
--   ["f x y z", "g x y z", "h x y z", ...]
--   
args :: Args -- | Non timed-out default arguments. Make conjectures based on a fixed -- number of mutants and tests, e.g.: -- --
--   reportWith (fixargs 100 200) f pmap
--   
-- -- This is just a shorthand, see: -- --
--   fixargs nm nt  =  args { nMutants = nm, nTests = nt, timeout = 0 }
--   
-- --
--   (fixargs nm nt) { nMutants = 500, nTests = 1000, timeout = 5 }  =  args
--   
fixargs :: Int -> Int -> Args -- | Report results generated by FitSpec. Uses standard configuration (see -- args). Needs a function to be mutated and a property map. -- Example (specification of boolean negation): -- --
--   properties not =
--     [ property $ \p -> not (not p) == p
--     , property $ \p -> not (not (not p)) == not p
--     ]
--   
--   main = report not properties
--   
report :: (Mutable a, ShowMutable a) => a -> (a -> [Property]) -> IO () -- | Same as report but can be configured via Args -- (args or fixargs), e.g.: -- --
--   reportWith args { timeout = 10 } fun properties
--   
reportWith :: (Mutable a, ShowMutable a) => Args -> a -> (a -> [Property]) -> IO () -- | Same as reportWith, but accepts a list of manually defined -- (extra) mutants to be tested alongside those automatically generated. reportWithExtra :: (Mutable a, ShowMutable a) => [a] -> Args -> a -> (a -> [Property]) -> IO () -- | Same as reportWith, but allow overriding of configuration via -- command line arguments. mainWith :: (Mutable a, ShowMutable a) => Args -> a -> (a -> [Property]) -> IO () -- | Same as report, but allow configuration via command line -- arguments. defaultMain :: (Mutable a, ShowMutable a) => a -> (a -> [Property]) -> IO () getArgs :: IO Args getArgsWith :: Args -> IO Args -- | This typeclass is similar to Listable. -- -- A type is Mutable when there exists a function that is able to -- list mutations of a value. Ideally: list all possible values without -- repetitions. -- -- Instances are usually defined by a mutiers function that given -- a value, returns tiers of mutants of that value: the first tier -- contains the equivalent mutant, of size 0, the second tier contains -- mutants of size 1, the third tier contains mutants of size 2, and so -- on. -- -- The equivalent mutant is the actual function without mutations. -- -- The size of a mutant is given by the sum of: the number of mutated -- points (relations) and the sizes of mutated arguments and results. -- -- To get only inequivalent mutants, just take the tail of either -- mutants or mutiers: -- --
--   tail mutants
--   
-- --
--   tail mutiers
--   
-- -- Given that the underlying Listable enumeration has no -- repetitions, parametric instances defined in this file will have no -- repeated mutants. class Mutable a where mutiers = map (: []) . mutants mutants = concat . mutiers mutiers :: Mutable a => a -> [[a]] mutants :: Mutable a => a -> [a] -- | Implementation of mutiers for non-functional data types. Use -- this to create instances for user-defined data types, e.g.: -- --
--   instance MyData
--     where mutiers = mutiersEq
--   
-- -- and for parametric datatypes: -- --
--   instance (Eq a, Eq b) => MyDt a b
--     where mutiers = mutiersEq
--   
-- -- Examples: -- --
--   mutiersEq True = [[True], [False]]
--   mutiersEq 2   = [[2], [0], [1], [], [3], [4], [5], [6], [7], [8], [9], ...]
--   mutiersEq [1] = [[[1]], [[]], [[0]], [[0,0]], [[0,0,0],[0,1],[1,0],[-1]], ...]
--   
mutiersEq :: (Listable a, Eq a) => a -> [[a]] -- | Types that can have their mutation shown. Has only one function -- mutantS that returns a simple AST (MutantS) representing -- the mutant. A standard implementation of mutantS for Eq -- types is given by mutantSEq. class ShowMutable a mutantS :: ShowMutable a => a -> a -> MutantS -- | For a given type Type instance of Eq and -- Show, define the ShowMutable instance as: -- --
--   instance ShowMutable Type
--     where mutantS = mutantSEq
--   
mutantSEq :: (Eq a, Show a) => a -> a -> MutantS -- | Show a Mutant as a tuple of lambdas. -- --
--    > putStrLn $ showMutantAsTuple ["p && q","not p"] ((&&),not) ((||),id)
--    ( \p q -> case (p,q) of
--               (False,False) -> True
--               _ -> p && q
--   , \p -> case p of
--             False -> False
--             True -> True
--             _ -> not p )
--   
-- -- Can be easily copy pasted into an interactive session for -- manipulation. On GHCi, use :{ and :} to allow -- multi-line expressions and definitions. showMutantAsTuple :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as a new complete top-level definition, with a prime -- appended to the name of the mutant. -- --
--   > putStrLn $ showMutantDefinition ["p && q","not p"] ((&&),not) ((==),id)
--   False &&- False = True
--   p     &&- q     = p && q
--   not' False = False
--   not' True  = True
--   not' p     = not p
--   
showMutantDefinition :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as a tuple of nested lambdas. Very similar to -- showMutantAsTuple, but the underlying data structure is not -- flatten: so the output is as close as possible to the underlying -- representation. showMutantNested :: ShowMutable a => [String] -> a -> a -> String -- | Show a Mutant as the list of bindings that differ from the original -- function(s). -- --
--   > putStrLn $ showMutantBindings ["p && q","not p"] ((&&),not) ((==),id)
--   False && False = True
--   not False = False
--   not True  = True
--   
-- -- Can possibly be copied into the source of the original function for -- manipulation. showMutantBindings :: ShowMutable a => [String] -> a -> a -> String -- | Derives Mutable, ShowMutable and (optionally) -- Listable instances for a given type Name. -- -- Consider the following Stack datatype: -- --
--   data Stack a = Stack a (Stack a) | Empty
--   
-- -- Writing -- --
--   deriveMutable ''Stack
--   
-- -- will automatically derive the following Listable, -- Mutable and ShowMutable instances: -- --
--   instance Listable a => Listable (Stack a) where
--     tiers = cons2 Stack \/ cons0 Empty
--   
--   instance (Eq a, Listable a) => Mutable a
--     where mutiers = mutiersEq
--   
--   instance (Eq a, Show a) => ShowMutable a
--     where mutantS = mutantSEq
--   
-- -- If a Listable instance already exists, it is not derived. (cf.: -- deriveListable) -- -- Needs the TemplateHaskell extension. deriveMutable :: Name -> DecsQ -- | Derives a Mutable instance for a given type Name using a given -- context for all type variables. deriveMutableE :: [Name] -> Name -> DecsQ