2014-03-30 17:12:33 +00:00
|
|
|
module Property.File where
|
|
|
|
|
2014-03-30 19:14:36 +00:00
|
|
|
import System.Directory
|
|
|
|
|
2014-03-30 17:12:33 +00:00
|
|
|
import Property
|
2014-03-30 19:14:36 +00:00
|
|
|
import Utility.Directory
|
2014-03-30 17:12:33 +00:00
|
|
|
|
|
|
|
{- Replaces all the content of a file. -}
|
|
|
|
hasContent :: FilePath -> [Line] -> Property
|
|
|
|
f `hasContent` newcontent = FileProperty ("replace " ++ f)
|
|
|
|
f (\_oldcontent -> newcontent)
|
|
|
|
|
|
|
|
{- Ensures that a line is present in a file, adding it to the end if not. -}
|
|
|
|
containsLine :: FilePath -> Line -> Property
|
|
|
|
f `containsLine` l = FileProperty (f ++ " contains:" ++ l) f go
|
|
|
|
where
|
|
|
|
go ls
|
|
|
|
| l `elem` ls = ls
|
|
|
|
| otherwise = ls++[l]
|
|
|
|
|
|
|
|
{- Ensures that a line is not present in a file.
|
|
|
|
- Note that the file is ensured to exist, so if it doesn't, an empty
|
|
|
|
- file will be written. -}
|
|
|
|
lacksLine :: FilePath -> Line -> Property
|
|
|
|
f `lacksLine` l = FileProperty (f ++ " remove: " ++ l) f (filter (/= l))
|
2014-03-30 19:14:36 +00:00
|
|
|
|
|
|
|
{- Note: Does not remove symlinks or non-plain-files. -}
|
|
|
|
notPresent :: FilePath -> Property
|
|
|
|
notPresent f = check (doesFileExist f) $ IOProperty (f ++ " not present") $
|
|
|
|
makeChange $ nukeFile f
|