[commit: packages/random] master: Make TestRandomRs (GHC #4218) fast and add to cabal file (bba3db1)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 15:44:54 UTC 2015


Repository : ssh://git@git.haskell.org/random

On branch  : master
Link       : http://git.haskell.org/packages/random.git/commitdiff/bba3db1dfd172790f9a6182d32e4034c42def6cb

>---------------------------------------------------------------

commit bba3db1dfd172790f9a6182d32e4034c42def6cb
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Tue Jul 1 16:28:57 2014 +0200

    Make TestRandomRs (GHC #4218) fast and add to cabal file


>---------------------------------------------------------------

bba3db1dfd172790f9a6182d32e4034c42def6cb
 random.cabal          | 16 +++++++++++++++-
 tests/TestRandomRs.hs | 38 ++++++++++++++++++--------------------
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/random.cabal b/random.cabal
index b0115de..511ce29 100644
--- a/random.cabal
+++ b/random.cabal
@@ -16,7 +16,9 @@ description:
 	library, including the ability to split random number
 	generators.
 build-type: Simple
-Cabal-Version: >= 1.6
+-- cabal-version 1.8 needed because "the field 'build-depends: random' refers
+-- to a library which is defined within the same package"
+cabal-version: >= 1.8
 
 
 
@@ -31,3 +33,15 @@ source-repository head
     type:     git
     location: http://git.haskell.org/packages/random.git
 
+-- To run the Test-Suite:
+-- $ cabal configure --enable-tests
+-- $ cabal test --show-details=always --test-options="+RTS -M1M -RTS"
+
+Test-Suite TestRandomRs
+    type:           exitcode-stdio-1.0
+    main-is:        TestRandomRs.hs
+    hs-source-dirs: tests
+    build-depends:  base >= 3 && < 5, random
+    ghc-options:    -rtsopts -O2
+    -- TODO. Why does the following not work?
+    --test-options:   +RTS -M1M -RTS
diff --git a/tests/TestRandomRs.hs b/tests/TestRandomRs.hs
index 74e319d..cdae106 100644
--- a/tests/TestRandomRs.hs
+++ b/tests/TestRandomRs.hs
@@ -1,24 +1,22 @@
-
--- Test from ticket #4218:
--- http://hackage.haskell.org/trac/ghc/ticket/4218
+-- Test for ticket #4218 (TestRandomRs):
+-- https://ghc.haskell.org/trac/ghc/ticket/4218
+--
+-- Fixed together with ticket #8704
+-- https://ghc.haskell.org/trac/ghc/ticket/8704
+-- Commit 4695ffa366f659940369f05e419a4f2249c3a776
+--
+-- Used to fail with:
+--
+-- $ cabal test TestRandomRs --test-options="+RTS -M1M -RTS"
+-- TestRandomRs: Heap exhausted;
 
 module Main where
 
-import Control.Monad
-import System.Random
-import Data.List
-
-force = foldr (\x r -> x `seq` (x:r)) []
-
--- Ten million random numbers:
-blowsTheHeap :: IO Integer
-blowsTheHeap = (last . take 10000000 . randomRs (0, 1000000)) `liftM` getStdGen
-
-works :: IO Integer
-works = (last . take 10000000 . force . randomRs (0, 1000000)) `liftM` getStdGen
-
-
-main = 
- do n <- blowsTheHeap
-    print n
+import Control.Monad (liftM, replicateM)
+import System.Random (randomRs, getStdGen)
 
+-- Return the five-thousandth random number:
+-- Should run in constant space (< 1Mb heap).
+main = do
+    n <- (last . take 5000 . randomRs (0, 1000000)) `liftM` getStdGen
+    print (n::Integer)



More information about the ghc-commits mailing list