packages feed

leksah-0.13.3.0: tests/Tests.hs

{-# LANGUAGE TemplateHaskell #-}
-----------------------------------------------------------------------------
--
-- Module      :  Tests
-- Copyright   :  (c) Juergen Nicklisch-Franken, Hamish Mackenzie
-- License     :  GNU-GPL
--
-- Maintainer  :  <maintainer at leksah.org>
-- Stability   :  provisional
-- Portability :  portable
--
-- |
--
-------------------------------------------------------------------------------
module Main (main) where

import System.Exit (exitFailure)
import Test.QuickCheck.All (quickCheckAll)
import IDE.ImportTool (parseHiddenModule, HiddenModuleResult(..))
import Control.Monad (unless)
import Distribution.Package
       (PackageName(..), PackageIdentifier(..))
import Distribution.Version (Version(..))
import Graphics.UI.Gtk (timeoutAddFull, initGUI)
import IDE.TextEditor.Tests (testEditors)
import System.Log.Logger
       (errorM, setLevel, rootLoggerName, updateGlobalLogger)
import System.Log (Priority(..))
import Control.Concurrent
       (yield, takeMVar, putMVar, newEmptyMVar, threadDelay, forkIO)
import System.Glib.MainLoop (priorityHigh)

testString =    "    Could not find module `Graphics.UI.Gtk':\n"
             ++ "      It is a member of the hidden package `gtk-0.11.0'.\n"
             ++ "      Perhaps you need to add `gtk' to the build-depends in your .cabal file.\n"
             ++ "      Use -v to see a list of the files searched for."

prop_parseHiddenModule = parseHiddenModule testString == Just HiddenModuleResult {hiddenModule = "Graphics.UI.Gtk", missingPackage = PackageIdentifier {pkgName = PackageName "gtk", pkgVersion = Version {versionBranch = [0,11,0], versionTags = []}}}

-- At some point the : was removed from this message...
testString2 =   "    Could not find module `Data.Attoparsec.Lazy'\n"
             ++ "    It is a member of the hidden package `attoparsec-0.10.2.0'.\n"
             ++ "    Perhaps you need to add `attoparsec' to the build-depends in your .cabal file.\n"
             ++ "    Use -v to see a list of the files searched for.\n"

prop_parseHiddenModule2 = parseHiddenModule testString2 == Just HiddenModuleResult {hiddenModule = "Data.Attoparsec.Lazy", missingPackage = PackageIdentifier {pkgName = PackageName "attoparsec", pkgVersion = Version {versionBranch = [0,10,2,0], versionTags = []}}}

main = do
    result <- newEmptyMVar
    forkIO $ do
        updateGlobalLogger rootLoggerName (setLevel DEBUG)
        allPass <- $quickCheckAll -- Run QuickCheck on all prop_ functions
        initGUI
        timeoutAddFull (yield >> return True) priorityHigh 10
        editorsOk <- testEditors
        putMVar result (allPass && editorsOk)
    forkIO $ do
        threadDelay 60000000
        errorM "leksah tests" "Test took too long to run"
        putMVar result False
    r <- takeMVar result
    unless r exitFailure