packages feed

cron 0.2.5 → 0.2.6

raw patch · 3 files changed

+79/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

cron.cabal view
@@ -1,5 +1,5 @@ Name:                cron-Version:             0.2.5+Version:             0.2.6 Description:   Cron data structure and Attoparsec parser. The idea is to embed it in larger   systems which want to roll their own scheduled tasks in a format that people@@ -52,6 +52,10 @@   Type:           exitcode-stdio-1.0   Main-Is:        Spec.hs   Hs-Source-Dirs: test+  Other-Modules:  SpecHelper+                  System.Cron.ParserSpec+                  System.Cron.ScheduleSpec+                  System.CronSpec   Build-Depends:  base                  >= 4 && < 5,                   cron,                   hspec                 >= 1.3,
+ test/SpecHelper.hs view
@@ -0,0 +1,29 @@+{-# LANGUAGE TemplateHaskell #-}+module SpecHelper (module X) where++import Control.Applicative as X+import Data.DeriveTH+import Data.Time.Clock as X+import Data.Time.Calendar as X+import Data.Time.LocalTime as X+import Test.Hspec as X+import Test.Hspec.QuickCheck as X+import Test.QuickCheck as X++import System.Cron as X++import Debug.Trace as X++instance Arbitrary UTCTime where+  arbitrary = do+    d <- ModifiedJulianDay . fromInteger . getPositive <$> arbitrary+    t <- fromInteger . getPositive <$> arbitrary+    return $ UTCTime d t++$(derive makeArbitrary ''CronField)+$(derive makeArbitrary ''MinuteSpec)+$(derive makeArbitrary ''HourSpec)+$(derive makeArbitrary ''DayOfWeekSpec)+$(derive makeArbitrary ''DayOfMonthSpec)+$(derive makeArbitrary ''MonthSpec)+$(derive makeArbitrary ''CronSchedule)
+ test/System/Cron/ScheduleSpec.hs view
@@ -0,0 +1,45 @@+module System.Cron.ScheduleSpec+    ( spec+    ) where++import           Control.Concurrent+import           Test.Hspec++import           System.Cron.Schedule++spec :: Spec+spec = sequence_ [ describeMonadSchedule+                 , describeExecSchedule+                 ]++empty :: IO ()+empty = return ()++flipMVar :: MVar String -> IO ()+flipMVar v = putMVar v "dost thou even hoist"++describeMonadSchedule :: Spec+describeMonadSchedule = describe "MonadSchedule" $ do+    let Right ((), s) = runSchedule (do addJob empty "* * * * *"+                                        addJob empty "0 * * * *"+                                        addJob empty "0 0 * * *")+    it "should place the first job as the last job stated." $+        let (Job x _) = (s !! 0)+         in show x `shouldBe` "CronSchedule 0 0 * * *"+    it "should place the last job as the first job stated." $+        let (Job x _) = (s !! 2)+         in show x `shouldBe` "CronSchedule * * * * *"+    it "should read all three jobs." $+        length s `shouldBe` 3++describeExecSchedule :: Spec+describeExecSchedule = describe "execSchedule" $ do+    it "should set an mvar each minute" $+        fireAndWait >>= (`shouldBe` "dost thou even hoist")+    where fireAndWait = do+            v    <- newEmptyMVar+            tids <- execSchedule $ do+                addJob (flipMVar v) "* * * * *"+            threadDelay (1000000 * 60)+            mapM_ killThread tids+            takeMVar v