summaryrefslogtreecommitdiff
path: root/Logs/Transfer.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-27 21:42:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-27 21:42:07 -0400
commitca59b87b11c01c417a7b3b8f0cf15426e6fadcfb (patch)
tree36c342a8ae999986aabf51d6a3371515e9ac1dfd /Logs/Transfer.hs
parentf54b34a6e6cb000d3117106fd19c13ef9dc7f38f (diff)
move Arbitrary instances out of Test and into modules that define the types
This is possible now that we build-depend on QuickCheck.
Diffstat (limited to 'Logs/Transfer.hs')
-rw-r--r--Logs/Transfer.hs31
1 files changed, 22 insertions, 9 deletions
diff --git a/Logs/Transfer.hs b/Logs/Transfer.hs
index e92dce2c0..018e1d4ff 100644
--- a/Logs/Transfer.hs
+++ b/Logs/Transfer.hs
@@ -21,6 +21,8 @@ import Data.Time.Clock.POSIX
import Data.Time
import System.Locale
import Control.Concurrent
+import Test.QuickCheck
+import Utility.QuickCheck ()
{- Enough information to uniquely identify a transfer, used as the filename
- of the transfer information file. -}
@@ -306,15 +308,6 @@ readTransferInfo mpid s = TransferInfo
then Just <$> readish =<< headMaybe (drop 1 bits)
else pure Nothing -- not failure
-{- for quickcheck -}
-prop_read_write_transferinfo :: TransferInfo -> Bool
-prop_read_write_transferinfo info
- | transferRemote info /= Nothing = True -- remote not stored
- | transferTid info /= Nothing = True -- tid not stored
- | otherwise = Just (info { transferPaused = False }) == info'
- where
- info' = readTransferInfo (transferPid info) (writeTransferInfo info)
-
parsePOSIXTime :: String -> Maybe POSIXTime
parsePOSIXTime s = utcTimeToPOSIXSeconds
<$> parseTime defaultTimeLocale "%s%Qs" s
@@ -330,3 +323,23 @@ failedTransferDir u direction r = gitAnnexTransferDir r
</> "failed"
</> showLcDirection direction
</> filter (/= '/') (fromUUID u)
+
+instance Arbitrary TransferInfo where
+ arbitrary = TransferInfo
+ <$> arbitrary
+ <*> arbitrary
+ <*> pure Nothing -- cannot generate a ThreadID
+ <*> pure Nothing -- remote not needed
+ <*> arbitrary
+ -- associated file cannot be empty (but can be Nothing)
+ <*> arbitrary `suchThat` (/= Just "")
+ <*> arbitrary
+
+prop_read_write_transferinfo :: TransferInfo -> Bool
+prop_read_write_transferinfo info
+ | transferRemote info /= Nothing = True -- remote not stored
+ | transferTid info /= Nothing = True -- tid not stored
+ | otherwise = Just (info { transferPaused = False }) == info'
+ where
+ info' = readTransferInfo (transferPid info) (writeTransferInfo info)
+