packages feed

tasty-coverage 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+58/−11 lines, 3 filesdep ~filepathPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: filepath

API changes (from Hackage documentation)

+ Test.Tasty.CoverageReporter: instance GHC.Classes.Eq Test.Tasty.CoverageReporter.RemoveTixHash
+ Test.Tasty.CoverageReporter: instance GHC.Classes.Ord Test.Tasty.CoverageReporter.RemoveTixHash
+ Test.Tasty.CoverageReporter: instance Test.Tasty.Options.IsOption Test.Tasty.CoverageReporter.RemoveTixHash

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for tasty-test -## 0.1.0.0 -- 2023-08-07+## 0.1.1.0 -- 2023-09-07++* Be more specific with the file suffixes which are computed from the test outcome. Previously only "PASSED" and "FAILED" were used. We now also use "EXCEPTION", "TIMEOUT" and "SKIPPED".+* If the name of the test contains a path separator, then this path separator is removed from the name of the generated tix file (#5)+* Add commandline option "--remove-tix-hash" which replaces the hash in the tix files with "0". This is useful for golden testing the output of the tasty-coverage ingredient.++## 0.1.0.0 -- 2023-08-21  * Release of first version on Hackage
src/Test/Tasty/CoverageReporter.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE InstanceSigs #-}+{-# LANGUAGE InstanceSigs, NamedFieldPuns #-} module Test.Tasty.CoverageReporter (coverageReporter) where  import Test.Tasty@@ -8,7 +8,7 @@ import Test.Tasty.Providers import Data.Typeable import Trace.Hpc.Reflect ( clearTix, examineTix )-import Trace.Hpc.Tix ( writeTix )+import Trace.Hpc.Tix ( writeTix, Tix(..), TixModule(..) ) import System.FilePath ( (<.>), (</>) ) import Control.Monad (forM_) import qualified Data.List.NonEmpty as NE@@ -16,7 +16,7 @@ import Data.Foldable (fold) import Data.Bifunctor (first) -newtype ReportCoverage = MkReportCoverage   Bool+newtype ReportCoverage = MkReportCoverage Bool   deriving (Eq, Ord, Typeable)  instance IsOption ReportCoverage where@@ -26,7 +26,22 @@     optionHelp = pure "Generate per-test coverage data"     optionCLParser = mkFlagCLParser mempty (MkReportCoverage True) +newtype RemoveTixHash = MkRemoveTixHash Bool+  deriving (Eq, Ord, Typeable) +instance IsOption RemoveTixHash where+  defaultValue = MkRemoveTixHash False+  parseValue = fmap MkRemoveTixHash . safeReadBool+  optionName = pure "remove-tix-hash"+  optionHelp = pure "Remove hash from tix file (used for golden tests)"+  optionCLParser = mkFlagCLParser mempty (MkRemoveTixHash True)++coverageOptions :: [OptionDescription]+coverageOptions = [ Option (Proxy :: Proxy ReportCoverage)+                  , Option (Proxy :: Proxy RemoveTixHash)+                  ]++ tixDir :: FilePath tixDir = "tix" @@ -46,7 +61,7 @@                 result <- run opts test (\_ -> pure ())                 tix <- examineTix                 let filepath = tixFilePath n result-                writeTix filepath tix+                writeTix filepath (removeHash opts tix)                 putStrLn ("Wrote coverage file: " <> filepath)           pure (NE.singleton name, f),           -- Append the name of the testgroup to the list of TestNames@@ -54,14 +69,21 @@         }  tixFilePath :: TestName -> Result -> FilePath-tixFilePath tn Result { resultOutcome = Success }  = tixDir </> tn <.> "PASSED" <.> ".tix"-tixFilePath tn Result { resultOutcome = Failure _ } = tixDir </> tn <.> "FAILED" <.> ".tix"+tixFilePath tn Result { resultOutcome }  =+  tixDir </> generateValidFilepath tn <.> outcomeSuffix resultOutcome <.> ".tix" +-- | We want to compute the file suffix that we use to distinguish+-- tix files for failing and succeeding tests.+outcomeSuffix :: Outcome -> String+outcomeSuffix Success = "PASSED"+outcomeSuffix (Failure TestFailed) = "FAILED"+outcomeSuffix (Failure (TestThrewException _)) = "EXCEPTION"+outcomeSuffix (Failure (TestTimedOut _)) = "TIMEOUT"+outcomeSuffix (Failure TestDepFailed) = "SKIPPED"+ coverageReporter :: Ingredient coverageReporter = TestManager coverageOptions coverageRunner -coverageOptions :: [OptionDescription]-coverageOptions = [Option (Proxy :: Proxy ReportCoverage)]  coverageRunner :: OptionSet -> TestTree -> Maybe (IO Bool) coverageRunner opts tree = case lookupOption opts of@@ -70,4 +92,22 @@     testNames opts tree     pure True +-- | Removes all path separators from the input String in order+-- to generate a valid filepath.+-- The names of some tests contain path separators, so we have to+-- remove them.+generateValidFilepath :: String -> FilePath+generateValidFilepath = filter (`notElem` pathSeparators)+  where+    -- Include both Windows and Posix, so that generated .tix files+    -- are consistent among systems.+    pathSeparators = ['\\','/']   +removeHash :: OptionSet -> Tix -> Tix+removeHash opts (Tix txs) = case lookupOption opts of+  MkRemoveTixHash False -> Tix txs+  MkRemoveTixHash True -> Tix (fmap removeHashModule txs)++removeHashModule :: TixModule -> TixModule+removeHashModule (TixModule name _hash i is) = TixModule name 0 i is+
tasty-coverage.cabal view
@@ -1,6 +1,6 @@ cabal-version:   3.0 name:            tasty-coverage-version:         0.1.0.0+version:         0.1.1.0 license:         BSD-3-Clause license-file:    LICENSE copyright:       David Binder, 2023@@ -33,7 +33,8 @@     ghc-options:      -Wall     build-depends:         base >=4.16 && <4.20,+        filepath >=1.3.8 && <=1.5,         tasty ^>=1.4,         hpc >=0.6 && <0.8,-        filepath >=1.3.8 && <1.4.100+