vcprompt / tests / test-hg

#!/bin/sh

# Tests that require a real hg repository and executable.

. ./common.sh

check_hg()
{
    check_available \
	"hg -q version" \
	"Mercurial Distributed SCM" \
	"hg not found: skipping this test script"
}

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

pretest()
{
    [ -d "$tmpdir" ] || die "tmpdir ($tmpdir) does not exist"
    cd $tmpdir
    if [ ! -d hg-repo -o -f hg-repo/.hg/tainted ]; then
	rm -rf hg-repo
	tar -xf $hgrepo
    fi
    cd hg-repo
}

posttest()
{
    cd $tmpdir
    rm -rf hg-repo
}

# default prompt format in test repo
test_basics()
{
    echo "test_basics:"
    pretest
    assert_vcprompt "show branch 1" "default" "%b"
    assert_vcprompt "show rev 1" "[1]" "[%r]"

    hg -q update stable
    assert_vcprompt "show branch 2" "stable" "%b"
    assert_vcprompt "show rev 2" "[2]" "[%r]"

    hg -q update default
    hg -q merge --tool internal:other stable
    assert_vcprompt "show branch 3" "default" "%b"
    assert_vcprompt "show rev 3" "[1,2]" "[%r]"

    posttest
}

test_status()
{
    echo "test_status:"
    pretest
    assert_vcprompt "clean 1" "" "%m"
    assert_vcprompt "clean 2" "" "%u"
    assert_vcprompt "clean 3" "" "%m%u"

    echo foo >> b
    assert_vcprompt "mod only 1" "+" "%m"
    assert_vcprompt "mod only 2" "" "%u"
    assert_vcprompt "mod only 3" "+" "%m%u"

    echo junk > junk
    assert_vcprompt "mod+unknown 1" "+" "%m"
    assert_vcprompt "mod+unknown 2" "?" "%u"
    assert_vcprompt "mod+unknown 3" "+?" "%m%u"

    hg -q update --clean .
    assert_vcprompt "unknown only 1" "" "%m"
    assert_vcprompt "unknown only 2" "?" "%u"
    assert_vcprompt "unknown only 3" "?" "%m%u"

    posttest
}

test_status_goofy_filenames()
{
    echo "test_status_goofy_filenames:"
    pretest

    # goofy filenames to test parsing of "? " and "M "
    echo junk > "junk M junk"
    assert_vcprompt "no modified 2" "" "%m"
    assert_vcprompt "no modified, 1 unknown" "?" "%u"
    assert_vcprompt "no modified, 1 unknown" "?" "%m%u"
    rm -f "junk M junk"

    fn="crazy? filename"
    echo "not junk" > "$fn"
    hg -q add "$fn"
    hg -q commit -m"yes, it's a crazy filename"
    assert_vcprompt "no modified files" "" "%m"
    assert_vcprompt "no unknown files" "" "%u"
    assert_vcprompt "no modified/unknown files" "" "%m%u"

    echo x >> "$fn"
    assert_vcprompt "1 modified" "+" "%m"
    assert_vcprompt "no unknown files" "" "%u"
    assert_vcprompt "1 modified, no unknown" "+" "%m%u"
    posttest
}

check_hg
find_vcprompt
find_hgrepo
setup

test_basics
test_status
test_status_goofy_filenames

report
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.