Skip to content

Commit

Permalink
Skip tests when running under ghci
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Jan 27, 2024
1 parent 9a5e28a commit c60ab6b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Test/Tasty/Inspection/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

module Test.Tasty.Inspection.Plugin (plugin) where

import Control.Monad (foldM)
import qualified Language.Haskell.TH.Syntax as TH
import System.Exit (exitFailure)

Expand All @@ -25,16 +26,16 @@ import GhcPlugins
import GHC.Types.TyThing
#endif

#if MIN_VERSION_ghc(9,3,0)
import Control.Monad (foldM)
#else
import Control.Monad (foldM, when)
#endif

import Test.Inspection (Obligation(..))
import qualified Test.Inspection.Plugin as P (checkProperty, CheckResult(..))
import Test.Tasty.Inspection.Internal (CheckResult(..))

#if MIN_VERSION_ghc(9,6,0)
import GHC.Driver.Backend (backendForcesOptimization0)
#elif MIN_VERSION_ghc(9,4,0)
import GHC.Driver.Backend (Backend(Interpreter))
#endif

-- | The plugin for inspection testing.
-- You normally do not need to touch it yourself,
-- 'Test.Tasty.Inspection.inspectTest' will enable it automatically.
Expand Down Expand Up @@ -97,20 +98,21 @@ resultToExpr (P.ResSuccessWithMessage sdoc) = do
App <$> dcExpr 'ResSuccessWithMessage <*> mkStringExpr (showSDoc dflags sdoc)
resultToExpr (P.ResFailure sdoc) = do
dflags <- getDynFlags
App <$> dcExpr 'ResFailure <*> mkStringExpr (showSDoc dflags sdoc)
if ghciDetected dflags
then App <$> dcExpr 'ResSuccessWithMessage <*> mkStringExpr "Skipped because backend forces -O0"
else App <$> dcExpr 'ResFailure <*> mkStringExpr (showSDoc dflags sdoc)

ghciDetected :: DynFlags -> Bool
#if MIN_VERSION_ghc(9,6,0)
ghciDetected = backendForcesOptimization0 . backend
#elif MIN_VERSION_ghc(9,4,0)
ghciDetected = (== Interpreter) . backend
#else
ghciDetected = const False
#endif

proofPass :: ModGuts -> CoreM ModGuts
proofPass guts = do
#if !MIN_VERSION_ghc(9,3,0)
dflags <- getDynFlags
when (optLevel dflags < 1) $ warnMsg
#if MIN_VERSION_ghc(8,9,0)
NoReason
#endif
$ fsep $ map text
$ words "Test.Inspection: Compilation without -O detected. Expect optimizations to fail."
#endif
uncurry (foldM checkObligation) (extractObligations guts)
proofPass = uncurry (foldM checkObligation) . extractObligations

partitionMaybe :: (a -> Maybe b) -> [a] -> ([a], [b])
partitionMaybe f = foldr go ([], [])
Expand Down

0 comments on commit c60ab6b

Please sign in to comment.