more tests
This commit is contained in:
parent
2533d826fc
commit
87f424eca7
3 changed files with 108 additions and 34 deletions
1
Makefile
1
Makefile
|
@ -37,6 +37,7 @@ testcoverage:
|
||||||
rm -f test.tix test
|
rm -f test.tix test
|
||||||
ghc -odir build/test -hidir build/test $(GHCFLAGS) --make -fhpc test
|
ghc -odir build/test -hidir build/test $(GHCFLAGS) --make -fhpc test
|
||||||
./test
|
./test
|
||||||
|
@echo ""
|
||||||
@hpc report test --exclude=Main --exclude=QC
|
@hpc report test --exclude=Main --exclude=QC
|
||||||
@hpc markup test --exclude=Main --exclude=QC --destdir=.hpc >/dev/null
|
@hpc markup test --exclude=Main --exclude=QC --destdir=.hpc >/dev/null
|
||||||
|
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -8,7 +8,7 @@ git-annex (0.16) UNRELEASED; urgency=low
|
||||||
significant problem, since the remote *did* record that it had the file.
|
significant problem, since the remote *did* record that it had the file.
|
||||||
* Also, add a general guard to detect attempts to record information
|
* Also, add a general guard to detect attempts to record information
|
||||||
about repositories with missing UUIDs.
|
about repositories with missing UUIDs.
|
||||||
* Test suite improvements. Current top-level test coverage: 43%
|
* Test suite improvements. Current top-level test coverage: 53%
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Tue, 04 Jan 2011 17:33:42 -0400
|
-- Joey Hess <joeyh@debian.org> Tue, 04 Jan 2011 17:33:42 -0400
|
||||||
|
|
||||||
|
|
139
test.hs
139
test.hs
|
@ -14,6 +14,7 @@ import IO (bracket_, bracket)
|
||||||
import Control.Monad (unless, when)
|
import Control.Monad (unless, when)
|
||||||
import Data.List
|
import Data.List
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
|
import qualified Control.Exception.Extensible as E
|
||||||
|
|
||||||
import qualified GitRepo as Git
|
import qualified GitRepo as Git
|
||||||
import qualified Locations
|
import qualified Locations
|
||||||
|
@ -23,7 +24,10 @@ import qualified GitAnnex
|
||||||
import qualified CmdLine
|
import qualified CmdLine
|
||||||
|
|
||||||
main :: IO (Counts, Int)
|
main :: IO (Counts, Int)
|
||||||
main = runVerboseTests $ TestList [quickchecks, toplevels]
|
main = do
|
||||||
|
r <- runVerboseTests $ TestList [quickchecks, toplevels]
|
||||||
|
cleanup tmpdir
|
||||||
|
return r
|
||||||
|
|
||||||
quickchecks :: Test
|
quickchecks :: Test
|
||||||
quickchecks = TestLabel "quickchecks" $ TestList
|
quickchecks = TestLabel "quickchecks" $ TestList
|
||||||
|
@ -38,12 +42,15 @@ quickchecks = TestLabel "quickchecks" $ TestList
|
||||||
|
|
||||||
toplevels :: Test
|
toplevels :: Test
|
||||||
toplevels = TestLabel "toplevel" $ TestList
|
toplevels = TestLabel "toplevel" $ TestList
|
||||||
|
-- test order matters, later tests may rely on state from earlier
|
||||||
[ test_init
|
[ test_init
|
||||||
, test_add
|
, test_add
|
||||||
|
, test_unannex
|
||||||
|
, test_drop
|
||||||
]
|
]
|
||||||
|
|
||||||
test_init :: Test
|
test_init :: Test
|
||||||
test_init = TestLabel "git-annex init" $ TestCase $ ingitrepo $ do
|
test_init = TestLabel "git-annex init" $ TestCase $ innewrepo $ do
|
||||||
git_annex "init" ["-q", reponame] @? "init failed"
|
git_annex "init" ["-q", reponame] @? "init failed"
|
||||||
e <- doesFileExist annexlog
|
e <- doesFileExist annexlog
|
||||||
unless e $
|
unless e $
|
||||||
|
@ -56,7 +63,7 @@ test_init = TestLabel "git-annex init" $ TestCase $ ingitrepo $ do
|
||||||
reponame = "test repo"
|
reponame = "test repo"
|
||||||
|
|
||||||
test_add :: Test
|
test_add :: Test
|
||||||
test_add = TestLabel "git-annex add" $ TestCase $ inannex $ do
|
test_add = TestLabel "git-annex add" $ TestCase $ inoldrepo $ do
|
||||||
writeFile file content
|
writeFile file content
|
||||||
git_annex "add" ["-q", "foo"] @? "add failed"
|
git_annex "add" ["-q", "foo"] @? "add failed"
|
||||||
s <- getSymbolicLinkStatus file
|
s <- getSymbolicLinkStatus file
|
||||||
|
@ -65,7 +72,7 @@ test_add = TestLabel "git-annex add" $ TestCase $ inannex $ do
|
||||||
c <- readFile file
|
c <- readFile file
|
||||||
unless (c == content) $
|
unless (c == content) $
|
||||||
assertFailure "file content changed during git-annex add"
|
assertFailure "file content changed during git-annex add"
|
||||||
r <- try (writeFile file $ content++"bar")
|
r <- try $ writeFile file $ content++"bar"
|
||||||
case r of
|
case r of
|
||||||
Left _ -> return () -- expected permission error
|
Left _ -> return () -- expected permission error
|
||||||
Right _ -> assertFailure "was able to modify annexed file content"
|
Right _ -> assertFailure "was able to modify annexed file content"
|
||||||
|
@ -73,47 +80,113 @@ test_add = TestLabel "git-annex add" $ TestCase $ inannex $ do
|
||||||
file = "foo"
|
file = "foo"
|
||||||
content = "foo file content"
|
content = "foo file content"
|
||||||
|
|
||||||
|
test_unannex :: Test
|
||||||
|
test_unannex = TestLabel "git-annex unannex" $ TestCase $ intmpcopyrepo $ do
|
||||||
|
git_annex "unannex" ["-q", "foo"] @? "unannex failed"
|
||||||
|
s <- getSymbolicLinkStatus "foo"
|
||||||
|
when (isSymbolicLink s) $
|
||||||
|
assertFailure "git-annex unannex left symlink"
|
||||||
|
|
||||||
|
test_drop :: Test
|
||||||
|
test_drop = TestLabel "git-annex drop" $ TestCase $ intmpcopyrepo $ do
|
||||||
|
r <- git_annex "drop" ["-q", "foo"]
|
||||||
|
(not r) @? "drop wrongly succeeded with no known copy of file"
|
||||||
|
checklink
|
||||||
|
git_annex "drop" ["-q", "--force", "foo"] @? "drop --force failed"
|
||||||
|
checklink
|
||||||
|
r' <- try $ readFile "foo"
|
||||||
|
case r' of
|
||||||
|
Left _ -> return () -- expected; dangling link
|
||||||
|
Right _ -> assertFailure "drop did not remove file content"
|
||||||
|
where
|
||||||
|
checklink = do
|
||||||
|
s <- getSymbolicLinkStatus "foo"
|
||||||
|
unless (isSymbolicLink s) $
|
||||||
|
assertFailure "git-annex drop killed symlink"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
git_annex :: String -> [String] -> IO Bool
|
git_annex :: String -> [String] -> IO Bool
|
||||||
git_annex command params = do
|
git_annex command params = do
|
||||||
gitrepo <- Git.repoFromCwd
|
-- catch all errors, including normally fatal errors
|
||||||
r <- try $
|
r <- E.try (run)::IO (Either E.SomeException ())
|
||||||
CmdLine.dispatch gitrepo (command:params)
|
|
||||||
GitAnnex.cmds GitAnnex.options GitAnnex.header
|
|
||||||
case r of
|
case r of
|
||||||
Right _ -> return True
|
Right _ -> return True
|
||||||
Left _ -> return False
|
Left _ -> return False
|
||||||
|
where
|
||||||
|
run = do
|
||||||
|
gitrepo <- Git.repoFromCwd
|
||||||
|
CmdLine.dispatch gitrepo (command:params)
|
||||||
|
GitAnnex.cmds GitAnnex.options GitAnnex.header
|
||||||
|
|
||||||
inannex :: Assertion -> Assertion
|
innewannex :: Assertion -> Assertion
|
||||||
inannex a = ingitrepo $ do
|
innewannex a = innewrepo $ do
|
||||||
git_annex "init" ["-q", reponame] @? "init failed"
|
git_annex "init" ["-q", reponame] @? "init failed"
|
||||||
a
|
a
|
||||||
where
|
where
|
||||||
reponame = "test repo"
|
reponame = "test repo"
|
||||||
|
|
||||||
ingitrepo :: Assertion -> Assertion
|
innewrepo :: Assertion -> Assertion
|
||||||
ingitrepo a = withgitrepo $ \r -> do
|
innewrepo a = withgitrepo $ \r -> indir r a
|
||||||
|
|
||||||
|
inoldrepo :: Assertion -> Assertion
|
||||||
|
inoldrepo = indir repodir
|
||||||
|
|
||||||
|
intmpcopyrepo :: Assertion -> Assertion
|
||||||
|
intmpcopyrepo a = withtmpcopyrepo $ \r -> indir r a
|
||||||
|
|
||||||
|
withtmpcopyrepo :: (FilePath -> Assertion) -> Assertion
|
||||||
|
withtmpcopyrepo = bracket (copyrepo repodir tmprepodir) cleanup
|
||||||
|
|
||||||
|
withgitrepo :: (FilePath -> Assertion) -> Assertion
|
||||||
|
withgitrepo = bracket (setuprepo repodir) return
|
||||||
|
|
||||||
|
indir :: FilePath -> Assertion -> Assertion
|
||||||
|
indir dir a = do
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
bracket_ (changeWorkingDirectory $ Git.workTree r)
|
bracket_ (changeWorkingDirectory $ dir)
|
||||||
(\_ -> changeWorkingDirectory cwd)
|
(\_ -> changeWorkingDirectory cwd)
|
||||||
a
|
a
|
||||||
|
|
||||||
withgitrepo :: (Git.Repo -> Assertion) -> Assertion
|
setuprepo :: FilePath -> IO FilePath
|
||||||
withgitrepo = bracket setup cleanup
|
setuprepo dir = do
|
||||||
where
|
cleanup dir
|
||||||
tmpdir = ".t"
|
ensuretmpdir
|
||||||
repodir = tmpdir ++ "/repo"
|
ok <- Utility.boolSystem "git" ["init", "-q", dir]
|
||||||
setup = do
|
unless ok $
|
||||||
cleanup True
|
assertFailure "git init failed"
|
||||||
createDirectory tmpdir
|
return dir
|
||||||
ok <- Utility.boolSystem "git" ["init", "-q", repodir]
|
|
||||||
unless ok $
|
copyrepo :: FilePath -> FilePath -> IO FilePath
|
||||||
assertFailure "git init failed"
|
copyrepo old new = do
|
||||||
return $ Git.repoFromPath repodir
|
cleanup new
|
||||||
cleanup _ = do
|
ensuretmpdir
|
||||||
e <- doesDirectoryExist tmpdir
|
ok <- Utility.boolSystem "cp" ["-pr", old, new]
|
||||||
when e $ do
|
unless ok $
|
||||||
-- git-annex prevents annexed file content
|
assertFailure "cp -pr failed"
|
||||||
-- from being removed with permissions
|
return new
|
||||||
-- bits; undo
|
|
||||||
_ <- Utility.boolSystem "chmod" ["+rw", "-R", tmpdir]
|
ensuretmpdir :: IO ()
|
||||||
removeDirectoryRecursive tmpdir
|
ensuretmpdir = do
|
||||||
|
e <- doesDirectoryExist tmpdir
|
||||||
|
unless e $
|
||||||
|
createDirectory tmpdir
|
||||||
|
|
||||||
|
cleanup :: FilePath -> IO ()
|
||||||
|
cleanup dir = do
|
||||||
|
e <- doesDirectoryExist dir
|
||||||
|
when e $ do
|
||||||
|
-- git-annex prevents annexed file content from being
|
||||||
|
-- removed via permissions bits; undo
|
||||||
|
_ <- Utility.boolSystem "chmod" ["+rw", "-R", dir]
|
||||||
|
removeDirectoryRecursive dir
|
||||||
|
|
||||||
|
tmpdir :: String
|
||||||
|
tmpdir = ".t"
|
||||||
|
|
||||||
|
repodir :: String
|
||||||
|
repodir = tmpdir ++ "/repo"
|
||||||
|
|
||||||
|
tmprepodir :: String
|
||||||
|
tmprepodir = tmpdir ++ "/tmprepo"
|
||||||
|
|
Loading…
Add table
Reference in a new issue