summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:27:08 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:27:08 -0400
commita323463726096bba15b6a353d35bc1eb0ae238b9 (patch)
tree5039b8e1505f41a716d4543c0235255d701fb4ab
parentaedc46caca6f24755c914f105d1ac6d9787a7755 (diff)
add more tests
-rw-r--r--Utility.hs31
-rw-r--r--test.hs15
2 files changed, 32 insertions, 14 deletions
diff --git a/Utility.hs b/Utility.hs
index 4ab5f0930..96bbc89ee 100644
--- a/Utility.hs
+++ b/Utility.hs
@@ -19,8 +19,10 @@ module Utility (
readMaybe,
safeWriteFile,
- prop_idempotent_shellescape,
- prop_idempotent_shellescape_multiword
+ prop_idempotent_shellEscape,
+ prop_idempotent_shellEscape_multiword,
+ prop_parentDir_basics,
+ prop_relPathDirToDir_basics
) where
import System.IO
@@ -45,7 +47,7 @@ readFileStrict :: FilePath -> IO String
readFileStrict f = readFile f >>= \s -> length s `seq` return s
{- Returns the parent directory of a path. Parent of / is "" -}
-parentDir :: String -> String
+parentDir :: FilePath -> FilePath
parentDir dir =
if not $ null dirs
then slash ++ join s (take (length dirs - 1) dirs)
@@ -55,6 +57,14 @@ parentDir dir =
slash = if isAbsolute dir then s else ""
s = [pathSeparator]
+prop_parentDir_basics :: FilePath -> Bool
+prop_parentDir_basics dir
+ | null dir = True
+ | dir == "/" = parentDir dir == ""
+ | otherwise = p /= dir
+ where
+ p = parentDir dir
+
{- Converts a filename into a normalized, absolute path. -}
absPath :: FilePath -> IO FilePath
absPath file = do
@@ -97,6 +107,13 @@ relPathDirToDir from to =
numcommon = length common
path = join s $ dotdots ++ uncommon
+prop_relPathDirToDir_basics :: FilePath -> FilePath -> Bool
+prop_relPathDirToDir_basics from to
+ | from == to = null r
+ | otherwise = not (null r) && (last r == '/')
+ where
+ r = relPathDirToDir from to
+
{- Run a system command, and returns True or False
- if it succeeded or failed.
-
@@ -150,10 +167,10 @@ shellUnEscape s = word:(shellUnEscape rest)
| otherwise = inquote q (w++[c]) cs
{- For quickcheck. -}
-prop_idempotent_shellescape :: String -> Bool
-prop_idempotent_shellescape s = [s] == (shellUnEscape $ shellEscape s)
-prop_idempotent_shellescape_multiword :: [String] -> Bool
-prop_idempotent_shellescape_multiword s = s == (shellUnEscape $ unwords $ map shellEscape s)
+prop_idempotent_shellEscape :: String -> Bool
+prop_idempotent_shellEscape s = [s] == (shellUnEscape $ shellEscape s)
+prop_idempotent_shellEscape_multiword :: [String] -> Bool
+prop_idempotent_shellEscape_multiword s = s == (shellUnEscape $ unwords $ map shellEscape s)
{- Removes a FileMode from a file.
- For example, call with otherWriteMode to chmod o-w -}
diff --git a/test.hs b/test.hs
index 28b54b78b..77a8606b3 100644
--- a/test.hs
+++ b/test.hs
@@ -7,14 +7,15 @@ import Utility
import TypeInternals
alltests :: [Test]
-alltests = [
- qctest "prop_idempotent_deencode" prop_idempotent_deencode,
- qctest "prop_idempotent_fileKey" prop_idempotent_fileKey,
- qctest "prop_idempotent_key_read_show" prop_idempotent_key_read_show,
- qctest "prop_idempotent_shellescape" prop_idempotent_shellescape,
- qctest "prop_idempotent_shellescape_multiword" prop_idempotent_shellescape_multiword
+alltests =
+ [ qctest "prop_idempotent_deencode" prop_idempotent_deencode
+ , qctest "prop_idempotent_fileKey" prop_idempotent_fileKey
+ , qctest "prop_idempotent_key_read_show" prop_idempotent_key_read_show
+ , qctest "prop_idempotent_shellEscape" prop_idempotent_shellEscape
+ , qctest "prop_idempotent_shellEscape_multiword" prop_idempotent_shellEscape_multiword
+ , qctest "prop_parentDir_basics" prop_parentDir_basics
+ , qctest "prop_relPathDirToDir_basics" prop_relPathDirToDir_basics
]
main :: IO (Counts, Int)
main = runVerboseTests (TestList alltests)
-