Skip to content

Commit

Permalink
Don't use catchIOError (GHC 7.0 doesn't have it)
Browse files Browse the repository at this point in the history
  • Loading branch information
knothed committed Jun 16, 2021
1 parent fba7e6c commit 3fd9afc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/test/src/SDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Shell
import System.FilePath
import System.Directory (setCurrentDirectory)
import System.Process
import System.IO.Error
import System.Exit
import Data.Ord
import Data.List
import Data.Maybe
import Control.Applicative
import Control.Exception
import Control.Monad.IO.Class

-- Test whether the tarballs are distribution-ready by calling `cabal sdist`, merging the tarballs into one umbrella directory and building and testing in this directory.
Expand Down Expand Up @@ -88,11 +88,14 @@ testWithBootstrapping dir executable = do
cabalSdistAll :: [String] -> String -> TypedShell [String]
cabalSdistAll packageNames baseDir = do
liftIO $ setCurrentDirectory baseDir
output <- liftIO $ readProcess "cabal" ["sdist", "all"] "" `catchIOError` const (return "")
output <- liftIO $ readProcess "cabal" ["sdist", "all"] "" `catchIO` const (return "")
let fullNames = catMaybes . catMaybes $ map extractFullName $ lines output
let matched = catMaybes $ map (bestMatch fullNames) packageNames
if length packageNames == length matched then return matched else empty
where
catchIO :: IO a -> (IOError -> IO a) -> IO a
catchIO = Control.Exception.catch

-- Find package-name-VERSION matching to package-name.
-- Note: we cannot just use `isPrefixOf` because then `happy` would match to `happy-frontend-1.21.0`!
bestMatch fullNames packageName = head' $ sortBy (comparing numPrefixMatches) prefixMatches where
Expand Down
6 changes: 3 additions & 3 deletions packages/test/src/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ runSingleTest happy arguments dir testFile = do

tryRemovingFile :: FilePath -> IO ()
tryRemovingFile file = do
removeFile file `catch` doNothing
removeFile file `catchIO` const (return ())
where
doNothing :: IOError -> IO ()
doNothing _ = return ()
catchIO :: IO a -> (IOError -> IO a) -> IO a
catchIO = Control.Exception.catch

-- Only works for .y and .ly files.
basename :: FilePath -> FilePath
Expand Down

0 comments on commit 3fd9afc

Please sign in to comment.