[PATCH 3/8] test-cat-file: test more invalid invocations

0 views
Skip to first unread message

Rob Browning

unread,
Mar 27, 2026, 7:09:04 PM (12 days ago) Mar 27
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
lib/bup/cmd/cat_file.py | 12 ++++++------
test/ext/test-cat-file | 27 ++++++++++++++++++++++-----
2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/lib/bup/cmd/cat_file.py b/lib/bup/cmd/cat_file.py
index 0feec430..6e9c5f5a 100644
--- a/lib/bup/cmd/cat_file.py
+++ b/lib/bup/cmd/cat_file.py
@@ -5,7 +5,7 @@ import re, stat, sys
from bup import options, git, vfs
from bup.compat import argv_bytes
from bup.helpers import EXIT_FAILURE, chunkyreader, log
-from bup.io import byte_stream
+from bup.io import byte_stream, path_msg as pm
from bup.repo import LocalRepo

optspec = """
@@ -31,14 +31,14 @@ def main(argv):
target = argv_bytes(extra[0])

if not re.match(br'/*[^/]+/[^/]+', target):
- o.fatal("path %r doesn't include a branch and revision" % target)
+ o.fatal(f"path {pm(target)} doesn't include a branch and revision")

with LocalRepo() as repo:
resolved = vfs.resolve(repo, target, follow=False)
leaf_item = resolved[-1][1]
if not leaf_item:
- log('error: cannot access %r in %r\n'
- % (b'/'.join(name for name, item in resolved), target))
+ res_path = b'/'.join(name for name, item in resolved)
+ log(f'error: cannot access {pm(res_path)} in {pm(target)}\n')
sys.exit(EXIT_FAILURE)

mode = vfs.item_mode(leaf_item)
@@ -48,7 +48,7 @@ def main(argv):

if opt.bupm:
if not stat.S_ISDIR(mode):
- o.fatal('%r is not a directory' % target)
+ o.fatal(f'{pm(target)} is not a directory')
_, bupm_oid = vfs.tree_data_and_bupm(repo, leaf_item.oid)
if bupm_oid:
with vfs.tree_data_reader(repo, bupm_oid) as meta_stream:
@@ -62,4 +62,4 @@ def main(argv):
for b in chunkyreader(f):
out.write(b)
else:
- o.fatal('%r is not a plain file' % target)
+ o.fatal(f'{pm(target)} is not a plain file')
diff --git a/test/ext/test-cat-file b/test/ext/test-cat-file
index 70757ce7..1fa344dc 100755
--- a/test/ext/test-cat-file
+++ b/test/ext/test-cat-file
@@ -18,21 +18,38 @@ WVSTART "cat-file"
WVPASS mkdir src
WVPASS date > src/foo
WVPASS bup index src
-WVPASS bup save -n src src
-WVPASS bup cat-file "src/latest/$(pwd)/src/foo" > cat-foo
+WVPASS bup save -n src --strip-path "$(pwd)" src
+
+WVSTART 'invalid invocations'
+WVFAIL eval 'bup cat-file 2> >(tee log)'
+WVPASS grep -F 'must specify a target' log
+WVFAIL eval 'bup cat-file x y 2> >(tee log)'
+WVPASS grep -F 'only one target file allowed' log
+WVFAIL eval 'bup cat-file --meta --bupm x 2> >(tee log)'
+WVPASS grep -F -e '--meta and --bupm are incompatible' log
+WVFAIL eval 'bup cat-file x 2> >(tee log)'
+WVPASS grep -F -e "path x doesn't include a branch and revision" log
+WVEXPRC 2 eval 'bup cat-file x/y 2> >(tee log)'
+WVPASS grep -F 'cannot access /x in x/y' log
+WVFAIL eval 'bup cat-file --bupm src/latest/src/foo 2> >(tee log)'
+WVPASS grep -F 'src/latest/src/foo is not a directory' log
+WVFAIL eval 'bup cat-file src/latest/src/ 2> >(tee log)'
+WVPASS grep -F 'src/latest/src/ is not a plain file' log
+
+WVPASS bup cat-file "src/latest/src/foo" > cat-foo
WVPASS diff -u src/foo cat-foo

WVSTART "cat-file --meta"
WVPASS bup meta --create --no-paths src/foo > src-foo.meta
-WVPASS bup cat-file --meta "src/latest/$(pwd)/src/foo" > cat-foo.meta
+WVPASS bup cat-file --meta "src/latest/src/foo" > cat-foo.meta

WVPASS bup meta -tvvf src-foo.meta | WVPASS grep -vE '^atime: ' > src-foo.list
WVPASS bup meta -tvvf cat-foo.meta | WVPASS grep -vE '^atime: ' > cat-foo.list
WVPASS diff -u src-foo.list cat-foo.list

WVSTART "cat-file --bupm"
-WVPASS bup cat-file --bupm "src/latest/$(pwd)/src/" > bup-cat-bupm
-src_hash=$(WVPASS bup ls -s "src/latest/$(pwd)" | cut -d' ' -f 1) || exit $?
+WVPASS bup cat-file --bupm "src/latest/src/" > bup-cat-bupm
+src_hash=$(WVPASS bup ls -s "src/latest/" | cut -d' ' -f 1) || exit $?
bupm_hash=$(WVPASS git ls-tree "$src_hash" | grep -F .bupm | cut -d' ' -f 3) \
|| exit $?
bupm_hash=$(WVPASS echo "$bupm_hash" | cut -d' ' -f 1) || exit $?
--
2.47.3

Reply all
Reply to author
Forward
0 new messages