fitspec 0.4.0 → 0.4.1
raw patch · 23 files changed
+149/−153 lines, 23 filesdep −haskell-srcdep −haskell-src-extsdep ~leancheck
Dependencies removed: haskell-src, haskell-src-exts
Dependency ranges changed: leancheck
Files
- LICENSE +1/−1
- README.md +8/−0
- TODO.md +2/−18
- bench/haskell-src-exts.hs +0/−38
- bench/haskell-src.hs +0/−58
- fitspec.cabal +19/−15
- src/Test/FitSpec.hs +7/−1
- src/Test/FitSpec/Derive.hs +7/−1
- src/Test/FitSpec/Dot.hs +8/−2
- src/Test/FitSpec/Engine.hs +7/−1
- src/Test/FitSpec/Main.hs +7/−1
- src/Test/FitSpec/Mutable.hs +7/−1
- src/Test/FitSpec/Mutable/Tuples.hs +7/−1
- src/Test/FitSpec/PrettyPrint.hs +7/−1
- src/Test/FitSpec/Report.hs +7/−1
- src/Test/FitSpec/ShowMutable.hs +12/−5
- src/Test/FitSpec/ShowMutable/Tuples.hs +7/−1
- src/Test/FitSpec/TestTypes.hs +7/−1
- src/Test/FitSpec/Utils.hs +20/−6
- tests/test-derive.hs +2/−0
- tests/test-mutate.hs +3/−0
- tests/test-showmutable.hs +2/−0
- tests/test-utils.hs +2/−0
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015-2016, Rudy Matela+Copyright (c) 2015-2017, Rudy Matela All rights reserved.
README.md view
@@ -1,6 +1,9 @@ FitSpec ======= +[![FitSpec Build Status][build-status]][build-log]+[![FitSpec on Hackage][hackage-version]][fitspec-on-hackage]+ 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@@ -149,3 +152,8 @@ [TH]: https://wiki.haskell.org/Template_Haskell [Cabal]: https://www.haskell.org/cabal++[build-status]: https://travis-ci.org/rudymatela/fitspec.svg?branch=master+[build-log]: https://travis-ci.org/rudymatela/fitspec+[hackage-version]: https://img.shields.io/hackage/v/fitspec.svg+[fitspec-on-hackage]: https://hackage.haskell.org/package/fitspec
TODO.md view
@@ -21,23 +21,7 @@ (cabal install, cabal from sandbox, source include) -v0.4.1+v0.4.2 ------ -* Fix `thread killed` when first run takes longer than timeout:-- $ ./bench/haskell-src -t5 -m500 -n1000- haskell-src: thread killed-- As it takes more than 5 seconds to run this example (at least on my machine),- the thread will be killed before concluding. I *think* this is the source of- the bug, but could be something else.-- EDIT (after re-reading the code and doing some tests): maybe the Thread- Killed exception somehow "infects" `x` as it may share some structure with- elements of `xs`.-- To solve this, maybe re-implement by probing (every 100ms) whether the IORef- was ever written to --- for that I will need a second boolean IORef. This has- the advantage of, by adding a *third* boolean IORef we can also exit earlier- when test cases and mutants are exhausted.+* implement `toplibs` hack (from LeanCheck and Speculate);
− bench/haskell-src-exts.hs
@@ -1,38 +0,0 @@-{-# LANGUAGE TemplateHaskell #-}-import Test.FitSpec-import Language.Haskell.Exts-import Language.Haskell.Exts.Pretty--instance Eq a => Eq (ParseResult a) where- ParseOk x == ParseOk y = x == y- ParseFailed l1 s1 == ParseFailed l2 s2 = l1 == l2 && s1 == s2- _ == _ = False--deriveMutableCascading ''ParseResult-deriveMutableCascading ''Module-deriveMutableCascading ''SrcSpanInfo--properties :: (String -> ParseResult (Module SrcSpanInfo)- ,Module SrcSpanInfo -> String)- -> [Property]-properties (parseFileContents,prettyPrint) =- [ property $ case parseFileContents "" of- ParseOk (Module _ _ _ _ _) -> True- _ -> False- , property $ case parseFileContents "a" of- ParseFailed (SrcLoc "<unknown>.hs" 2 1) _ -> True- _ -> False- , property $ \m -> case parseFileContents (prettyPrint m) of- ParseOk m' -> case parseFileContents (prettyPrint m') of- ParseOk m'' -> m' == m''- _ -> False- _ -> True--- Not true:---, property $ \s -> case parseFileContents s of--- ParseOk m' -> prettyPrint m' == s--- _ -> True- ]--main = mainWith args { names = ["parseFileContents f", "prettyPrint m"] }- (parseFileContents,prettyPrint)- properties
− bench/haskell-src.hs
@@ -1,58 +0,0 @@-{-# LANGUAGE TemplateHaskell, StandaloneDeriving #-}-import Test.FitSpec-import Language.Haskell.Parser-import Language.Haskell.Pretty as P-import Language.Haskell.Syntax-import Data.Ratio-import Data.List (intercalate)-import Data.Function (on)-import Data.Char--deriving instance Eq HsModule -- needed for Mutable--deriveMutableCascading ''HsModule---- change ``take 5'' below to ``take n'' where n `elem` [1,2,3,4]--- to see surviving mutants for different refinements------ All 5 properties should be reported as ``apparently complete''--- so no surviving mutants.-properties :: (HsModule -> String) -> [Property]-properties prettyPrint = take 5- [ property $- \nm loc -> (prettyPrint $ HsModule loc (Module nm) Nothing [] [])- == "module " ++ nm ++ " where"-- , property $- \nm loc -> (prettyPrint $ HsModule loc (Module nm) (Just []) [] [])- == "module " ++ nm ++ " () where"-- , property $- \nm loc -> (prettyPrint $ HsModule loc (Module nm) Nothing [] [HsFunBind []])- == "module " ++ nm ++ " where"-- , property $- \nm loc imports decls ->- (prettyPrint $ HsModule loc (Module nm) Nothing imports decls)- === unlines (("module " ++ nm ++ " where")- :(map P.prettyPrint imports- ++ map P.prettyPrint decls))-- , property $- \nm loc imports exports decls ->- (prettyPrint $ HsModule loc (Module nm) (Just exports) imports decls)- === unlines (["module " ++ nm ++ " ("- ++ intercalate ", " (map P.prettyPrint exports)- ++ ") where"]- ++ map P.prettyPrint imports- ++ map P.prettyPrint decls)- ]- where- (===) :: String -> String -> Bool- (===) = (==) `on` (filter (not . null) . lines)--main = mainWith args { names = ["prettyPrint"]- , timeout = 0- }- prettyPrint- properties
fitspec.cabal view
@@ -1,5 +1,5 @@ name: fitspec-version: 0.4.0+version: 0.4.1 synopsis: refining property sets for testing Haskell programs description: FitSpec provides automated assistance in the task of refining test properties@@ -38,7 +38,7 @@ source-repository this type: git location: https://github.com/rudymatela/fitspec- tag: v0.4.0+ tag: v0.4.1 library@@ -110,19 +110,23 @@ default-language: Haskell2010 type: exitcode-stdio-1.0 -benchmark haskell-src- main-is: haskell-src.hs- build-depends: base >= 4 && < 5, leancheck, cmdargs, template-haskell, haskell-src- hs-source-dirs: src, bench- default-language: Haskell2010- type: exitcode-stdio-1.0--benchmark haskell-src-exts- main-is: haskell-src-exts.hs- build-depends: base >= 4 && < 5, leancheck, cmdargs, template-haskell, haskell-src-exts- hs-source-dirs: src, bench- default-language: Haskell2010- type: exitcode-stdio-1.0+-- The haskell-src and haskell-src-exts are commented out as they pull a lot of+-- dependencies. Ultimately a flag could be added to optionally activate them,+-- but better not make this cabal file too much complex.+--+--benchmark haskell-src+-- main-is: haskell-src.hs+-- build-depends: base >= 4 && < 5, leancheck, cmdargs, template-haskell, haskell-src+-- hs-source-dirs: src, bench+-- default-language: Haskell2010+-- type: exitcode-stdio-1.0+--+--benchmark haskell-src-exts+-- main-is: haskell-src-exts.hs+-- build-depends: base >= 4 && < 5, leancheck, cmdargs, template-haskell, haskell-src-exts+-- hs-source-dirs: src, bench+-- default-language: Haskell2010+-- type: exitcode-stdio-1.0 benchmark heaps main-is: heaps.hs
src/Test/FitSpec.hs view
@@ -1,4 +1,10 @@--- | __ FitSpec: refining property-sets for functional testing __+-- |+-- Module : Test.FitSpec+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- __ 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
src/Test/FitSpec/Derive.hs view
@@ -1,4 +1,10 @@--- | Experimental module for deriving 'Mutable' and 'ShowMutable' instances+-- |+-- Module : Test.FitSpec.Derive+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- 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)
src/Test/FitSpec/Dot.hs view
@@ -1,5 +1,11 @@--- | Experimental module to generate dotfiles (for graphviz) with implications--- between property sub-sets.+-- |+-- Module : Test.FitSpec.Dot+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- Experimental module to generate dotfiles (for graphviz) with implications+-- between property sub-sets. module Test.FitSpec.Dot where import Test.FitSpec
src/Test/FitSpec/Engine.hs view
@@ -1,4 +1,10 @@--- | FitSpec: refining property-sets for functional testing+-- |+-- Module : Test.FitSpec.Engine+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- FitSpec: refining property-sets for functional testing -- -- This is the main engine, besides "Test.FitSpec.Mutable". module Test.FitSpec.Engine
src/Test/FitSpec/Main.hs view
@@ -1,4 +1,10 @@--- | Exports "main" functions for FitSpec.+-- |+-- Module : Test.FitSpec.Main+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- Exports "main" functions for FitSpec. -- They work exactly by 'report' and 'reportWith' but can be customized by -- command line arguments. --
src/Test/FitSpec/Mutable.hs view
@@ -1,4 +1,10 @@--- | Enumeration of function mutations+-- |+-- Module : Test.FitSpec.Mutable+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- Enumeration of function mutations module Test.FitSpec.Mutable ( Mutable (..) , mutiersEq
src/Test/FitSpec/Mutable/Tuples.hs view
@@ -1,4 +1,10 @@--- | Mutable instances: septuples up to 12-tuples+-- |+-- Module : Test.FitSpec.Mutable.Tuples+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- 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.
src/Test/FitSpec/PrettyPrint.hs view
@@ -1,4 +1,10 @@--- | A very simple pretty printing library used to generate 'Test.FitSpec' reports.+-- |+-- Module : Test.FitSpec.PrettyPrint+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- A very simple pretty printing library used to generate 'Test.FitSpec' reports. module Test.FitSpec.PrettyPrint ( beside , above
src/Test/FitSpec/Report.hs view
@@ -1,4 +1,10 @@--- | Generate 'Test.FitSpec' reports.+-- |+-- Module : Test.FitSpec.Report+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- Generate 'Test.FitSpec' reports. module Test.FitSpec.Report ( report , reportWith
src/Test/FitSpec/ShowMutable.hs view
@@ -1,4 +1,10 @@--- | Show mutant variations+-- |+-- Module : Test.FitSpec.ShowMutable+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- Exports a typeclass to show mutant variations. module Test.FitSpec.ShowMutable ( ShowMutable (..) , mutantSEq@@ -18,6 +24,7 @@ import Data.List (intercalate,tails) import Data.Char (isLetter) import Data.Ratio (Ratio)+import Data.Word (Word) -- for GHC <= 7.10 -- | Show a Mutant as a tuple of lambdas.@@ -26,10 +33,10 @@ -- > ( \p q -> case (p,q) of -- > (False,False) -> True -- > _ -> p && q--- >, \p -> case p of--- > False -> False--- > True -> True--- > _ -> not p )+-- > , \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.
src/Test/FitSpec/ShowMutable/Tuples.hs view
@@ -1,4 +1,10 @@--- | ShowMutable instances: septuples up to 12-tuples+-- |+-- Module : Test.FitSpec.Tuples+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- 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.
src/Test/FitSpec/TestTypes.hs view
@@ -1,4 +1,10 @@--- | FitSpec's Test Types:+-- |+-- Module : Test.FitSpec.TestTypes+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- FitSpec's Test Types: -- 'Nat', -- 'Int2', 'Int3', 'Int4', -- 'UInt2', 'UInt3', 'UInt4'.
src/Test/FitSpec/Utils.hs view
@@ -1,4 +1,10 @@--- | General purpose utility functions for FitSpec+-- |+-- Module : Test.FitSpec.Utils+-- Copyright : (c) 2015-2017 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- General purpose utility functions for FitSpec {-# LANGUAGE CPP #-} module Test.FitSpec.Utils ( (...)@@ -38,7 +44,7 @@ import Data.Function (on) import Data.Ord (comparing) import Data.List (groupBy,sortBy)-import Data.IORef (newIORef, readIORef, writeIORef)+import Data.IORef (IORef, newIORef, readIORef, writeIORef) import Control.Concurrent (forkIO, threadDelay, killThread) import Control.Monad (liftM) @@ -111,22 +117,30 @@ takeWhileIncreasingOn :: Ord b => (a -> b) -> [a] -> [a] takeWhileIncreasingOn f = takeWhileIncreasing (compare `on` f) +readIORefUntil :: (a -> Bool) -> IORef a -> IO a+readIORefUntil p r = do+ x <- readIORef r+ if p x+ then return x+ else threadDelay 100000 -- 100ms+ >> readIORefUntil p r -- | @lastTimeout s xs@ will take the last value of @xs@ it is able evaluate -- before @s@ seconds elapse. lastTimeout :: Int -> [a] -> IO a lastTimeout _ [] = error "lastTimeout: empty list" lastTimeout 0 (x:_) = return x -- no time to lose-lastTimeout s (x:xs) = do- r <- newIORef x+lastTimeout s xs = do+ r <- newIORef (undefined,False) tid <- forkIO $ keepImproving r xs threadDelay (s*1000000) -- TODO: change to waitForThread!!!+ (x,_) <- readIORefUntil snd r killThread tid- readIORef r+ return x where keepImproving _ [] = return () keepImproving r (x:xs) = do evaluate x- writeIORef r x+ writeIORef r (x,True) keepImproving r xs (***) :: (a -> b) -> (c -> d) -> (a,c) -> (b,d)
tests/test-derive.hs view
@@ -1,3 +1,5 @@+-- Copyright (c) 2015-2017 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE). {-# LANGUAGE TemplateHaskell #-} import System.Exit (exitFailure) import Data.List (elemIndices,sort)
tests/test-mutate.hs view
@@ -1,3 +1,5 @@+-- Copyright (c) 2015-2017 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE). import System.Exit (exitFailure) import Data.List (elemIndices, sort) import Data.Tuple (swap)@@ -8,6 +10,7 @@ import Test.LeanCheck.Function.ListsOfPairs (functionPairs, defaultFunPairsToFunction) import Data.Monoid ((<>))+import Data.Word (Word) -- for GHC <= 7.10 polyAppend :: [a] -> [b] -> [Either a b] polyAppend xs ys = map Left xs ++ map Right ys
tests/test-showmutable.hs view
@@ -1,3 +1,5 @@+-- Copyright (c) 2015-2017 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE). {-# LANGUAGE NoMonomorphismRestriction #-} import System.Exit (exitFailure) import System.Environment (getArgs)
tests/test-utils.hs view
@@ -1,3 +1,5 @@+-- Copyright (c) 2015-2017 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE). import System.Exit (exitFailure) import Data.List (elemIndices,sortBy)