fix reversion in info, and add test case

info: Fix reversion in last release involving handling of unsupported input
by continuing to handle any other inputs, before exiting nonzero at the
end.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2023-02-20 14:31:24 -04:00
parent 4199c457e2
commit 16d3097a08
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 44 additions and 18 deletions

View file

@ -6,6 +6,9 @@ git-annex (10.20230215) UNRELEASED; urgency=medium
* view: Fix a reversion in 10.20230214 that omitted a file from a view
when the file had no metadata set, but the view only used path fields.
* stack.yaml: Update to lts-19.33 and aws-0.24
* info: Fix reversion in last release involving handling of unsupported
input by continuing to handle any other inputs, before exiting nonzero
at the end.
-- Joey Hess <id@joeyh.name> Tue, 14 Feb 2023 14:11:11 -0400

View file

@ -182,7 +182,9 @@ itemInfo o (si, p) = ifM (isdir p)
noInfo :: String -> SeekInput -> String -> Annex ()
noInfo s si msg = do
showStart "info" (encodeBS s) si
giveup msg
showNote msg
showEndFail
Annex.incError
dirInfo :: InfoOptions -> FilePath -> SeekInput -> Annex ()
dirInfo o dir si = showCustom (unwords ["info", dir]) si $ do

16
Test.hs
View file

@ -1,6 +1,6 @@
{- git-annex test suite
-
- Copyright 2010-2022 oey Hess <id@joeyh.name>
- Copyright 2010-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -1163,6 +1163,12 @@ test_info :: Assertion
test_info = intmpclonerepo $ do
isjson
readonly_query isjson
-- When presented with an input that it does not support,
-- info does not stop but processess subsequent inputs too.
git_annex'' (const True)
(sha1annexedfile `isInfixOf`)
"info"
[annexedfile, "dnefile", sha1annexedfile] Nothing "info"
where
isjson = do
json <- BU8.fromString <$> git_annex_output "info" ["--json"]
@ -1682,7 +1688,7 @@ test_uninit = intmpclonerepo $ do
git_annex "get" [] "get"
annexed_present annexedfile
-- any exit status is accepted; does abnormal exit
git_annex'' (const True) "uninit" [] Nothing "uninit"
git_annex'' (const True) (const True) "uninit" [] Nothing "uninit"
checkregularfile annexedfile
doesDirectoryExist ".git" @? ".git vanished in uninit"
@ -1797,8 +1803,8 @@ test_borg_remote = when BuildInfo.borg $ do
borgdirparent <- fromRawFilePath <$> (absPath . toRawFilePath =<< tmprepodir)
let borgdir = borgdirparent </> "borgrepo"
intmpclonerepo $ do
testProcess "borg" ["init", borgdir, "-e", "none"] Nothing (== True) "borg init"
testProcess "borg" ["create", borgdir++"::backup1", "."] Nothing (== True) "borg create"
testProcess "borg" ["init", borgdir, "-e", "none"] Nothing (== True) (const True) "borg init"
testProcess "borg" ["create", borgdir++"::backup1", "."] Nothing (== True) (const True) "borg create"
git_annex "initremote" (words $ "borg type=borg borgrepo="++borgdir) "initremote"
git_annex "sync" ["borg"] "sync borg"
@ -1808,7 +1814,7 @@ test_borg_remote = when BuildInfo.borg $ do
annexed_present annexedfile
git_annex_expectoutput "find" ["--in=borg"] []
testProcess "borg" ["create", borgdir++"::backup2", "."] Nothing (== True) "borg create"
testProcess "borg" ["create", borgdir++"::backup2", "."] Nothing (== True) (const True) "borg create"
git_annex "sync" ["borg"] "sync borg after getting file"
git_annex_expectoutput "find" ["--in=borg"] [annexedfile]

View file

@ -1,6 +1,6 @@
{- git-annex test suite framework
-
- Copyright 2010-2022 Joey Hess <id@joeyh.name>
- Copyright 2010-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -67,27 +67,29 @@ import qualified Command.Uninit
-- displayed if the process does not return the expected value.
--
-- In debug mode, the output is allowed to pass through.
testProcess :: String -> [String] -> Maybe [(String, String)] -> (Bool -> Bool) -> String -> Assertion
testProcess command params environ expectedret faildesc = do
-- So the output does not get checked in debug mode.
testProcess :: String -> [String] -> Maybe [(String, String)] -> (Bool -> Bool) -> (String -> Bool) -> String -> Assertion
testProcess command params environ expectedret expectedtranscript faildesc = do
let p = (proc command params) { env = environ }
debug <- testDebug . testOptions <$> getTestMode
if debug
then do
ret <- withCreateProcess p $ \_ _ _ pid ->
waitForProcess pid
(expectedret (ret == ExitSuccess)) @? (faildesc ++ " failed")
(expectedret (ret == ExitSuccess)) @? (faildesc ++ " failed with unexpected exit code")
else do
(transcript, ret) <- Utility.Process.Transcript.processTranscript' p Nothing
(expectedret ret) @? (faildesc ++ " failed (transcript follows)\n" ++ transcript)
(expectedret ret) @? (faildesc ++ " failed with unexpected exit code (transcript follows)\n" ++ transcript)
(expectedtranscript transcript) @? (faildesc ++ " failed with unexpected output (transcript follows)\n" ++ transcript)
-- Run git. (Do not use to run git-annex as the one being tested
-- may not be in path.)
git :: String -> [String] -> String -> Assertion
git command params = testProcess "git" (command:params) Nothing (== True)
git command params = testProcess "git" (command:params) Nothing (== True) (const True)
-- For when git is expected to fail.
git_shouldfail :: String -> [String] -> String -> Assertion
git_shouldfail command params = testProcess "git" (command:params) Nothing (== False)
git_shouldfail command params = testProcess "git" (command:params) Nothing (== False) (const True)
-- Run git-annex.
git_annex :: String -> [String] -> String -> Assertion
@ -95,23 +97,23 @@ git_annex command params faildesc = git_annex' command params Nothing faildesc
-- Runs git-annex with some environment.
git_annex' :: String -> [String] -> Maybe [(String, String)] -> String -> Assertion
git_annex' = git_annex'' (== True)
git_annex' = git_annex'' (== True) (const True)
-- For when git-annex is expected to fail.
git_annex_shouldfail :: String -> [String] -> String -> Assertion
git_annex_shouldfail command params faildesc = git_annex_shouldfail' command params Nothing faildesc
git_annex_shouldfail' :: String -> [String] -> Maybe [(String, String)] -> String -> Assertion
git_annex_shouldfail' = git_annex'' (== False)
git_annex_shouldfail' = git_annex'' (== False) (const True)
git_annex'' :: (Bool -> Bool) -> String -> [String] -> Maybe [(String, String)] -> String -> Assertion
git_annex'' expectedret command params environ faildesc = do
git_annex'' :: (Bool -> Bool) -> (String -> Bool) -> String -> [String] -> Maybe [(String, String)] -> String -> Assertion
git_annex'' expectedret expectedtranscript command params environ faildesc = do
pp <- Annex.Path.programPath
debug <- testDebug . testOptions <$> getTestMode
let params' = if debug
then "--debug":params
else params
testProcess pp (command:params') environ expectedret faildesc
testProcess pp (command:params') environ expectedret expectedtranscript faildesc
{- Runs git-annex and returns its standard output. -}
git_annex_output :: String -> [String] -> IO String

View file

@ -55,3 +55,5 @@ IMHO prior behavior is "more correct" and we rely on it in datalad - get respons
[[!meta author=yoh]]
[[!tag projects/datalad]]
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,11 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2023-02-20T17:56:39Z"
content="""
Fixed this. Note that with the fix, it will still exit nonzero at the end
when given a path that does not exist, but it will first process the other
inputs.
Also I've added a test case.
"""]]