From 4a7d636bad0d03af22f440bef9bd141bfc0dc309 Mon Sep 17 00:00:00 2001
From: Claudio Bandera <claudio.bandera@kit.edu>
Date: Mon, 31 Aug 2015 00:07:46 +0200
Subject: Added tests for stash indicator

---
 radar-base.sh | 12 ++++++++----
 test          |  1 +
 test-stash.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 4 deletions(-)
 create mode 100755 test-stash.sh

diff --git a/radar-base.sh b/radar-base.sh
index 1be76e4..ec907b0 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -470,16 +470,20 @@ zsh_color_remote_commits() {
   printf %s "$remote"
 }
 
+stashed_status() {
+  printf '%s' "$(git stash list | wc -l 2>/dev/null)"
+}
+
 bash_stash_status() {
-  local number_stashes="$(git stash list | wc -l)"
+  local number_stashes="$(stashed_status)"
   if [ $number_stashes -gt 0 ]; then
-    printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02)"
+    printf " $number_stashes\x01\033[1;33m\x02=\x01\033[0m\x02"
   fi
 }
 
 zsh_stash_status() {
-  local number_stashes="$(git stash list | wc -l)"
+  local number_stashes="$(stashed_status)"
   if [ $number_stashes -gt 0 ]; then
-    printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%})"
+    printf %s " $number_stashes%{$fg_bold[yellow]%}=%{$reset_color%}"
   fi
 }
\ No newline at end of file
diff --git a/test b/test
index a6a8775..d5213be 100755
--- a/test
+++ b/test
@@ -5,3 +5,4 @@
 ./test-branches.sh
 ./test-files.sh
 ./test-status.sh
+./test-stash.sh
\ No newline at end of file
diff --git a/test-stash.sh b/test-stash.sh
new file mode 100755
index 0000000..aecd83c
--- /dev/null
+++ b/test-stash.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+scriptDir="$(cd "$(dirname "$0")"; pwd)"
+
+source "$scriptDir/radar-base.sh"
+
+tmpfile=""
+
+cd_to_tmp() {
+  tmpfile="/tmp/git-prompt-tests-$(time_now)$1"
+  mkdir -p "$tmpfile"
+  cd "$tmpfile"
+}
+
+rm_tmp() {
+  cd $scriptDir
+  rm -rf /tmp/git-prompt-tests*
+}
+
+test_unstashed_status() {
+  cd_to_tmp
+  git init --quiet
+
+  assertEquals "0" "$(stashed_status)"
+
+  rm_tmp
+}
+
+test_stashed_status() {
+  cd_to_tmp
+  git init --quiet
+
+  touch foo
+  git add --all
+  git commit -m "Initial commit"  >/dev/null
+  echo "test">foo
+  git stash > /dev/null
+  assertEquals "1" "$(stashed_status)"
+  
+  echo "test2">foo
+  git stash > /dev/null
+  assertEquals "2" "$(stashed_status)"
+
+  git stash drop > /dev/null
+  assertEquals "1" "$(stashed_status)"
+
+
+  rm_tmp
+}
+
+. ./shunit/shunit2
-- 
cgit v1.2.3