1module Util where23import Control.Monad (void)4import System.Directory5 ( copyFile,6 createDirectoryIfMissing,7 getTemporaryDirectory,8 listDirectory,9 removePathForcibly,10 )11import System.FilePath (takeFileName, (</>))1213-- Path to temporary directory for golden tests.14getTestDir :: IO FilePath15getTestDir = do16 tempDir <- getTemporaryDirectory17 pure $ tempDir </> "mach-tests"1819-- Copy files in skelekton directory to a subdirectory with the20-- given name in a temporary directory obtained via 'getTestDir'.21prepTempDir :: String -> FilePath -> IO FilePath22prepTempDir name skel = do23 tempDir <- (</> name) <$> getTestDir24 removePathForcibly tempDir25 >> createDirectoryIfMissing True tempDir2627 -- Copy files from the skeleton dir to the tempDir.28 -- Only works for regular files, probably doesn't recurse.29 void $ listDirectory skel >>= mapM (\n -> copyFile (skel </> n) $ tempDir </> takeFileName n)3031 pure tempDir