Skip to content

Commit 6b92c8c

Browse files
author
Cerem Cem ASLAN
committed
added more tests
1 parent f20e4db commit 6b92c8c

6 files changed

Lines changed: 107 additions & 25 deletions

File tree

run-tests.sh

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
#!/bin/bash
2-
32
dump(){
43
echo "expected:"
54
echo "${1}"
65
echo "got:"
76
echo "${2}"
87
}
98

10-
TESTS_DIR="./tests"
11-
rm -rf "$TESTS_DIR" 2> /dev/null
12-
mkdir -p "$TESTS_DIR/a/b"
13-
(
14-
cd "$TESTS_DIR"; git init foo > /dev/null
15-
cd a; git init bar > /dev/null
16-
cd b; git init baz > /dev/null
17-
)
18-
19-
res=$(./mgitstatus --depth=0 "$TESTS_DIR")
20-
#echo "$res"
21-
22-
# Test 1
23-
expected=$(cat << EOF
24-
./tests/a/b/baz: Repo has no commits yet
25-
./tests/a/bar: Repo has no commits yet
26-
./tests/foo: Repo has no commits yet
27-
EOF
28-
)
29-
30-
[[ "$res" = "$expected" ]] \
31-
&& echo "Test 1: 'Repo has no commits yet' passed" \
32-
|| { echo "Test 1: failed."; dump "$expected" "$res"; }
9+
check(){
10+
local got="$1"
11+
local expected="$2"
12+
if [[ "$got" != "$expected" ]]; then
13+
echo "FAILED in $(basename $test):"
14+
echo "-> Expected: "
15+
echo "$expected"
16+
echo "-> Got:"
17+
echo "$got"
18+
return 1
19+
else
20+
return 0
21+
fi
22+
23+
}
3324

34-
echo "All tests are passed."
25+
cwd=$PWD
26+
TESTS_DIR="$cwd/tests/__tmp__"
27+
rm -rf "$TESTS_DIR" 2> /dev/null
28+
bin="$PWD/mgitstatus"
29+
export bin
30+
export TESTS_DIR
31+
for test in $cwd/tests/*; do
32+
mkdir "$TESTS_DIR"
33+
cd "$TESTS_DIR"
34+
. $test
35+
echo "Passed: $(basename $test)"
36+
rm -rf "$TESTS_DIR" 2> /dev/null
37+
done

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__tmp__

tests/needs-push.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(
2+
git init a
3+
cd a
4+
echo "hello" > file
5+
git add .
6+
git commit -m "first commit"
7+
cd ..
8+
git clone a x
9+
cd x
10+
echo "there" > file
11+
git add .
12+
git commit -m "second commit"
13+
) > /dev/null
14+
15+
check "`$bin --depth=0 x`" "`cat << EOL
16+
x: Needs push (master)
17+
EOL
18+
`" || break

tests/no-commits-yet.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(
2+
mkdir -p a/b
3+
git init foo > /dev/null
4+
cd a
5+
git init bar > /dev/null
6+
cd b
7+
git init baz > /dev/null
8+
)
9+
10+
check "`$bin --depth=0 .`" "`cat << EOL
11+
./a/b/baz: Repo has no commits yet
12+
./a/bar: Repo has no commits yet
13+
./foo: Repo has no commits yet
14+
EOL
15+
`" || break

tests/stalled.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(
2+
git init a
3+
cd a
4+
echo "hello" > file
5+
git add .
6+
git commit -m "first commit"
7+
cd ..
8+
git clone a x
9+
cd x
10+
git checkout -b "second"
11+
echo "there" > file
12+
git add .
13+
git commit -m "second commit"
14+
) > /dev/null
15+
16+
check "`$bin --depth=0 x`" "`cat << EOL
17+
x: Needs upstream (second)
18+
EOL
19+
`" || break
20+
21+
# If some other branch has commits that current branch hasn't,
22+
# then the other branch is accepted as "stalled"
23+
(
24+
cd x
25+
git checkout master
26+
)
27+
28+
check "`$bin --depth=0 x`" "`cat << EOL
29+
x: Needs upstream (second) 1 stalled (second)
30+
EOL
31+
`" || break
32+

tests/untracked.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(
2+
git init a
3+
cd a
4+
echo "hello" > file
5+
git add .
6+
git commit -m "first commit"
7+
echo "there" > file2
8+
) > /dev/null
9+
10+
check "`$bin --depth=0 a`" "`cat << EOL
11+
a: Needs upstream (master) Untracked files
12+
EOL
13+
`" || break

0 commit comments

Comments
 (0)