[PATCH 4/4] Improve save/restore test coverage, particularly wrt invocations

0 views
Skip to first unread message

Rob Browning

unread,
May 7, 2026, 6:29:15 PMMay 7
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---

Pushed to main.

lib/bup/cmd/restore.py | 11 ++++-----
lib/bup/cmd/save.py | 2 +-
test/ext/test-save-restore | 49 ++++++++++++++++++++++++++++++++------
3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/lib/bup/cmd/restore.py b/lib/bup/cmd/restore.py
index 0c971f23..797a7a07 100644
--- a/lib/bup/cmd/restore.py
+++ b/lib/bup/cmd/restore.py
@@ -9,7 +9,7 @@ from bup.compat import argv_bytes, fsencode
from bup.helpers import (add_error, chunkyreader,
mkdirp, parse_rx_excludes, progress, qprogress,
should_rx_exclude_path)
-from bup.io import byte_stream
+from bup.io import byte_stream, path_msg
from bup.repo import main_repo_location, repo_for_location


@@ -230,7 +230,7 @@ def main(argv):
o.fatal)

if not extra:
- o.fatal('must specify at least one filename to restore')
+ o.fatal('must specify at least one path to restore')

exclude_rxs = parse_rx_excludes(flags, o.fatal)

@@ -268,9 +268,8 @@ def main(argv):
path_name = os.path.split(path)[1]
leaf_name, leaf_item = resolved[-1]
if not leaf_item:
- add_error('error: cannot access %r in %r'
- % (b'/'.join(name for name, item in resolved),
- path))
+ res_msg = path_msg(b'/'.join(name for name, item in resolved))
+ add_error(f'error: cannot access {res_msg} in {path_msg(path)}')
continue
if not path_name or path_name == b'.':
# Source is /foo/what/ever/ or /foo/what/ever/. -- extract
@@ -279,7 +278,7 @@ def main(argv):
# metadata to the current directory.
treeish = vfs.item_mode(leaf_item)
if not treeish:
- add_error('%r cannot be restored as a directory' % path)
+ add_error(f'{path_msg(path)} cannot be restored as a directory')
else:
items = vfs.contents(src, leaf_item, want_meta=True)
dot, leaf_item = next(items, None)
diff --git a/lib/bup/cmd/save.py b/lib/bup/cmd/save.py
index 79361a15..6cecdbda 100644
--- a/lib/bup/cmd/save.py
+++ b/lib/bup/cmd/save.py
@@ -131,7 +131,7 @@ def opts_from_cmdline(argv):
opt.grafts = grafts

if opt.name and not valid_save_name(opt.name):
- o.fatal("'%s' is not a valid branch name" % path_msg(opt.name))
+ o.fatal(f'{path_msg(opt.name)} is not a valid branch name')

return opt, o

diff --git a/test/ext/test-save-restore b/test/ext/test-save-restore
index 3b781e76..15f3c9d8 100755
--- a/test/ext/test-save-restore
+++ b/test/ext/test-save-restore
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
-. wvtest.sh
-. wvtest-bup.sh
-. dev/lib.sh
+. ./wvtest.sh || exit $?
+. ./wvtest-bup.sh || exit $?
+. ./dev/lib.sh || exlt $?
+. ./test/lib/btl.sh || exit $?

set -o pipefail

@@ -38,10 +39,44 @@ WVPASS mkdir $D/d $D/d/e
WVPASS bup random 512 >$D/f
WVPASS touch $D/d/z
WVPASS touch $D/d/z
-WVPASS bup index $D
+(cd "$D/d" && WVPASS ln -s z z-link)
+WVPASS bup index -vv $D
WVPASS bup save -t $D


+WVSTART 'save (argument validation)'
+WVFAIL err-to log bup save
+WVPASS grep -E '^error: use one or more of -t, -c, -n' log
+WVFAIL err-to log bup save -n main
+WVPASS grep -E '^error: no filenames given' log
+WVFAIL err-to log bup save -n "x y" src
+WVPASS grep -E "^error: 'x y' is not a valid branch name" log
+WVFAIL err-to log bup save -n main --date never src
+WVPASS grep -E '^error: --date never is not a float' log
+WVFAIL err-to log bup save -n main --smaller nope src
+WVPASS grep -E "^error: invalid --smaller \(can't parse 'nope' as a number\)" log
+WVFAIL err-to log bup save -n main --bwlimit nope src
+WVPASS grep -E "^error: invalid --bwlimit \(can't parse 'nope' as a number\)" log
+WVFAIL err-to log bup save -n main --strip-path x --strip src
+WVPASS grep -E '^error: --strip is incompatible with --strip-path' log
+WVFAIL err-to log bup save -n main --graft x=y --strip src
+WVPASS grep -E '^error: --strip is incompatible with --graft' log
+WVFAIL err-to log bup save -n main --graft x=y --strip-path x src
+WVPASS grep -E '^error: --strip-path is incompatible with --graft' log
+WVFAIL err-to log bup save -n main --graft x/y src
+WVPASS grep -E '^error: a graft point must be of the form old_path=new_path' log
+
+WVPASS git --git-dir bup config set bup.split.trees 42
+WVFAIL err-to log bup save -n main /dev/null
+WVPASS grep -E '^error: got invalid bool value 42 from git config' log
+WVPASS git --git-dir bup config unset bup.split.trees
+
+
+WVSTART 'restore (argument validation)'
+WVFAIL err-to log bup restore -C /dev/null
+WVPASS grep -E '^error: must specify at least one path to restore' log
+
+
WVSTART "restore"
WVPASS force-delete buprestore.tmp
WVFAIL bup restore boink
@@ -51,7 +86,7 @@ WVPASS bup save -n main /
WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D"
WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
WVPASS force-delete buprestore.tmp
-WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D/"
+WVPASS bup restore -vv -C buprestore.tmp "/main/latest/$tmpdir/$D/"
WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
WVPASS diff -ur $D/ buprestore.tmp/
WVPASS force-delete buprestore.tmp
@@ -143,8 +178,8 @@ WVSTART "save disjoint top-level directories"
WVPASS date > "$tmpdir2/2"

export BUP_DIR="$tmpdir/bup"
- WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
-
+ WVPASS test -d bup
+ WVPASS rm -rf bup
WVPASS bup init
WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
--
2.47.3

Reply all
Reply to author
Forward
0 new messages