Skip to content

Commit

Permalink
Merge pull request #12 from well-typed/test-split
Browse files Browse the repository at this point in the history
Split tests into internal and external
  • Loading branch information
dcoutts authored Jun 14, 2024
2 parents e8fd52f + 966d277 commit 444d84d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 28 deletions.
29 changes: 23 additions & 6 deletions blockio-uring.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ source-repository head

library
exposed-modules: System.IO.BlockIO
hs-source-dirs: src
other-modules:
System.IO.BlockIO.URing
System.IO.BlockIO.URingFFI

build-depends:
base >=4.12 && <4.20
, base >=4.12 && <4.20
, primitive ^>=0.9
, vector ^>=0.13

Expand All @@ -51,7 +52,7 @@ library
benchmark bench
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: benchmark .
hs-source-dirs: benchmark src
main-is: Bench.hs
build-depends:
, array
Expand All @@ -61,8 +62,8 @@ benchmark bench
, primitive
, random
, time
, vector
, unix
, vector

pkgconfig-depends: liburing
other-modules:
Expand All @@ -73,17 +74,33 @@ benchmark bench
ghc-options: -Wall -threaded

test-suite test
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: test.hs
build-depends:
, array
, base
, blockio-uring
, primitive
, tasty
, tasty-hunit
, vector

ghc-options: -threaded

test-suite test-internals
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test .
main-is: Main.hs
hs-source-dirs: test src
main-is: test-internals.hs
build-depends:
, array
, base
, primitive
, tasty
, vector
, tasty-hunit
, vector

pkgconfig-depends: liburing
other-modules:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 3 additions & 22 deletions test/Main.hs → test/test-internals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,27 @@ module Main (main) where

import Control.Exception (SomeException, try)
import Data.Word (Word64)
import System.IO.BlockIO
import System.IO.BlockIO.URing as URing
import System.IO.BlockIO.URing
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "test" [
tests = testGroup "test-internals" [
testCase "example_simpleNoop 1" $ example_simpleNoop 1
, testCase "example_simpleNoop maxBound" $ example_simpleNoop maxBound
, testCase "example_initClose" example_initClose
, testCase "example_closeIsIdempotent" example_closeIsIdempotent
]

example_simpleNoop :: Word64 -> Assertion
example_simpleNoop n = do
uring <- setupURing (URingParams 1)
prepareNop uring (IOOpId n)
URing.submitIO uring
submitIO uring
completion <- awaitIO uring
closeURing uring
IOCompletion (IOOpId n) (IOResult 0) @=? completion

deriving instance Eq IOCompletion
deriving instance Show IOCompletion

example_initClose :: Assertion
example_initClose = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx

example_closeIsIdempotent :: Assertion
example_closeIsIdempotent = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx
eith <- try @SomeException (closeIOCtx ctx)
case eith of
Left (e :: SomeException) ->
assertFailure ("Close on a closed context threw an error : " <> show e)
Right () ->
pure ()
31 changes: 31 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Main (main) where

import Control.Exception (SomeException, try)
import System.IO.BlockIO
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "test"
[ testCase "example_initClose" example_initClose
, testCase "example_closeIsIdempotent" example_closeIsIdempotent
]

example_initClose :: Assertion
example_initClose = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx

example_closeIsIdempotent :: Assertion
example_closeIsIdempotent = do
ctx <- initIOCtx defaultIOCtxParams
closeIOCtx ctx
eith <- try (closeIOCtx ctx)
case eith of
Left e ->
assertFailure ("Close on a closed context threw an error : " <> show (e :: SomeException))
Right () ->
pure ()

0 comments on commit 444d84d

Please sign in to comment.