Revert "Simplify test suite"

This reverts commit 8f2625dc87.
ghc92
Lennart Spitzner 2023-01-31 15:21:38 +00:00
parent 5806dfc208
commit eabf4e9d45
1 changed files with 26 additions and 13 deletions

View File

@ -1,12 +1,14 @@
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad import qualified Control.Monad as Monad
import qualified Data.List as List import qualified Data.List as List
import qualified Language.Haskell.Brittany.Main as Brittany import qualified Language.Haskell.Brittany.Main as Brittany
import qualified System.Directory as Directory import qualified System.Directory as Directory
import qualified System.FilePath as FilePath import qualified System.FilePath as FilePath
import qualified System.IO as IO
import qualified Test.Hspec as Hspec import qualified Test.Hspec as Hspec
main :: IO () main :: IO ()
main = Hspec.hspec . Hspec.parallel $ do main = Hspec.hspec $ do
let directory = "data" let directory = "data"
entries <- Hspec.runIO $ Directory.listDirectory directory entries <- Hspec.runIO $ Directory.listDirectory directory
Monad.forM_ (List.sort entries) $ \entry -> Monad.forM_ (List.sort entries) $ \entry ->
@ -15,7 +17,8 @@ main = Hspec.hspec . Hspec.parallel $ do
Just slug -> Hspec.it slug $ do Just slug -> Hspec.it slug $ do
let input = FilePath.combine directory entry let input = FilePath.combine directory entry
expected <- readFile input expected <- readFile input
let output = FilePath.combine "output" entry actual <- withTemporaryFile $ \output handle -> do
IO.hClose handle
Directory.copyFile input output Directory.copyFile input output
Brittany.mainWith Brittany.mainWith
"brittany" "brittany"
@ -26,9 +29,19 @@ main = Hspec.hspec . Hspec.parallel $ do
, "inplace" , "inplace"
, output , output
] ]
actual <- readFile output readFile output
Literal actual `Hspec.shouldBe` Literal expected Literal actual `Hspec.shouldBe` Literal expected
withTemporaryFile :: (FilePath -> IO.Handle -> IO a) -> IO a
withTemporaryFile callback = do
directory <- Directory.getTemporaryDirectory
let
acquire = IO.openTempFile directory "brittany-.hs"
release filePath handle = do
IO.hClose handle
Directory.removeFile filePath
Exception.bracket acquire (uncurry release) (uncurry callback)
newtype Literal newtype Literal
= Literal String = Literal String
deriving Eq deriving Eq