summaryrefslogtreecommitdiffstats
path: root/test-branches.sh
blob: ddf442c29bc5906eb0a1384b838f665c93a905f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
scriptDir="$(cd "$(dirname "$0")"; pwd)"

source "$scriptDir/git-base.sh"

tmpfile=""

cd_to_tmp() {
  tmpfile="/tmp/git-prompt-tests-$(time_now)"
  mkdir -p "$tmpfile"
  cd "$tmpfile"
}

rm_tmp() {
  cd $scriptDir
  rm -r "$tmpfile"
}

test_branch_name_in_repo() {
  cd_to_tmp
  git init --quiet
  git checkout -b foo --quiet
  assertEquals "foo" "$(branch_name)"

  git checkout -b bar --quiet
  assertEquals "bar" "$(branch_name)"

  git checkout -b baz --quiet
  assertEquals "baz" "$(branch_name)"

  rm_tmp
}

test_branch_name_not_in_repo() {
  cd_to_tmp
  assertEquals "" "$(branch_name)"
  rm_tmp
}

. ./shunit/shunit2