Skip to content

Commit 2dd573e

Browse files
committed
Merge pull request #12 from nnutter/delete
increased test coverage and quality
2 parents 1f3174d + 8d3ef30 commit 2dd573e

12 files changed

Lines changed: 413 additions & 183 deletions

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
language: perl
12
before_install:
23
- git clone https://github.com/sstephenson/bats.git
34
install:
45
- sudo bats/install.sh /usr/local
56
script:
6-
- t/git-bd.bats
7+
- prove -v t/*.bats

t/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Running tests requires the [Bash Automated Testing System][1] which can be
2+
easily installed from source and from Homebrew.
3+
4+
Once [BATS][1] is installed you can execute the test files directly, for example,
5+
6+
```
7+
$ t/create.bats
8+
✓ create succeeds without start point
9+
✓ create succeeds with start point
10+
✓ create fails when start point doesn't exist
11+
12+
3 tests, 0 failures
13+
```
14+
15+
Since [BATS][1] can produce TAP output you can use it with `prove`, for example,
16+
17+
```
18+
$ prove -j 4 --exec bats t/*.bats
19+
t/branch_exists.bats ..... ok
20+
t/bd_registered.bats ..... ok
21+
t/create.bats ............ ok
22+
t/bd_exists.bats ......... ok
23+
t/setup.bats ............. ok
24+
t/rename.bats ............ ok
25+
t/work_tree_exists.bats .. ok
26+
t/delete.bats ............ ok
27+
All tests successful.
28+
Files=8, Tests=29, 7 wallclock secs ( 0.05 usr 0.02 sys + 8.44 cusr 8.53 csys = 17.04 CPU)
29+
Result: PASS
30+
```
31+
32+
[1]: https://github.com/sstephenson/bats

t/bd_exists.bats

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
function setup {
6+
init_repo
7+
}
8+
9+
function teardown {
10+
tempdir_cleanup
11+
}
12+
13+
@test "bd_exists does find known bd" {
14+
git bd some_bd
15+
bd_exists some_bd
16+
}
17+
18+
@test "bd_exists does not find unknown bd" {
19+
! bd_exists some_bd
20+
}
21+
22+
@test "bd_exists fails if branch is deleted" {
23+
git bd some_bd
24+
git branch -d some_bd
25+
! bd_exists some_bd
26+
}
27+
28+
@test "bd_exists fails if work_tree is deleted" {
29+
git bd some_bd
30+
rm -rf "${TEMPDIR}/some_bd"
31+
! bd_exists some_bd
32+
}
33+
34+
@test "bd_exists fails if bd is unregistered" {
35+
git bd some_bd
36+
git config --unset bd.some_bd.work-tree
37+
! bd_exists some_bd
38+
}

t/bd_registered.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
function setup {
6+
init_repo
7+
}
8+
9+
function teardown {
10+
tempdir_cleanup
11+
}
12+
13+
@test "bd_registered does find known bd" {
14+
git bd some_bd
15+
bd_registered some_bd
16+
}
17+
18+
@test "bd_registered does not find unknown bd" {
19+
! bd_registered some_bd
20+
}

t/branch_exists.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
function setup {
6+
init_repo
7+
}
8+
9+
function teardown {
10+
tempdir_cleanup
11+
}
12+
13+
@test "branch_exists finds master" {
14+
branch_exists master
15+
}
16+
17+
@test "branch_exists does not find unknown_branch" {
18+
! branch_exists unknown_branch
19+
}

t/create.bats

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
function setup {
6+
init_repo
7+
}
8+
9+
function teardown {
10+
tempdir_cleanup
11+
}
12+
13+
@test "create succeeds without start point" {
14+
run git-bd foo
15+
test "$status" -eq 0
16+
bd_exists foo
17+
test "$(sha_of foo)" = "$(sha_of master)"
18+
}
19+
20+
@test "create succeeds with start point" {
21+
git checkout -b foo
22+
echo foo > README.md
23+
git commit -m 'foo' README.md
24+
git checkout master
25+
26+
run git-bd baz foo
27+
test "$status" -eq 0
28+
bd_exists baz
29+
test "$(sha_of baz)" = "$(sha_of foo)"
30+
test "$(sha_of baz)" != "$(sha_of master)"
31+
}
32+
33+
@test "create fails when start point doesn't exist" {
34+
run git-bd baz foo
35+
test "$status" -ne 0
36+
! bd_registered baz
37+
! branch_exists baz
38+
! work_tree_exists baz
39+
}

t/delete.bats

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env bats
2+
3+
load test_helper
4+
5+
function setup {
6+
init_repo
7+
}
8+
9+
function teardown {
10+
tempdir_cleanup
11+
}
12+
13+
@test "delete fails from the same bd" {
14+
git-bd foo
15+
cd "$TEMPDIR/foo"
16+
17+
bd_exists foo
18+
run git-bd -df foo
19+
test "$status" -ne 0
20+
bd_exists foo
21+
}
22+
23+
@test "delete succeeds when branch is merged" {
24+
git-bd foo
25+
26+
bd_exists foo
27+
run git-bd -df foo
28+
test "$status" -eq 0
29+
! bd_registered foo
30+
! branch_exists foo
31+
! work_tree_exists foo
32+
}
33+
34+
@test "delete fails when branch is unmerged" {
35+
git-bd foo
36+
cd "$TEMPDIR/foo"
37+
echo foo > README.md
38+
git commit -m 'foo' README.md
39+
cd "$TEMPDIR/master"
40+
41+
bd_exists foo
42+
run git-bd -df foo
43+
test "$status" -ne 0
44+
bd_registered foo
45+
branch_exists foo
46+
! work_tree_exists foo
47+
}
48+
49+
@test "force delete succeeds when branch is umerged" {
50+
git-bd foo
51+
cd "$TEMPDIR/foo"
52+
echo foo > README.md
53+
git commit -m 'foo' README.md
54+
cd "$TEMPDIR/master"
55+
56+
bd_exists foo
57+
run git-bd -Df foo
58+
test "$status" -eq 0
59+
! bd_registered foo
60+
! branch_exists foo
61+
! work_tree_exists foo
62+
}
63+
64+
@test "delete fails for unknown branchdir" {
65+
run git-bd -df foo
66+
test "$status" -ne 0
67+
! bd_registered foo
68+
! branch_exists foo
69+
! work_tree_exists foo
70+
}
71+
72+
@test "delete with branch and work_tree already removed" {
73+
git-bd foo
74+
75+
git branch -d foo
76+
rm -rf "$TEMPDIR/foo"
77+
78+
bd_registered foo
79+
run git-bd -df foo
80+
test "$status" -eq 0
81+
! bd_registered foo
82+
! branch_exists foo
83+
! work_tree_exists foo
84+
}
85+
86+
@test "delete with branch already removed" {
87+
git-bd foo
88+
bd_exists foo
89+
90+
git branch -d foo
91+
92+
bd_registered foo
93+
work_tree_exists foo
94+
run git-bd -df foo
95+
test "$status" -eq 0
96+
! bd_registered foo
97+
! branch_exists foo
98+
! work_tree_exists foo
99+
}
100+
101+
@test "delete with work_tree already removed" {
102+
git-bd foo
103+
rm -rf "$TEMPDIR/foo"
104+
105+
bd_registered foo
106+
branch_exists foo
107+
run git-bd -df foo
108+
test "$status" -eq 0
109+
! bd_registered foo
110+
! branch_exists foo
111+
! work_tree_exists foo
112+
}
113+
114+
@test "delete does not touch work_tree or branch if unregistered" {
115+
git-bd foo
116+
117+
git config --unset bd.foo.work-tree
118+
119+
! bd_registered foo
120+
branch_exists foo
121+
work_tree_exists foo
122+
run git-bd -df foo
123+
test "$status" -ne 0
124+
! bd_registered foo
125+
branch_exists foo
126+
work_tree_exists foo
127+
}

0 commit comments

Comments
 (0)