blob: 2fd89149d108442b0a8f942bb48f426e8025a37f [file] [log] [blame]
-- | A test of the FSATrace program
module Utils(
Env(..), ShellMode(..), SpaceMode(..),
Prop,
Path(..), Arg(..),
cased, valid
) where
import Parse
import Control.Monad.Trans.Reader
import Data.Char
import Data.List
import System.FilePath
import System.Info.Extra
import Test.QuickCheck
--import Debug.Trace
data Env = Env
{ shellMode :: ShellMode
, tmpDir :: FilePath
, pwdDir :: FilePath
}
type Prop = Reader Env Property
newtype Arg = Arg { unarg :: String } deriving (Show, Eq)
instance Arbitrary Arg where
arbitrary = Arg <$> listOf1 validChars
where validChars = arbitrary `suchThat` (`notElem` "\0")
newtype Path = Path { unpath :: FilePath }
instance Eq Path where
(==) (Path a) (Path b) = equalFilePath a b
instance Show Path where
show (Path p) = show p
instance Ord Path where
compare (Path x) (Path y) = compare (cased x) (cased y)
data ShellMode = Unshelled | Shelled deriving (Show, Eq, Enum, Bounded)
data SpaceMode = Unspaced | Spaced deriving (Show, Eq, Enum, Bounded)
cased :: String -> String
cased | isWindows = map toLower
| otherwise = id
valid :: FilePath -> Access Path -> Bool
valid t (R p) = inTmp t p
valid t (Q p) = inTmp t p
valid t (W p) | isWindows = inTmp t p
| otherwise = not $ "/dev/" `isPrefixOf` unpath p
valid t (D p) = inTmp t p
valid t (T p) = inTmp t p
valid t (M p _) = inTmp t p
valid _ (RW _) = False -- sort on Windows produces this
valid _ _ = True
inTmp :: FilePath -> Path -> Bool
inTmp t = isPrefixOf (cased t) . cased . unpath