Greg Ward avatar Greg Ward committed eb48d3c

Add test-git to test reporting modified/unknown files with git.

Comments (0)

Files changed (4)

 ~$
 \.o$
 ^vcprompt$
+
+^tests/\w+-repo(\.tar)?$
 check: vcprompt
 	cd tests && ./test-simple
 
+gitrepo = tests/git-repo.tar
+
+check-git: vcprompt $(gitrepo)
+	cd tests && ./test-git
+
+$(gitrepo): tests/setup-git
+	cd tests && ./setup-git
+
+# target check-all requires that all supported VC tools be
+# installed
+check-all: check check-git
+
 clean:
 	rm -f $(objects) vcprompt
+#!/bin/sh
+
+# Setup the test git repository that will be used by test-git.
+# 
+# Output is git-repo.tar, which can be unpacked for each test -- that
+# way tests can modify the repo and/or working dir without harming
+# other tests.
+
+set -ex
+cd `dirname $0`
+rm -rf git-repo
+git init git-repo
+cd git-repo
+
+# two files tracked by git
+echo a > a
+echo b > b
+git add -A
+git commit -m"add a, b"
+
+# uncommitted change to b
+echo foo >> b
+
+# some ignored files
+echo "*.o" > .git/info/exclude
+touch a.o
+
+# an unknown file ("other" in git-speak)
+touch junk
+
+cd ..
+tar -cf git-repo.tar git-repo
+rm -rf git-repo
+#!/bin/sh
+
+# Tests that require a real git repository and executable.
+
+source ./common.sh
+
+find_gitrepo()
+{
+    gitrepo="$testdir/git-repo.tar"
+    if [ ! -f $gitrepo ]; then
+        echo "$gitrepo not found" >&2
+        exit 1
+    fi
+}
+
+pretest()
+{
+    cd $tmpdir
+    if [ ! -d git-repo -o -f git-repo/.git/tainted ]; then
+        #echo "unpacking $gitrepo"
+        rm -rf git-repo
+        tar -xf $gitrepo
+    fi
+    cd git-repo
+
+    # weird: git diff --quiet gives incorrect results on the 
+    # first run after untar'ing, so run it once now to get
+    # past that
+    git diff --quiet || true
+}
+
+posttest()
+{
+    :
+}
+
+# default prompt format in our test repo
+test_basics()
+{
+    pretest
+    assert_vcprompt "show branch" "master" "%b"
+    assert_vcprompt "show modified" "!" "%m"
+    assert_vcprompt "show unknown" "?" "%u"
+    posttest
+}
+
+# "%m" expands to nothing if no uncommitted changes
+test_no_modified()
+{
+    pretest
+    touch .git/tainted
+    assert_vcprompt "modified and unknown" "master!?" "%b%m%u"
+    git reset -q --hard HEAD
+    assert_vcprompt "no modified files, still 1 unknown" "master?" "%b%m%u"
+    posttest
+}
+
+# "%u" expands to nothing if no unknown files
+test_no_unknown()
+{
+    pretest
+    touch .git/tainted
+    rm -f junk
+    assert_vcprompt "modified and ignore, no unknown" "master!" "%b%m%u"
+    rm -f a.o
+    assert_vcprompt "modified, no ignored, no unknown" "master!" "%b%m%u"
+    git reset -q --hard HEAD
+    assert_vcprompt "no modified, no ignored, no unknown" "master" "%b%m%u"
+    posttest
+}
+
+find_vcprompt
+find_gitrepo
+setup
+
+failed=""
+
+#set -e
+test_basics
+test_no_modified
+test_no_unknown
+
+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.