expose tasty test suite's option parser

This commit is contained in:
Joey Hess 2014-01-21 00:08:43 -04:00
parent df66e15555
commit d1bf61464f
6 changed files with 32 additions and 17 deletions

View file

@ -34,5 +34,4 @@ start ps = do
stop stop
startIO :: CmdParams -> IO () startIO :: CmdParams -> IO ()
startIO [] = warningIO "git-annex was built without its test suite; not testing" startIO _ = warningIO "git-annex was built without its test suite; not testing"
startIO _ = error "Cannot specify any additional parameters when running test"

35
Test.hs
View file

@ -14,9 +14,9 @@ import Test.Tasty.Runners
import Test.Tasty.HUnit import Test.Tasty.HUnit
import Test.Tasty.QuickCheck import Test.Tasty.QuickCheck
import Options.Applicative hiding (command)
import System.PosixCompat.Files import System.PosixCompat.Files
import Control.Exception.Extensible import Control.Exception.Extensible
import Data.Monoid
import qualified Data.Map as M import qualified Data.Map as M
import System.IO.HVFS (SystemFS(..)) import System.IO.HVFS (SystemFS(..))
import qualified Text.JSON import qualified Text.JSON
@ -72,8 +72,8 @@ import qualified Utility.Gpg
type TestEnv = M.Map String String type TestEnv = M.Map String String
main :: IO () main :: [String] -> IO ()
main = do main ps = do
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
indirectenv <- prepare False indirectenv <- prepare False
directenv <- prepare True directenv <- prepare True
@ -88,14 +88,27 @@ main = do
let tests = testGroup "Tests" let tests = testGroup "Tests"
[properties, unitTests env ""] [properties, unitTests env ""]
#endif #endif
let runner = tryIngredients [consoleTestReporter] mempty tests -- Can't use tasty's defaultMain because one of the command line
ifM (maybe (error "tasty failed to return a runner!") id runner) -- parameters is "test".
( exitSuccess let pinfo = info (helper <*> suiteOptionParser ingredients tests)
, do ( fullDesc <> header "Builtin test suite" )
putStrLn " (This could be due to a bug in git-annex, or an incompatability" opts <- either (\f -> error =<< errMessage f "git-annex test") return $
putStrLn " with utilities, such as git, installed on this system.)" execParserPure (prefs idm) pinfo ps
exitFailure case tryIngredients ingredients opts tests of
) Nothing -> error "No tests found!?"
Just act -> ifM act
( exitSuccess
, do
putStrLn " (This could be due to a bug in git-annex, or an incompatability"
putStrLn " with utilities, such as git, installed on this system.)"
exitFailure
)
ingredients :: [Ingredient]
ingredients =
[ consoleTestReporter
, listingTests
]
properties :: TestTree properties :: TestTree
properties = testGroup "QuickCheck" properties = testGroup "QuickCheck"

1
debian/control vendored
View file

@ -54,6 +54,7 @@ Build-Depends:
libghc-tasty-dev [!mipsel !sparc], libghc-tasty-dev [!mipsel !sparc],
libghc-tasty-hunit-dev [!mipsel !sparc], libghc-tasty-hunit-dev [!mipsel !sparc],
libghc-tasty-quickcheck-dev [!mipsel !sparc], libghc-tasty-quickcheck-dev [!mipsel !sparc],
libghc-optparse-applicative-dev,
lsof [!kfreebsd-i386 !kfreebsd-amd64], lsof [!kfreebsd-i386 !kfreebsd-amd64],
ikiwiki, ikiwiki,
perlmagick, perlmagick,

View file

@ -822,6 +822,8 @@ subdirectories).
This runs git-annex's built-in test suite. This runs git-annex's built-in test suite.
There are several parameters, provided by Haskell's tasty test framework.
* `xmppgit` * `xmppgit`
This command is used internally to perform git pulls over XMPP. This command is used internally to perform git pulls over XMPP.

View file

@ -114,7 +114,7 @@ Executable git-annex
CPP-Options: -DWITH_CLIBS CPP-Options: -DWITH_CLIBS
if flag(TestSuite) if flag(TestSuite)
Build-Depends: tasty, tasty-hunit, tasty-quickcheck Build-Depends: tasty, tasty-hunit, tasty-quickcheck, optparse-applicative
CPP-Options: -DWITH_TESTSUITE CPP-Options: -DWITH_TESTSUITE
if flag(TDFA) if flag(TDFA)

View file

@ -26,9 +26,9 @@ main = run =<< getProgName
go a = do go a = do
ps <- getArgs ps <- getArgs
#ifdef WITH_TESTSUITE #ifdef WITH_TESTSUITE
if ps == ["test"] case ps of
then Test.main ("test":ps') -> Test.main ps'
else a ps _ -> a ps
#else #else
a ps a ps
#endif #endif