diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2018-01-13 01:09:56 +0100 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2018-01-18 14:10:26 +0100 |
commit | dbc6285489cb5171c611ebfd214e5c72d61a9dc8 (patch) | |
tree | 529b7ac7ff847f09855b32e9bc3b64f0c9f01e88 /tests | |
parent | 79988a8a5c2e3c1f29ca1e20c2d4a258863cd106 (diff) |
Fix and refactor CH.C.Compile
..compilation outputs were landing in CWD
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CompileTest.hs | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/tests/CompileTest.hs b/tests/CompileTest.hs index 0f5bf34..e65de8d 100644 --- a/tests/CompileTest.hs +++ b/tests/CompileTest.hs @@ -1,5 +1,8 @@ -{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE ScopedTypeVariables, GADTs #-} +import System.Environment (getArgs) +import System.Directory +import System.FilePath import System.Process import System.Exit import System.IO @@ -33,14 +36,34 @@ withinRange'CH v r = where v' = either (const $ parseVer "1000000000") id v +setupHOME :: IO () +setupHOME = do + tmp <- fromMaybe "/tmp" <$> lookupEnv "TMPDIR" + let home = tmp </> "compile-test-home" + _ <- rawSystem "rm" ["-r", home] + createDirectory home + setEnv "HOME" home + main :: IO () main = do - setEnv "HOME" =<< fromMaybe "/tmp" <$> lookupEnv "TMPDIR" + args <- getArgs + + let action + | null args = testAllCabalVersions + | otherwise = testCabalVersions $ map parseVer' args + + setupHOME + _ <- rawSystem "cabal" ["update"] - let parseVer' "HEAD" = Left HEAD - parseVer' v = Right $ parseVer v + action +parseVer' :: String -> Either HEAD Version +parseVer' "HEAD" = Left HEAD +parseVer' v = Right $ parseVer v + +testAllCabalVersions :: IO () +testAllCabalVersions = do let cabal_versions :: [Either HEAD Version] cabal_versions = map parseVer' -- "1.14.0" -- not supported at runtime @@ -105,7 +128,11 @@ main = do relevant_cabal_versions = reverse $ filter (flip withinRange'CH constraint) cabal_versions - rvs <- forM relevant_cabal_versions $ \ver -> do + testCabalVersions relevant_cabal_versions + +testCabalVersions :: [Either HEAD Version] -> IO () +testCabalVersions versions = do + rvs <- forM versions $ \ver -> do let sver = either show showVersion ver hPutStrLn stderr $ "\n\n\n\n\n\n====== Compiling with Cabal-" ++ sver compilePrivatePkgDb ver @@ -118,9 +145,9 @@ main = do Left rvc -> "failed (exit code "++show rvc++")" - let drvs = relevant_cabal_versions `zip` rvs + let drvs = versions `zip` rvs - mapM_ printStatus (relevant_cabal_versions `zip` rvs) + mapM_ printStatus drvs if any isLeft' $ map snd $ filter ((/=Left HEAD) . fst) drvs then exitFailure else exitSuccess @@ -143,8 +170,11 @@ compileWithPkg :: Maybe PackageDbDir -> CabalVersion -> IO (Either ExitCode FilePath) compileWithPkg mdb cabalVer = - compile "/does-not-exist" defaultOptions { oVerbose = True } $ - Compile Nothing mdb cabalVer [cabalPkgId cabalVer] + compile + (CompileWithCabalPackage mdb cabalVer [cabalPkgId cabalVer] CPSGlobal) + "/does-not-exist" + defaultOptions { oVerbose = True } + cabalPkgId :: CabalVersion -> String cabalPkgId (CabalHEAD _commitid) = "Cabal" |