From 59fbff5cfdb597fba2b9d90d68ddb23ed4fd2174 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Wed, 8 Aug 2012 22:38:33 -0500 Subject: [PATCH] Improved unit-tests Refactor the old-style make-replay-repo/check-replay-repo scripts into the new test framework, for easier Makefile-based testing. --- .gitignore | 3 +- tests/diff-repo.sh | 61 ++++++++++++++++++++++++++++++++++++ tests/t0000-basic.sh | 15 +++++++++ tests/t0001-diff-repo.sh | 53 +++++++++++++++++++++++++++++++ tests/t0100-replay-all.sh | 34 ++++++++++++++++++++ tests/t0101-replay-trunk.sh | 35 +++++++++++++++++++++ tests/t0102-replay-branch.sh | 36 +++++++++++++++++++++ 7 files changed, 236 insertions(+), 1 deletion(-) create mode 100755 tests/diff-repo.sh create mode 100755 tests/t0000-basic.sh create mode 100755 tests/t0001-diff-repo.sh create mode 100755 tests/t0100-replay-all.sh create mode 100755 tests/t0101-replay-trunk.sh create mode 100755 tests/t0102-replay-branch.sh diff --git a/.gitignore b/.gitignore index 387da60..8a51a1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.pyc *.pyo +tests/_file* tests/_repo* tests/_wc* -tests/_dup_wc +tests/test-results *.swp diff --git a/tests/diff-repo.sh b/tests/diff-repo.sh new file mode 100755 index 0000000..75d9e47 --- /dev/null +++ b/tests/diff-repo.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# Compare the contents of two different SVN repositories. + +[ $# -eq 0 ] && { + echo "usage: $0 [repo1] [repo2]" + exit 1 +} + +PWD=$(pwd) +WC1="$PWD/_wc_tmp1" +WC2="$PWD/_wc_tmp2" +found_diff=0 + +# Create a working-copy for the reference repo +# Note: We assume that the replay working-copy ("_wc_target") still exists from t*.sh +rm -rf "$WC1" "$WC2" +svn co -q $1 "$WC1" +svn co -q $2 "$WC2" + +# Check if the final list of files is the same +cd "$WC1" && FILES1=$(find . -type f | grep -v "\.svn" | sed 's/^\.\///') && cd "$PWD" +cd "$WC2" && FILES2=$(find . -type f | grep -v "\.svn" | sed 's/^\.\///') && cd "$PWD" +if [ "$FILES1" != "$FILES2" ]; then + echo "Found file-list differences:" + echo "$FILES1" > _files1.txt + echo "$FILES2" > _files2.txt + echo "<<< @A" + echo ">>> @B" + diff _files1.txt _files2.txt + rm _files1.txt _files2.txt + found_diff=1 +fi + +# Check if the final file-contents is the same +cd "$WC1" +FILES=$(find . -type f | grep -v "\.svn") +cd "$PWD" +while read file; do + fname=$(echo "$file" | sed 's/^\.\///') + FILE1="$WC1/$fname" + FILE2="$WC2/$fname" + if [ -f "$FILE2" ]; then + chksum1=$(md5sum "$FILE1" | cut -c1-32) + chksum2=$(md5sum "$FILE2" | cut -c1-32) + if [ "$chksum1" != "$chksum2" ]; then + echo "Checksum mismatch: $fname" + echo "<<< @A $fname $chksum1" + echo ">>> @B $fname $chksum2" + found_diff=1 + fi + else + found_diff=1 + fi +done < <(echo "$FILES") + +# Clean-up +rm -rf "$WC1" "$WC2" + +# If we found any differences, exit with an error-code +[ "$found_diff" -eq 1 ] && exit 1 +exit 0 diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh new file mode 100755 index 0000000..ab82c0c --- /dev/null +++ b/tests/t0000-basic.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +test_description='Test unit-test primitives +' +. ./test-lib.sh + +################################################################ + +test_expect_success 'test success' ' + : +' +test_expect_failure 'test failure' ' + false +' +test_done diff --git a/tests/t0001-diff-repo.sh b/tests/t0001-diff-repo.sh new file mode 100755 index 0000000..547772d --- /dev/null +++ b/tests/t0001-diff-repo.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +test_description='Test diff-repo.sh +' +. ./test-lib.sh + +PWD=$(pwd) +PWDURL=$(echo "file://$PWD" | sed 's/\ /%20/g') +REPO="$PWD/_repo_tmp" +REPO2="$PWD/_repo_tmp2" +REPOURL="$PWDURL/_repo_tmp" +REPO2URL="$PWDURL/_repo_tmp2" +WC="$PWD/_wc_tmp" + +rm -rf "$REPO" "$REPO2" "$WC" + +# Create dummy repo +svnadmin create "$REPO" +svn mkdir -q -m "Add /trunk" $REPOURL/trunk +svn co -q $REPOURL/trunk "$WC" +mkdir -p "$WC/Module/ProjectA" +echo "Module/ProjectA/FileA1.txt (Initial)" >> "$WC/Module/ProjectA/FileA1.txt" +echo "Module/ProjectA/FileA2.txt (Initial)" >> "$WC/Module/ProjectA/FileA2.txt" +svn -q add "$WC/Module" +svn ci -q -m "Initial population" "$WC" + +test_expect_success \ + "diff-repo: REPO1/trunk == REPO1/trunk" \ + "./diff-repo.sh $REPOURL/trunk $REPOURL/trunk" + +test_expect_failure \ + "diff-repo: REPO1/trunk != REPO1/trunk/Module" \ + "./diff-repo.sh $REPOURL/trunk $REPOURL/trunk/Module" + +rsync -aq $PWD/_repo_tmp/ $PWD/_repo_tmp2 + +test_expect_success \ + "diff-repo: REPO1/trunk == REPO2/trunk" \ + "./diff-repo.sh $REPOURL/trunk $REPO2URL/trunk" + +rm -rf "$WC" +svn co -q $REPO2URL/trunk "$WC" +echo "Module/ProjectA/FileA1.txt (Edit)" >> "$WC/Module/ProjectA/FileA1.txt" +echo "Module/ProjectA/FileA3.txt (New File)" >> "$WC/Module/ProjectA/FileA3.txt" +svn -q add "$WC/Module/ProjectA/FileA3.txt" +svn ci -q -m "Second commit" "$WC" + +test_expect_failure \ + "diff-repo: REPO1/trunk == REPO2/trunk" \ + "./diff-repo.sh $REPOURL/trunk $REPO2URL/trunk" + +rm -rf "$REPO" "$REPO2" "$WC" +test_done diff --git a/tests/t0100-replay-all.sh b/tests/t0100-replay-all.sh new file mode 100755 index 0000000..e822c09 --- /dev/null +++ b/tests/t0100-replay-all.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +test_description='Use svnreplay to create a full copy of the ref repo +' +. ./test-lib.sh + +SVNREPLAY="../svnreplay.py" +PWD=$(pwd) +PWDURL=$(echo "file://$PWD" | sed 's/\ /%20/g') +REPO="$PWD/_repo_replay" +REPOURL=$(echo "file://$REPO" | sed 's/\ /%20/g') + +# Clean-up +rm -rf "$REPO" _wc_target + +# Init repo +svnadmin create "$REPO" +# Add pre-revprop-change hook script +cp ../hook-examples/pre-revprop-change_example.txt "$REPO/hooks/pre-revprop-change" +chmod 755 "$REPO/hooks/pre-revprop-change" + + +################################################################ +OFFSET="/" + +test_expect_success \ + "svnreplay _repo_ref$OFFSET _repo_replay$OFFSET" \ + "$SVNREPLAY -a \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_expect_success \ + "diff-repo _repo_ref$OFFSET _repo_replay$OFFSET" \ + "./diff-repo.sh \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_done diff --git a/tests/t0101-replay-trunk.sh b/tests/t0101-replay-trunk.sh new file mode 100755 index 0000000..5d877bc --- /dev/null +++ b/tests/t0101-replay-trunk.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +test_description='Use svnreplay to create a filtered repo with only /trunk history +' +. ./test-lib.sh + +SVNREPLAY="../svnreplay.py" +PWD=$(pwd) +PWDURL=$(echo "file://$PWD" | sed 's/\ /%20/g') +REPO="$PWD/_repo_replay" +REPOURL=$(echo "file://$REPO" | sed 's/\ /%20/g') + +# Clean-up +rm -rf "$REPO" _wc_target + +# Init repo +svnadmin create "$REPO" +# Add pre-revprop-change hook script +cp ../hook-examples/pre-revprop-change_example.txt "$REPO/hooks/pre-revprop-change" +chmod 755 "$REPO/hooks/pre-revprop-change" + + +################################################################ +OFFSET="/trunk" +svn mkdir -q -m "Add $OFFSET" $REPOURL$OFFSET + +test_expect_success \ + "svnreplay _repo_ref$OFFSET _repo_replay$OFFSET" \ + "$SVNREPLAY -a \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_expect_success \ + "diff-repo _repo_ref$OFFSET _repo_replay$OFFSET" \ + "./diff-repo.sh \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_done diff --git a/tests/t0102-replay-branch.sh b/tests/t0102-replay-branch.sh new file mode 100755 index 0000000..4ab2ccf --- /dev/null +++ b/tests/t0102-replay-branch.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +test_description='Use svnreplay to create a filtered repo with only /trunk/Module2/ProjectB history +' +. ./test-lib.sh + +SVNREPLAY="../svnreplay.py" +PWD=$(pwd) +PWDURL=$(echo "file://$PWD" | sed 's/\ /%20/g') +REPO="$PWD/_repo_replay" +REPOURL=$(echo "file://$REPO" | sed 's/\ /%20/g') + +# Clean-up +rm -rf "$REPO" _wc_target + +# Init repo +svnadmin create "$REPO" +# Add pre-revprop-change hook script +cp ../hook-examples/pre-revprop-change_example.txt "$REPO/hooks/pre-revprop-change" +chmod 755 "$REPO/hooks/pre-revprop-change" + + +################################################################ +OFFSET="/trunk/Module2/ProjectB" +svn mkdir -q -m "Add /trunk" $REPOURL/trunk +svn mkdir -q --parents -m "Add $OFFSET" $REPOURL$OFFSET + +test_expect_success \ + "svnreplay _repo_ref$OFFSET _repo_replay$OFFSET" \ + "$SVNREPLAY -a \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_expect_success \ + "diff-repo _repo_ref$OFFSET _repo_replay$OFFSET" \ + "./diff-repo.sh \"$PWDURL/_repo_ref$OFFSET\" \"$PWDURL/_repo_replay$OFFSET\"" + +test_done -- 2.43.0