Source

vcprompt / tests / test-svn

#!/bin/sh

# Tests that require a real svn repository and executable.

. ./common.sh

check_svn()
{
    check_available \
        "svn --version" \
        "svn, version " \
        "svn not found: skipping this test script"
    need=`svn --version | head -n1 | sed 's/, version /-/; s/\.[0-9]* .*//'`
    check_feature $need "$need not built in: skipping this test script"
}

find_svnrepo()
{
    if [ ! -f $testdir/svn-repo-1.tar ]; then
        echo "svn-repo-1.tar not found" >&2
        exit 1
    fi
    if [ ! -f $testdir/svn-repo-2.tar ]; then
        echo "svn-repo-2.tar not found" >&2
        exit 1
    fi
}

pretest()
{
    repobase=$1
    checkout_path=$2
    [ -d $tmpdir ] || die "tmpdir ($tmpdir) does not exist"
    cd $tmpdir
    svnrepo=$testdir/$repobase.tar
    rm -rf $repobase svn-wc
    tar -xf $svnrepo
    repourl=file://$tmpdir/$repobase
    svn -q checkout $repourl/$checkout_path svn-wc
    cd svn-wc
}

posttest()
{
    cd $tmpdir
    rm -rf svn-repo-* svn-wc
}

# default prompt format in test repo
test_basics()
{
    echo "test_basics:"
    pretest "svn-repo-1" "trunk"
    assert_vcprompt "vc name" "svn" "%n"
    assert_vcprompt "branch name on trunk" "trunk" "%b"
    assert_vcprompt "rev num on trunk" "2" "%r"

    svn -q switch $repourl/branches/stable
    assert_vcprompt "branch name on non-trunk branch" "stable" "%b"
    assert_vcprompt "rev num on branch" "4" "%r"

    # XXX checkout whole project: /trunk + /branches + /tags
    # XXX in a subdir: /trunk/d, /branches/stable/d

    posttest
}

test_weird_checkout()
{
    # checkout the whole repo, ie. parent of trunk/, tags/, branches/
    echo "test_weird_checkout:"
    pretest "svn-repo-1" ""
    assert_vcprompt "vc name" "svn" "%n"
    assert_vcprompt "no branch name (in project root)" "" "%b"

    cd trunk
    assert_vcprompt "branch name on trunk" "trunk" "%b"

    cd ../branches/stable
    assert_vcprompt "branch name on non-trunk branch" "stable" "%b"


    posttest
}

test_multiproject_repo()
{
    echo "test_multiproject_repo"
    pretest "svn-repo-2" "proj1/trunk"
    assert_vcprompt "trunk in multiproject repo" "[svn,1,trunk]" "[%n,%r,%b]"

    # argh, 'svn switch' doesn't work reliably (in 1.7 it requires
    # --ignore-ancestry, and in 1.6 that option doesn't exist) -- so
    # avoid it
    cd ..
    svn -q checkout $repourl/proj1/branches/1.0 wc2
    cd wc2
    assert_vcprompt "branch in multiproject repo" "[svn,2,1.0]" "[%n,%r,%b]"

    posttest
}

find_vcprompt
check_svn
find_svnrepo
setup

test_basics
test_weird_checkout
test_multiproject_repo