Skip to content

Commit

Permalink
Tests: move away from detailed interface
Browse files Browse the repository at this point in the history
Use `exitcode-stdio-1.0` instead. Because these tests randomly fail for GHC 8.0.2 and 7.10.3 with this error:

```
panic! read @TestSuiteLog ""
CallStack (from HasCallStack):
  error, called at src/Distribution/Simple/Test/LibV09.hs:133:34 in Cabal-3.10.1.0-5sSVeMY5t4HKsrW2wqIvsr:Distribution.Simple.Test.LibV09
```
  • Loading branch information
runeksvendsen committed Jan 7, 2025
1 parent 277a60d commit faf7dc8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
18 changes: 17 additions & 1 deletion Test/AllTests.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{-
Some tests to verify that serialisation works as expected
-}
module AllTests(tests)
module Main(main)
where

import GHC.Packing

import qualified Data.Array.IArray as A
import Control.Concurrent
import Control.Monad (forM_, forM, unless)

import System.Environment
import System.IO
import System.Directory
import qualified System.Exit
import qualified Data.ByteString as B
import Control.Exception
import Data.Typeable
Expand Down Expand Up @@ -52,6 +54,20 @@ tests = do putStrLn "Running all tests"
-- all configured tests, see below
mytests = [eval_array, pack_array, pack_ThreadId, pack_MVar ]

main :: IO ()
main = do
putStrLn "Running all tests"
results <- forM mytests runTest
unless (and results) $ do
putStrLn "Some tests failed (see output above)"
System.Exit.exitFailure
where
runTest (name, action) = do
putStrLn $ "Running test '" ++ name ++ "'..."
b <- action
putStrLn $ (if b then "PASS: " else "FAIL: ") ++ name
return b

-- test data
arr, output :: A.Array Int Int
arr = A.array (0,127) [ (i,i) | i <- [0..127] ]
Expand Down
32 changes: 27 additions & 5 deletions Test/QCTest.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE RecordWildCards, DeriveFunctor #-}
module QCTest(tests) where
module Main(main) where

import Distribution.TestSuite
import Test.QuickCheck
Expand All @@ -10,11 +10,33 @@ import qualified Data.Foldable as F
import Control.Applicative

import GHC.Packing

-- use "detailed" interface: defining test instances
tests :: IO [Test]
tests = mapM (return . Test . uncurry (runQC 10))
import qualified System.Exit
import Control.Monad (forM, unless)

main :: IO ()
main = do
putStrLn "Running all tests"
results <- forM mytests runTest
unless (and results) $ do
putStrLn "Some tests failed (see output above)"
System.Exit.exitFailure
where
runTest (name, action) = do
putStrLn $ "Running test '" ++ name ++ "'..."
b <- action
putStrLn $ (if b then "PASS: " else "FAIL: ") ++ name
return b

mytests :: [(String, IO Bool)]
mytests =
map
(fmap (runQC' 10))
[boldTrees, foldmap square (+) 0, foldmapforce square (+) 0 ]
where
runQC' size = fmap readResult . quickCheckWithResult stdArgs{maxSize=size}

readResult Success{..} = True
readResult _ = False

square x = x*x

Expand Down
8 changes: 4 additions & 4 deletions packman.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ test-suite testexceptions
ghc-options: -debug -optc-g -optc-DDEBUG

test-suite alltests
type: detailed-0.9
test-module: AllTests
type: exitcode-stdio-1.0
main-is: AllTests.hs
hs-source-dirs: Test
build-depends: base >= 4.7,
directory >= 1.2,
Expand Down Expand Up @@ -159,8 +159,8 @@ test-suite testmthread
ghc-options: -with-rtsopts=-N4 -threaded

test-suite quickchecktest
type: detailed-0.9
test-module: QCTest
type: exitcode-stdio-1.0
main-is: QCTest.hs
hs-source-dirs: Test
build-depends: base >= 4.7,
directory >= 1.2,
Expand Down

0 comments on commit faf7dc8

Please sign in to comment.