Revision 105266b2 test/hs/Test/Ganeti/TestCommon.hs

b/test/hs/Test/Ganeti/TestCommon.hs
59 59
  , resultProp
60 60
  , readTestData
61 61
  , genSample
62
  , testParser
62 63
  ) where
63 64

  
64 65
import Control.Applicative
65 66
import Control.Exception (catchJust)
66 67
import Control.Monad
68
import Data.Attoparsec.Text (Parser, parseOnly)
67 69
import Data.List
70
import Data.Text (pack)
68 71
import Data.Word
69 72
import qualified Data.Set as Set
70 73
import System.Environment (getEnv)
......
340 343
  case values of
341 344
    [] -> error "sample' returned an empty list of values??"
342 345
    x:_ -> return x
346

  
347
-- | Function for testing whether a file is parsed correctly.
348
testParser :: (Show a, Eq a) => Parser a -> String -> a -> HUnit.Assertion
349
testParser parser fileName expectedContent = do
350
  fileContent <- readTestData fileName
351
  case parseOnly parser $ pack fileContent of
352
    Left msg -> HUnit.assertFailure $ "Parsing failed: " ++ msg
353
    Right obtained -> HUnit.assertEqual fileName expectedContent obtained

Also available in: Unified diff