use tasty resources
This commit is contained in:
parent
78ead70ea4
commit
4a4e2f9a6c
3 changed files with 26 additions and 23 deletions
44
Test.hs
44
Test.hs
|
@ -74,20 +74,19 @@ type TestEnv = M.Map String String
|
||||||
|
|
||||||
main :: [String] -> IO ()
|
main :: [String] -> IO ()
|
||||||
main ps = do
|
main ps = do
|
||||||
|
let tests = testGroup "Tests"
|
||||||
|
-- Test both direct and indirect mode.
|
||||||
|
-- Windows is only going to use direct mode,
|
||||||
|
-- so don't test twice.
|
||||||
|
[ properties
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
indirectenv <- prepare False
|
, withTestEnv True $ unitTests "(direct)"
|
||||||
directenv <- prepare True
|
, withTestEnv False $ unitTests "(indirect)"
|
||||||
let tests = testGroup "Tests"
|
|
||||||
[ localOption (QuickCheckTests 1000) properties
|
|
||||||
, unitTests directenv "(direct)"
|
|
||||||
, unitTests indirectenv "(indirect)"
|
|
||||||
]
|
|
||||||
#else
|
#else
|
||||||
-- Windows is only going to use direct mode, so don't test twice.
|
, withTestEnv False $ unitTests ""
|
||||||
env <- prepare False
|
|
||||||
let tests = testGroup "Tests"
|
|
||||||
[properties, unitTests env ""]
|
|
||||||
#endif
|
#endif
|
||||||
|
]
|
||||||
|
|
||||||
-- Can't use tasty's defaultMain because one of the command line
|
-- Can't use tasty's defaultMain because one of the command line
|
||||||
-- parameters is "test".
|
-- parameters is "test".
|
||||||
let pinfo = info (helper <*> suiteOptionParser ingredients tests)
|
let pinfo = info (helper <*> suiteOptionParser ingredients tests)
|
||||||
|
@ -111,7 +110,7 @@ ingredients =
|
||||||
]
|
]
|
||||||
|
|
||||||
properties :: TestTree
|
properties :: TestTree
|
||||||
properties = testGroup "QuickCheck"
|
properties = localOption (QuickCheckTests 1000) $ testGroup "QuickCheck"
|
||||||
[ testProperty "prop_idempotent_deencode_git" Git.Filename.prop_idempotent_deencode
|
[ testProperty "prop_idempotent_deencode_git" Git.Filename.prop_idempotent_deencode
|
||||||
, testProperty "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode
|
, testProperty "prop_idempotent_deencode" Utility.Format.prop_idempotent_deencode
|
||||||
, testProperty "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey
|
, testProperty "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey
|
||||||
|
@ -142,9 +141,8 @@ properties = testGroup "QuickCheck"
|
||||||
, testProperty "prop_duration_roundtrips" Utility.HumanTime.prop_duration_roundtrips
|
, testProperty "prop_duration_roundtrips" Utility.HumanTime.prop_duration_roundtrips
|
||||||
]
|
]
|
||||||
|
|
||||||
unitTests :: TestEnv -> String -> TestTree
|
unitTests :: String -> IO TestEnv -> TestTree
|
||||||
unitTests env note = testGroup ("Unit Tests " ++ note)
|
unitTests note getenv = testGroup ("Unit Tests " ++ note)
|
||||||
-- test order matters, later tests may rely on state from earlier
|
|
||||||
[ check "init" test_init
|
[ check "init" test_init
|
||||||
, check "add" test_add
|
, check "add" test_add
|
||||||
, check "add sha1dup" test_add_sha1dup
|
, check "add sha1dup" test_add_sha1dup
|
||||||
|
@ -190,13 +188,13 @@ unitTests env note = testGroup ("Unit Tests " ++ note)
|
||||||
, check "bup remote" test_bup_remote
|
, check "bup remote" test_bup_remote
|
||||||
, check "crypto" test_crypto
|
, check "crypto" test_crypto
|
||||||
, check "preferred content" test_preferred_content
|
, check "preferred content" test_preferred_content
|
||||||
, check "global cleanup" test_global_cleanup
|
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
check desc t = testCase desc (t env)
|
check desc t = testCase desc (getenv >>= t)
|
||||||
|
|
||||||
test_global_cleanup :: TestEnv -> Assertion
|
{- Tests that need a origin git repo. -}
|
||||||
test_global_cleanup _env = cleanup tmpdir
|
withTestEnv :: Bool -> (IO TestEnv -> TestTree) -> TestTree
|
||||||
|
withTestEnv forcedirect = withResource (prepareTestEnv forcedirect) releaseTestEnv
|
||||||
|
|
||||||
test_init :: TestEnv -> Assertion
|
test_init :: TestEnv -> Assertion
|
||||||
test_init env = innewrepo env $ do
|
test_init env = innewrepo env $ do
|
||||||
|
@ -1258,8 +1256,12 @@ annexed_present = runchecks
|
||||||
unannexed :: FilePath -> Assertion
|
unannexed :: FilePath -> Assertion
|
||||||
unannexed = runchecks [checkregularfile, checkcontent, checkwritable]
|
unannexed = runchecks [checkregularfile, checkcontent, checkwritable]
|
||||||
|
|
||||||
prepare :: Bool -> IO TestEnv
|
releaseTestEnv :: TestEnv -> IO ()
|
||||||
prepare forcedirect = do
|
releaseTestEnv _env = do
|
||||||
|
cleanup tmpdir
|
||||||
|
|
||||||
|
prepareTestEnv :: Bool -> IO TestEnv
|
||||||
|
prepareTestEnv forcedirect = do
|
||||||
whenM (doesDirectoryExist tmpdir) $
|
whenM (doesDirectoryExist tmpdir) $
|
||||||
error $ "The temporary directory " ++ tmpdir ++ " already exists; cannot run test suite."
|
error $ "The temporary directory " ++ tmpdir ++ " already exists; cannot run test suite."
|
||||||
|
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -51,7 +51,7 @@ Build-Depends:
|
||||||
libghc-http-dev,
|
libghc-http-dev,
|
||||||
libghc-feed-dev,
|
libghc-feed-dev,
|
||||||
libghc-regex-tdfa-dev [!mipsel !s390],
|
libghc-regex-tdfa-dev [!mipsel !s390],
|
||||||
libghc-tasty-dev [!mipsel !sparc],
|
libghc-tasty-dev (>= 0.7) [!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,
|
libghc-optparse-applicative-dev,
|
||||||
|
|
|
@ -114,7 +114,8 @@ Executable git-annex
|
||||||
CPP-Options: -DWITH_CLIBS
|
CPP-Options: -DWITH_CLIBS
|
||||||
|
|
||||||
if flag(TestSuite)
|
if flag(TestSuite)
|
||||||
Build-Depends: tasty, tasty-hunit, tasty-quickcheck, optparse-applicative
|
Build-Depends: tasty (>= 0.7), tasty-hunit, tasty-quickcheck,
|
||||||
|
optparse-applicative
|
||||||
CPP-Options: -DWITH_TESTSUITE
|
CPP-Options: -DWITH_TESTSUITE
|
||||||
|
|
||||||
if flag(TDFA)
|
if flag(TDFA)
|
||||||
|
|
Loading…
Reference in a new issue