X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=t%2Ftest-rm.sh;h=00a5a8579ebef4fc639fdaecd69de71381e8c93f;hb=ae9cde2e3df85569bf76487a9528080926841db5;hp=737d9e9040859bad852e65073711a7ae35c9493f;hpb=7fdfad135587067d4fc0ff9fbc9d708497542b9c;p=bup.git diff --git a/t/test-rm.sh b/t/test-rm.sh index 737d9e9..00a5a85 100755 --- a/t/test-rm.sh +++ b/t/test-rm.sh @@ -2,8 +2,6 @@ . ./wvtest-bup.sh || exit $? . ./t/lib.sh || exit $? -set -o pipefail - top="$(WVPASS pwd)" || exit $? tmpdir="$(WVPASS wvmktempdir)" || exit $? @@ -16,23 +14,23 @@ compare-trees() { "$top/t/compare-trees" "$@"; } wv_matches_rx() { - caller_file=${BASH_SOURCE[0]} - caller_line=${BASH_LINENO[0]} - src="$caller_file:$caller_line" + local caller_file=${BASH_SOURCE[0]} + local caller_line=${BASH_LINENO[0]} + local src="$caller_file:$caller_line" if test $# -ne 2; then echo "! $src wv_matches_rx requires 2 arguments FAILED" 1>&2 return fi - str="$1" - rx="$2" - (echo "Matching:" - echo "$str" | sed 's/^\(.*\)/ \1/' - echo "Against:" - echo "$rx" | sed 's/^\(.*\)/ \1/') 1>&2 - if [[ "$str" =~ $rx ]]; then - echo "! $src regex matches ok" 1>&2 + local str="$1" + local rx="$2" + echo "Matching:" 1>&2 || exit $? + echo "$str" | sed 's/^\(.*\)/ \1/' 1>&2 || exit $? + echo "Against:" 1>&2 || exit $? + echo "$rx" | sed 's/^\(.*\)/ \1/' 1>&2 || exit $? + if [[ "$str" =~ ^${rx}$ ]]; then + echo "! $src regex matches ok" 1>&2 || exit $? else - echo "! $src regex doesn't match FAILED" 1>&2 + echo "! $src regex doesn't match FAILED" 1>&2 || exit $? fi } @@ -50,11 +48,14 @@ WVPASS "$top"/t/sync-tree bup/ bup-baseline/ # FIXME: test -n WVPASS bup tick # Make sure we always get the timestamp changes below WVPASS bup rm --unsafe /src -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ '\*deleting[ ]+logs/refs/heads/src -\*deleting[ ]+refs/heads/src +\*deleting[ ]+refs/heads/src( +\.d\.\.t\.\.\.[.]*[ ]+\./)? \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/ -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/' +\.d\.\.t\.\.\.[.]*[ ]+refs/heads/( +>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?' WVSTART "rm /foo (one of many)" @@ -69,11 +70,14 @@ WVPASS bup save -n src-3 src WVPASS "$top"/t/sync-tree bup/ bup-baseline/ WVPASS bup tick # Make sure we always get the timestamp changes below WVPASS bup rm --unsafe /src -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ "\*deleting[ ]+logs/refs/heads/src -\*deleting[ ]+refs/heads/src +\*deleting[ ]+refs/heads/src( +\.d\.\.t\.\.\.[.]*[ ]+\./)? \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/ -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/" +\.d\.\.t\.\.\.[.]*[ ]+refs/heads/( +>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?" WVSTART "rm /foo /bar (multiple of many)" @@ -88,13 +92,16 @@ WVPASS bup save -n src-5 src WVPASS "$top"/t/sync-tree bup/ bup-baseline/ WVPASS bup tick # Make sure we always get the timestamp changes below WVPASS bup rm --unsafe /src-2 /src-4 -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ -"\*deleting[ ]+logs/refs/heads/src-4 -\*deleting[ ]+logs/refs/heads/src-2 -\*deleting[ ]+refs/heads/src-4 +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ +"\*deleting[ ]+logs/refs/heads/src-2 +\*deleting[ ]+logs/refs/heads/src-4 \*deleting[ ]+refs/heads/src-2 +\*deleting[ ]+refs/heads/src-4( +\.d\.\.t\.\.\.[.]*[ ]+\./)? \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/ -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/" +\.d\.\.t\.\.\.[.]*[ ]+refs/heads/( +>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?" WVSTART "rm /foo /bar (all)" @@ -103,19 +110,22 @@ WVPASS mv bup-baseline bup WVPASS "$top"/t/sync-tree bup/ bup-baseline/ WVPASS bup tick # Make sure we always get the timestamp changes below WVPASS bup rm --unsafe /src /src-2 /src-3 /src-4 /src-5 -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ -"\*deleting[ ]+logs/refs/heads/src-5 -\*deleting[ ]+logs/refs/heads/src-4 -\*deleting[ ]+logs/refs/heads/src-3 +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ +"\*deleting[ ]+logs/refs/heads/src \*deleting[ ]+logs/refs/heads/src-2 -\*deleting[ ]+logs/refs/heads/src -\*deleting[ ]+refs/heads/src-5 -\*deleting[ ]+refs/heads/src-4 -\*deleting[ ]+refs/heads/src-3 -\*deleting[ ]+refs/heads/src-2 +\*deleting[ ]+logs/refs/heads/src-3 +\*deleting[ ]+logs/refs/heads/src-4 +\*deleting[ ]+logs/refs/heads/src-5 \*deleting[ ]+refs/heads/src +\*deleting[ ]+refs/heads/src-2 +\*deleting[ ]+refs/heads/src-3 +\*deleting[ ]+refs/heads/src-4 +\*deleting[ ]+refs/heads/src-5( +\.d\.\.t\.\.\.[.]*[ ]+\./)? \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/ -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/" +\.d\.\.t\.\.\.[.]*[ ]+refs/heads/( +>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?" WVSTART "rm /foo/bar (lone save - equivalent to rm /foo)" @@ -125,28 +135,34 @@ WVPASS mkdir src WVPASS echo twisty-maze > src/1 WVPASS bup index src WVPASS bup save -n src src -save1="$(WVPASS bup ls src | head -n 1)" || exit $? +WVPASS bup ls src > tmp-ls +save1="$(WVPASS head -n 1 tmp-ls)" || exit $? WVPASS "$top"/t/sync-tree bup/ bup-baseline/ WVPASS bup tick # Make sure we always get the timestamp changes below WVFAIL bup rm --unsafe /src/latest WVPASS bup rm --unsafe /src/"$save1" -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ "\*deleting[ ]+logs/refs/heads/src -\*deleting[ ]+refs/heads/src +\*deleting[ ]+refs/heads/src( +\.d\.\.t\.\.\.[.]*[ ]+\./)? \.d\.\.t\.\.\.[.]*[ ]+logs/refs/heads/ -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/" +\.d\.\.t\.\.\.[.]*[ ]+refs/heads/( +>f\+\+\+\+\+\+\+\+\+[ ]+packed-refs)?" verify-changes-caused-by-rewriting-save() -( - local before="$1" - local after="$2" - local tmpdir="$(WVPASS wvmktempdir)" || exit $? - (WVPASS cd "$before" && WVPASS find . | WVPASS sort) > "$tmpdir/before" - (WVPASS cd "$after" && WVPASS find . | WVPASS sort) > "$tmpdir/after" +{ + local before="$1" after="$2" tmpdir + tmpdir="$(WVPASS wvmktempdir)" || exit $? + (WVPASS cd "$before" && WVPASS find . | WVPASS sort) \ + > "$tmpdir/before" || exit $? + (WVPASS cd "$after" && WVPASS find . | WVPASS sort) \ + > "$tmpdir/after" || exit $? + local new_paths new_idx new_pack observed new_paths="$(WVPASS comm -13 "$tmpdir/before" "$tmpdir/after")" || exit $? - new_idx="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.idx$' | cut -b 3-)" - new_pack="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.pack$' | cut -b 3-)" + new_idx="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.idx$' | cut -b 3-)" || exit $? + new_pack="$(echo "$new_paths" | WVPASS grep -E '^\./objects/pack/pack-.*\.pack$' | cut -b 3-)" || exit $? wv_matches_rx "$(compare-trees "$after/" "$before/")" \ ">fcst\.\.\.[.]*[ ]+logs/refs/heads/src \.d\.\.t\.\.\.[.]*[ ]+objects/ @@ -157,7 +173,7 @@ verify-changes-caused-by-rewriting-save() \.d\.\.t\.\.\.[.]*[ ]+refs/heads/ >fc\.t\.\.\.[.]*[ ]+refs/heads/src" WVPASS rm -rf "$tmpdir" -) +} commit-hash-n() { @@ -199,10 +215,12 @@ WVPASS bup tick # Make sure we always get the timestamp changes below WVSTART "rm /foo/BAR (first of many)" WVPASS "$top"/t/sync-tree bup-baseline/ bup/ -victim="$(WVPASS bup ls src | head -n 1)" || exit $? +WVPASS bup ls src > tmp-ls +victim="$(WVPASS head -n 1 tmp-ls)" || exit $? WVPASS bup rm --unsafe /src/"$victim" verify-changes-caused-by-rewriting-save bup-baseline bup -WVPASSEQ 2 $(git rev-list src | wc -l) +observed=$(WVPASS git rev-list src | WVPASS wc -l) || exit $? +WVPASSEQ 2 $observed WVPASSEQ "$(rm-safe-cinfo 1 bup src)" "$(rm-safe-cinfo 2 bup-baseline src)" WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)" @@ -212,7 +230,8 @@ WVPASS "$top"/t/sync-tree bup-baseline/ bup/ victim="$(WVPASS bup ls src | tail -n +2 | head -n 1)" || exit $? WVPASS bup rm --unsafe /src/"$victim" verify-changes-caused-by-rewriting-save bup-baseline bup -WVPASSEQ 2 $(git rev-list src | wc -l) +observed=$(git rev-list src | wc -l) || exit $? +WVPASSEQ 2 $observed WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)" WVPASSEQ "$(rm-safe-cinfo 2 bup src)" "$(rm-safe-cinfo 3 bup-baseline src)" @@ -221,11 +240,13 @@ WVSTART "rm /foo/BAR (last of many)" WVPASS "$top"/t/sync-tree bup-baseline/ bup/ victim="$(WVPASS bup ls src | tail -n 2 | head -n 1)" || exit $? WVPASS bup rm --unsafe -vv /src/"$victim" -wv_matches_rx "$(compare-trees bup/ bup-baseline/)" \ -">fcst\.\.\.[.]*[ ]+logs/refs/heads/src -\.d\.\.t\.\.\.[.]*[ ]+refs/heads/ ->fc\.t\.\.\.[.]*[ ]+refs/heads/src" -WVPASSEQ 2 $(git rev-list src | wc -l) +observed="$(compare-trees bup/ bup-baseline/ | LC_ALL=C sort)" || exit $? +wv_matches_rx "$observed" \ +"\.d\.\.t\.\.\.[.]*[ ]+refs/heads/ +>fc\.t\.\.\.[.]*[ ]+refs/heads/src +>fcst\.\.\.[.]*[ ]+logs/refs/heads/src" +observed=$(git rev-list src | wc -l) || exit $? +WVPASSEQ 2 $observed WVPASSEQ "$(commit-hash-n 1 bup src)" "$(commit-hash-n 1 bup-baseline src)" WVPASSEQ "$(commit-hash-n 2 bup src)" "$(commit-hash-n 2 bup-baseline src)"