简体   繁体   中英

Running HUnit tests with Hspec

I want to run HUnit tests inside a spec:

module SHCSpec (spec)
    where

import Test.Hspec
import Test.Hspec.Contrib.HUnit
import Test.HUnit

import SHC.Types
import SHC.Lix


spec :: Spec
spec = do
    fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
        [ Irrelevant @=? toHit []
        , None       @=? toHit [False]
        , None       @=? toHit [False, False]
        , Partial    @=? toHit [False, True]
        , Partial    @=? toHit [True, False]
        , Partial    @=? toHit [False, False, True]
        , Partial    @=? toHit [False, True, False]
        , Partial    @=? toHit [True, False, False]
        , Full       @=? toHit [True]
        , Full       @=? toHit [True, True]
        ])

The above code works, but it produces this ugly output:

SHC
  SHC.Lix
    toHit
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>

Is it possible to attach the label toHit to every test case? Something like this:

SHC
  SHC.Lix
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit

Even better would be to append a number to each toHit case. I messed with TestList and map TestLabel to no avail.

How about attaching labels to all the tests with a function like:

label ts =
  [ show i ~: t | (i,t) <- zip [(1::Int)..] ts ]

Just prefix your list of tests with a call to label :

spec :: Spec
spec = do
    fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
        label
        [ Irrelevant @=? toHit []
        , None       @=? toHit [False]
        ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM