test if magic library works

(When built with it.)

I saw John Thorvald Wodder II doing this in
https://github.com/datalad/datalad-extensions/blob/master/.github/workflows/build-git-annex-windows.yaml
and it seemed like a good idea.

John used an empty file for the binary file, but I think it's
slightly suprising file picks that mime type for it, so opted to instead
use something less ambiguous.
This commit is contained in:
Joey Hess 2020-10-27 13:39:58 -04:00
parent 64e7bac810
commit 37054e0946
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

23
Test.hs
View file

@ -298,6 +298,7 @@ unitTests note = testGroup ("Unit Tests " ++ note)
, testCase "export_import_subdir" test_export_import_subdir
, testCase "shared clone" test_shared_clone
, testCase "log" test_log
, testCase "magic" test_magic
, testCase "import" test_import
, testCase "reinject" test_reinject
, testCase "unannex (no copy)" test_unannex_nocopy
@ -446,6 +447,28 @@ test_log :: Assertion
test_log = intmpclonerepo $ do
git_annex "log" [annexedfile] @? "log failed"
test_magic :: Assertion
test_magic = intmpclonerepo $ do
#ifdef WITH_MAGICMIME
boolSystem "git"
[ Param "config"
, Param "annex.largefiles"
, Param "mimeencoding=binary"
] @? "git config annex.largefiles failed"
writeFile "binary" "\127"
writeFile "text" "test\n"
git_annex "add" ["binary", "text"]
@? "git-annex add failed with mimeencoding in largefiles"
git_annex "sync" []
@? "git-annex sync failed"
(isJust <$> annexeval (Annex.CatFile.catKeyFile (encodeBS "binary")))
@? "binary file not added to annex despite mimeencoding config"
(isNothing <$> annexeval (Annex.CatFile.catKeyFile (encodeBS "text")))
@? "non-binary file got added to annex despite mimeencoding config"
#else
return ()
#endif
test_import :: Assertion
test_import = intmpclonerepo $ Utility.Tmp.Dir.withTmpDir "importtest" $ \importdir -> do
(toimport1, importf1, imported1) <- mktoimport importdir "import1"