diff options
Diffstat (limited to 'testkiki')
-rw-r--r-- | testkiki/testkiki.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs index c45764f..606f268 100644 --- a/testkiki/testkiki.hs +++ b/testkiki/testkiki.hs | |||
@@ -16,6 +16,7 @@ import System.Exit | |||
16 | import System.IO | 16 | import System.IO |
17 | --import System.Posix.ByteString.FilePath | 17 | --import System.Posix.ByteString.FilePath |
18 | import Control.Applicative | 18 | import Control.Applicative |
19 | import Data.List | ||
19 | import Control.Monad | 20 | import Control.Monad |
20 | import qualified Data.ByteString.Char8 as B | 21 | import qualified Data.ByteString.Char8 as B |
21 | import Data.Time.Clock | 22 | import Data.Time.Clock |
@@ -23,6 +24,7 @@ import Data.Time.Clock.POSIX | |||
23 | import Data.IORef | 24 | import Data.IORef |
24 | import Crypto.Hash.SHA1 (hash) | 25 | import Crypto.Hash.SHA1 (hash) |
25 | import System.IO.Unsafe (unsafePerformIO) | 26 | import System.IO.Unsafe (unsafePerformIO) |
27 | import ProcessUtils | ||
26 | 28 | ||
27 | #if !MIN_VERSION_base(4,7,0) | 29 | #if !MIN_VERSION_base(4,7,0) |
28 | setEnv k v = System.Posix.Env.setEnv k v True | 30 | setEnv k v = System.Posix.Env.setEnv k v True |
@@ -305,3 +307,44 @@ doTests tkConfig = hspec $ do | |||
305 | appendpaths config str = TKS { gnupghome = gnupghome config ++ str | 307 | appendpaths config str = TKS { gnupghome = gnupghome config ++ str |
306 | , chroot = chroot config ++ str | 308 | , chroot = chroot config ++ str |
307 | } | 309 | } |
310 | |||
311 | |||
312 | |||
313 | safeFileInfo :: FilePath -> IO (UTCTime,FilePath) | ||
314 | safeFileInfo file = do | ||
315 | mtime <- getModificationTime file | ||
316 | let folder = takeDirectory file | ||
317 | fileDotOld = file ++ ".old" | ||
318 | readProcess "cp" ["-aR",file,fileDotOld] "" | ||
319 | return (mtime,fileDotOld) | ||
320 | |||
321 | compareSha1 :: FilePath -> IO Bool | ||
322 | compareSha1 file = do | ||
323 | let folder = takeDirectory file | ||
324 | fileDotOld = file ++ ".old" | ||
325 | hash1 <- hash <$> B.readFile fileDotOld | ||
326 | hash2 <- hash <$> B.readFile file | ||
327 | return (hash1 == hash2) | ||
328 | |||
329 | getMTimes :: FilePath -> IO (UTCTime, UTCTime) | ||
330 | getMTimes file = (,) <$> getModificationTime oldfile <*> getModificationTime file | ||
331 | where oldfile = file ++ ".old" | ||
332 | |||
333 | getLineCounts :: FilePath -> IO (Int, Int) | ||
334 | getLineCounts file = (,) <$> l oldfile <*> l file | ||
335 | where oldfile = file ++ ".old" | ||
336 | l x = length . B.lines <$> B.readFile x | ||
337 | |||
338 | linesSubtractedAndAdded :: FilePath -> IO (Int,Int) | ||
339 | linesSubtractedAndAdded file = counts <$> readPipe [("diff",["-u",oldfile,file]),("sed",["-n","4,$ p"])] "" | ||
340 | where oldfile = file ++ ".old" | ||
341 | counts x = ( length $ filter ("-" `isPrefixOf`) (lines x) | ||
342 | , length $ filter ("+" `isPrefixOf`) (lines x) ) | ||
343 | |||
344 | saveOutputOfRun :: FilePath -> IO String -> IO ((FilePath -> IO a) -> (IO a)) | ||
345 | saveOutputOfRun fileToFill action = do | ||
346 | action >>= writeFile (fileToFill ++ ".old") | ||
347 | return $ \getSomething -> do | ||
348 | bRanAgain <- doesFileExist fileToFill | ||
349 | when (not bRanAgain) $ action >>= writeFile fileToFill | ||
350 | getSomething fileToFill | ||