Hello community, here is the log from the commit of package ghc-clock for openSUSE:Factory checked in at 2015-08-23 15:43:04 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-clock (Old) and /work/SRC/openSUSE:Factory/.ghc-clock.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-clock" Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-clock/ghc-clock.changes 2015-05-21 08:35:36.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-clock.new/ghc-clock.changes 2015-08-23 17:38:47.000000000 +0200 @@ -1,0 +2,5 @@ +Thu Aug 6 19:54:15 UTC 2015 - [email protected] + +- update to 0.5.1 + +------------------------------------------------------------------- Old: ---- clock-0.4.6.0.tar.gz New: ---- clock-0.5.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-clock.spec ++++++ --- /var/tmp/diff_new_pack.gMpv0r/_old 2015-08-23 17:38:48.000000000 +0200 +++ /var/tmp/diff_new_pack.gMpv0r/_new 2015-08-23 17:38:48.000000000 +0200 @@ -18,8 +18,8 @@ %global pkg_name clock -Name: ghc-%{pkg_name} -Version: 0.4.6.0 +Name: ghc-clock +Version: 0.5.1 Release: 0 Summary: High-resolution clock functions: monotonic, realtime, cputime License: BSD-3-Clause ++++++ clock-0.4.6.0.tar.gz -> clock-0.5.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/clock-0.4.6.0/System/Clock.hsc new/clock-0.5.1/System/Clock.hsc --- old/clock-0.4.6.0/System/Clock.hsc 2015-05-08 15:39:59.000000000 +0200 +++ new/clock-0.5.1/System/Clock.hsc 2015-06-28 01:57:26.000000000 +0200 @@ -4,6 +4,9 @@ -- <http://www.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html#> {-# OPTIONS_GHC -fno-warn-type-defaults #-} +-- To allow importing Data.Int and Data.Word indiscriminately on all platforms, +-- since we can't systematically predict what typedef's expand to. +{-# OPTIONS_GHC -fno-warn-unused-imports #-} module System.Clock ( Clock(..) @@ -16,6 +19,7 @@ import Control.Applicative ((<$>), (<*>)) import Data.Int +import Data.Word import Data.Typeable (Typeable) import Foreign.Ptr import Foreign.Storable @@ -24,7 +28,7 @@ #if defined(_WIN32) # include "hs_clock_win32.c" -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) # include "hs_clock_darwin.c" #else # include <time.h> @@ -76,7 +80,7 @@ foreign import ccall hs_clock_win32_getres_realtime :: Ptr TimeSpec -> IO () foreign import ccall hs_clock_win32_getres_processtime :: Ptr TimeSpec -> IO () foreign import ccall hs_clock_win32_getres_threadtime :: Ptr TimeSpec -> IO () -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) foreign import ccall hs_clock_darwin_gettime :: #{type clock_id_t} -> Ptr TimeSpec -> IO () foreign import ccall hs_clock_darwin_getres :: #{type clock_id_t} -> Ptr TimeSpec -> IO () #else @@ -85,7 +89,7 @@ #endif #if defined(_WIN32) -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) clockToConst :: Clock -> #{type clock_id_t} clockToConst Monotonic = #const SYSTEM_CLOCK clockToConst Realtime = #const CALENDAR_CLOCK @@ -116,7 +120,7 @@ getTime Realtime = allocaAndPeek hs_clock_win32_gettime_realtime getTime ProcessCPUTime = allocaAndPeek hs_clock_win32_gettime_processtime getTime ThreadCPUTime = allocaAndPeek hs_clock_win32_gettime_threadtime -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) getTime clk = allocaAndPeek $ hs_clock_darwin_gettime $ clockToConst clk #else getTime clk = allocaAndPeek $ clock_gettime $ clockToConst clk @@ -127,7 +131,7 @@ getRes Realtime = allocaAndPeek hs_clock_win32_getres_realtime getRes ProcessCPUTime = allocaAndPeek hs_clock_win32_getres_processtime getRes ThreadCPUTime = allocaAndPeek hs_clock_win32_getres_threadtime -#elif defined(__MACH__) +#elif defined(__MACH__) && defined(__APPLE__) getRes clk = allocaAndPeek $ hs_clock_darwin_getres $ clockToConst clk #else getRes clk = allocaAndPeek $ clock_getres $ clockToConst clk @@ -137,7 +141,7 @@ data TimeSpec = TimeSpec { sec :: {-# UNPACK #-} !Int64 -- ^ seconds , nsec :: {-# UNPACK #-} !Int64 -- ^ nanoseconds - } deriving (Eq, Generic, Read, Show, Typeable) + } deriving (Generic, Read, Show, Typeable) #if defined(_WIN32) instance Storable TimeSpec where @@ -166,31 +170,53 @@ #endif normalize :: TimeSpec -> TimeSpec -normalize (TimeSpec xs xn) = +normalize (TimeSpec xs xn) + | xn < 0 || xn >= 10^9 = let (q, r) = xn `divMod` (10^9) in TimeSpec (xs + q) r + | otherwise = TimeSpec xs xn instance Num TimeSpec where (TimeSpec xs xn) + (TimeSpec ys yn) = normalize $ TimeSpec (xs + ys) (xn + yn) (TimeSpec xs xn) - (TimeSpec ys yn) = normalize $ TimeSpec (xs - ys) (xn - yn) - (TimeSpec xs xn) * (TimeSpec ys yn) = - normalize $ TimeSpec (xs * ys) (xn * yn) + (normalize -> TimeSpec xs xn) * (normalize -> TimeSpec ys yn) = + let + -- convert to arbitraty Integer type to avoid int overflow + xsi = toInteger xs + xni = toInteger xn + ysi = toInteger ys + yni = toInteger yn + in + normalize $ TimeSpec + -- seconds + (fromInteger $ xsi * ysi) + -- nanoseconds + (fromInteger $ (xni * yni + (xni * ysi + xsi * yni) * (10^9)) + `div` (10^9)) negate (TimeSpec xs xn) = normalize $ TimeSpec (negate xs) (negate xn) - abs (TimeSpec xs xn) = - normalize $ TimeSpec (abs xs) (signum xs * xn) - signum (normalize -> TimeSpec xs yn) - | signum xs == 0 = TimeSpec 0 (signum yn) - | otherwise = TimeSpec 0 (signum xs) + abs (normalize -> TimeSpec xs xn) + | xs == 0 = normalize $ TimeSpec 0 xn + | otherwise = normalize $ TimeSpec (abs xs) (signum xs * xn) + signum (normalize -> TimeSpec xs xn) + | xs == 0 = TimeSpec (signum xn) 0 + | otherwise = TimeSpec (signum xs) 0 fromInteger x = -- For range, compute div, mod over integers, not any bounded type. let (q, r) = x `divMod` (10^9) in TimeSpec (fromInteger q) (fromInteger r) +instance Eq TimeSpec where + (normalize -> TimeSpec xs xn) == (normalize -> TimeSpec ys yn) + | True == equality = xn == yn + | otherwise = equality + where + equality = xs == ys + instance Ord TimeSpec where - compare (TimeSpec xs xn) (TimeSpec ys yn) + compare (normalize -> TimeSpec xs xn) (normalize -> TimeSpec ys yn) | EQ == ordering = compare xn yn | otherwise = ordering where @@ -202,4 +228,4 @@ -- | TimeSpec as nano seconds. timeSpecAsNanoSecs :: TimeSpec -> Integer -timeSpecAsNanoSecs t = toInteger (sec t) * 1000000000 + toInteger (nsec t) +timeSpecAsNanoSecs t = toInteger (sec t) * (10^9) + toInteger (nsec t) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/clock-0.4.6.0/clock.cabal new/clock-0.5.1/clock.cabal --- old/clock-0.4.6.0/clock.cabal 2015-05-08 15:39:59.000000000 +0200 +++ new/clock-0.5.1/clock.cabal 2015-06-28 01:57:26.000000000 +0200 @@ -1,5 +1,5 @@ name: clock -version: 0.4.6.0 +version: 0.5.1 stability: stable synopsis: High-resolution clock functions: monotonic, realtime, cputime. description: A package for convenient access to high-resolution clock and @@ -23,14 +23,14 @@ . Imported Control.Applicative operators correctly for Haskell Platform on Windows on 2015-04-21. . - GNU/HURD build failure reported by Pino Toscano, patched by Joachim Breitner on 2015-05-07. + Unit tests and instance fixes by Christian Burger on 2015-06-25. . [Version Scheme] Major-@/R/@-ewrite . New-@/F/@-unctionality . @/I/@-mprovementAndBugFixes . @/P/@-ackagingOnly . * @PackagingOnly@ changes are made for quality assurance reasons. -copyright: Copyright © Cetin Sert 2009-2013, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014, Chris Done 2015, Dimitri Sabadie 2015 +copyright: Copyright © Cetin Sert 2009-2013, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014 2015, Chris Done 2015, Dimitri Sabadie 2015, Christian Burger 2015 license: BSD3 license-file: LICENSE author: Cetin Sert <[email protected]>, Corsis Research @@ -39,7 +39,7 @@ bug-reports: https://github.com/corsis/clock/issues category: System build-type: Simple -cabal-version: >= 1.6 +cabal-version: >= 1.8 source-repository head @@ -71,3 +71,19 @@ if flag(llvm) ghc-options: -fllvm -optlo-O3 + + +test-suite test +-- default-language: +-- Haskell2010 + type: + exitcode-stdio-1.0 + hs-source-dirs: + tests + main-is: + test.hs + build-depends: + base >= 4 && < 5 + , tasty >= 0.10 + , tasty-quickcheck + , clock diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/clock-0.4.6.0/tests/test.hs new/clock-0.5.1/tests/test.hs --- old/clock-0.4.6.0/tests/test.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/clock-0.5.1/tests/test.hs 2015-06-28 01:57:26.000000000 +0200 @@ -0,0 +1,59 @@ +import Test.Tasty +import Test.Tasty.QuickCheck as QuickCheck +import Data.Fixed +import Data.List +-- import Test.Tasty.HUnit as HUnit +import System.Clock + +instance Arbitrary TimeSpec where + arbitrary = do + sec <- arbitrarySizedIntegral + nan <- arbitrarySizedIntegral + return $ TimeSpec sec nan + +main = defaultMain (adjustOption (QuickCheckTests 100000 +) $ tests) + +tests :: TestTree +tests = testGroup "All tests" [numInstanceTests, eqOrdInstancesTests] + +numInstanceTests = testGroup "Num class tests" [ + -- let's make at least 100,000 tests + qcNumInstance + ] + +eqOrdInstancesTests = testGroup "Eq and Ord instance tests" [ + -- let's make at least 100,000 tests + qcEqOrdInstance + ] + +qcNumInstance = testGroup "QuickCheck" + [ + QuickCheck.testProperty "x = abs(x) * signum(x)" $ + \ x -> (x :: TimeSpec) == (abs x) * (signum x) + , QuickCheck.testProperty "integer addition equals TimeSpec addition" $ + \ x y -> x + y == timeSpecAsNanoSecs (fromInteger x + fromInteger y) + , QuickCheck.testProperty "integer substraction equals TimeSpec addition" $ + \ x y -> x - y == timeSpecAsNanoSecs (fromInteger x - fromInteger y) + , QuickCheck.testProperty + "rational multiplication equals TimeSpec multiplication" $ + \ x y -> + let + rationalMul = truncate ((x :: Nano) * (y :: Nano) * (10^9)) + timespecMul = timeSpecAsNanoSecs ( + fromInteger (truncate (x * 10^9)) + * fromInteger (truncate (y * 10^9))) + in + rationalMul == timespecMul + , QuickCheck.testProperty "neg(neg(x)) = x" $ + \ x -> negate (negate x :: TimeSpec) == x + ] + +qcEqOrdInstance = testGroup "QuickCheck" + [ + QuickCheck.testProperty + "random list of TimeSpecs is sorted like equivalent list of integers" $ + \ x -> + sort (x :: [TimeSpec]) + == + map (fromInteger) (sort (map timeSpecAsNanoSecs x)) + ]
