Skip to content

Commit

Permalink
Merge pull request #8763 from haskell/Show-TestEnv
Browse files Browse the repository at this point in the history
cabal-testsuite: new `instance Show TestEnv`
  • Loading branch information
mergify[bot] authored Feb 22, 2023
2 parents 90a2f33 + 6885fa7 commit e48386c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cabal-testsuite/src/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ runTestM mode m = withSystemTempDirectory "cabal-testsuite" $ \tmp_dir -> do
testPlan = Nothing,
testRecordDefaultMode = DoNotRecord,
testRecordUserMode = Nothing,
testRecordNormalizer = id,
testSourceCopyRelativeDir = "source"
}
let go = do cleanup
Expand Down Expand Up @@ -527,12 +526,11 @@ data TestEnv = TestEnv
, testRecordDefaultMode :: RecordMode
-- | User explicitly set record mode. Not implemented ATM.
, testRecordUserMode :: Maybe RecordMode
-- | Function to normalize recorded output
, testRecordNormalizer :: String -> String
-- | Name of the subdirectory we copied the test's sources to,
-- relative to 'testSourceDir'
, testSourceCopyRelativeDir :: FilePath
}
deriving Show

testRecordMode :: TestEnv -> RecordMode
testRecordMode env = fromMaybe (testRecordDefaultMode env) (testRecordUserMode env)
Expand Down
4 changes: 4 additions & 0 deletions cabal-testsuite/src/Test/Cabal/Plan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@ import Control.Monad

-- TODO: index this
data Plan = Plan { planInstallPlan :: [InstallItem] }
deriving Show

data InstallItem
= APreExisting
| AConfiguredGlobal ConfiguredGlobal
| AConfiguredInplace ConfiguredInplace
deriving Show

-- local or inplace package
data ConfiguredInplace = ConfiguredInplace
{ configuredInplaceDistDir :: FilePath
, configuredInplaceBuildInfo :: Maybe FilePath
, configuredInplacePackageName :: PackageName
, configuredInplaceComponentName :: Maybe ComponentName }
deriving Show

data ConfiguredGlobal = ConfiguredGlobal
{ configuredGlobalBinFile :: Maybe FilePath
, configuredGlobalPackageName :: PackageName
, configuredGlobalComponentName :: Maybe ComponentName }
deriving Show

instance FromJSON Plan where
parseJSON (Object v) = fmap Plan (v .: "install-plan")
Expand Down
8 changes: 2 additions & 6 deletions cabal-testsuite/src/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ recordHeader args = do
env <- getTestEnv
let mode = testRecordMode env
str_header = "# " ++ intercalate " " args ++ "\n"
header = C.pack (testRecordNormalizer env str_header)
header = C.pack str_header
case mode of
DoNotRecord -> return ()
_ -> do
Expand All @@ -696,7 +696,7 @@ recordLog res = do
liftIO $ C.appendFile (testWorkDir env </> "test.log")
(C.pack $ "+ " ++ resultCommand res ++ "\n"
++ resultOutput res ++ "\n\n")
liftIO . C.appendFile (testActualFile env) . C.pack . testRecordNormalizer env $
liftIO . C.appendFile (testActualFile env) . C.pack $
case mode of
RecordAll -> unlines (lines (resultOutput res))
RecordMarked -> getMarkedOutput (resultOutput res)
Expand Down Expand Up @@ -787,10 +787,6 @@ recordMode mode = withReaderT (\env -> env {
testRecordUserMode = Just mode
})

recordNormalizer :: (String -> String) -> TestM a -> TestM a
recordNormalizer f =
withReaderT (\env -> env { testRecordNormalizer = testRecordNormalizer env . f })

assertOutputContains :: MonadIO m => WithCallStack (String -> Result -> m ())
assertOutputContains needle result =
withFrozenCallStack $
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/src/Test/Cabal/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data ScriptEnv = ScriptEnv
, runnerPackages :: [(OpenUnitId, ModuleRenaming)]
, runnerWithSharedLib :: Bool
}
deriving Show

{-
Expand Down

0 comments on commit e48386c

Please sign in to comment.