File: Util.hs

package info (click to toggle)
haskell-system-fileio 0.3.16.4-6.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176 kB
  • sloc: haskell: 1,327; ansic: 155; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

-- Copyright (C) 2011 John Millikin <jmillikin@gmail.com>
--
-- See license.txt for details
module FilesystemTests.Util
	( assertionsWithTemp
	, todo
	) where

import           Prelude hiding (FilePath)

import           Control.Exception (finally)
import           System.IO.Temp (withSystemTempDirectory)
import           Test.Chell

import           Filesystem (removeTree)
import           Filesystem.Path.CurrentOS (FilePath, decodeString)

assertionsWithTemp :: String -> (FilePath -> Assertions a) -> Test
assertionsWithTemp name io = test name impl where
	impl options = withTempDir name $ \dir -> do
		runTest (assertions name (io dir)) options

withTempDir :: String -> (FilePath -> IO a) -> IO a
withTempDir name io = withSystemTempDirectory
	("tests." ++ name ++ ".")
	(\dir ->
		let dir' = decodeString dir in
		finally (io dir') (removeTree dir'))

todo :: String -> Test
todo name = skipIf True (assertions name (return ()))