-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
206 lines (180 loc) · 5.12 KB
/
test.sh
File metadata and controls
206 lines (180 loc) · 5.12 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env bash
# Test script for git-ignore extension
# This script verifies installation and basic functionality
set -e
# Colours for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Test counters
TESTS_PASSED=0
TESTS_FAILED=0
TESTS_SKIPPED=0
# Test directory
TEST_DIR=$(mktemp -d)
trap "rm -rf $TEST_DIR" EXIT
print_test() {
echo -e "${BLUE}TEST:${NC} $1"
}
print_pass() {
echo -e " ${GREEN}✓ PASS${NC}: $1"
((TESTS_PASSED++))
}
print_fail() {
echo -e " ${RED}✗ FAIL${NC}: $1"
((TESTS_FAILED++))
}
print_skip() {
echo -e " ${YELLOW}⊘ SKIP${NC}: $1"
((TESTS_SKIPPED++))
}
# Test 1: Check if git-ignore is installed
print_test "Installation check"
if command -v git-ignore >/dev/null 2>&1; then
print_pass "git-ignore command found"
else
print_fail "git-ignore command not found in PATH"
echo "Please run ./install.sh first"
exit 1
fi
# Test 2: Check if git subcommand works
print_test "Git subcommand integration"
if git ignore help >/dev/null 2>&1; then
print_pass "git ignore subcommand works"
else
print_skip "git ignore subcommand not working (may need shell restart)"
fi
# Test 3: Create test repository
print_test "Test repository setup"
cd "$TEST_DIR"
git init >/dev/null 2>&1
if [[ -d .git ]]; then
print_pass "Created test repository"
else
print_fail "Failed to create test repository"
exit 1
fi
# Test 4: Add patterns
print_test "Adding patterns"
git ignore "*.log" >/dev/null 2>&1
if grep -q "^\*.log$" .gitignore; then
print_pass "Successfully added *.log pattern"
else
print_fail "Failed to add pattern"
fi
# Test 5: Add multiple patterns
print_test "Adding multiple patterns"
git ignore add "*.tmp" "build/" >/dev/null 2>&1
if grep -q "^\*.tmp$" .gitignore && grep -q "^build/$" .gitignore; then
print_pass "Successfully added multiple patterns"
else
print_fail "Failed to add multiple patterns"
fi
# Test 6: Duplicate detection
print_test "Duplicate pattern detection"
output=$(git ignore add "*.log" 2>&1)
if echo "$output" | grep -q "already exists"; then
print_pass "Duplicate detection works"
else
print_fail "Duplicate detection failed"
fi
# Test 7: List patterns
print_test "Listing patterns"
output=$(git ignore list 2>&1)
if echo "$output" | grep -q "\*.log" && echo "$output" | grep -q "\*.tmp"; then
print_pass "List command works"
else
print_fail "List command failed"
fi
# Test 8: Remove pattern
print_test "Removing patterns"
git ignore remove "*.tmp" >/dev/null 2>&1
if ! grep -q "^\*.tmp$" .gitignore; then
print_pass "Successfully removed pattern"
else
print_fail "Failed to remove pattern"
fi
# Test 9: Check ignored files
print_test "Checking ignored files"
touch test.log
output=$(git ignore check test.log 2>&1)
if echo "$output" | grep -q "ignored"; then
print_pass "Check command works"
else
print_fail "Check command failed"
fi
# Test 10: Check non-ignored files
print_test "Checking non-ignored files"
touch test.txt
output=$(git ignore check test.txt 2>&1)
if echo "$output" | grep -q "not ignored"; then
print_pass "Check command correctly identifies non-ignored files"
else
print_fail "Check command failed for non-ignored files"
fi
# Test 11: Test with subdirectories
print_test "Subdirectory patterns"
mkdir -p src/components
git ignore add "src/components/" >/dev/null 2>&1
if grep -q "^src/components/$" .gitignore; then
print_pass "Subdirectory patterns work"
else
print_fail "Subdirectory patterns failed"
fi
# Test 12: Bash completion (if in bash)
if [[ -n "$BASH_VERSION" ]]; then
print_test "Bash completion"
if [[ -f ~/.local/share/bash-completion/completions/git-ignore ]]; then
print_pass "Bash completion file installed"
else
print_skip "Bash completion file not found"
fi
else
print_skip "Bash completion test (not running bash)"
fi
# Test 13: Zsh completion (if in zsh)
if [[ -n "$ZSH_VERSION" ]]; then
print_test "Zsh completion"
if [[ -f ~/.zsh/completions/_git-ignore ]]; then
print_pass "Zsh completion file installed"
else
print_skip "Zsh completion file not found"
fi
else
print_skip "Zsh completion test (not running zsh)"
fi
# Test 14: Help command
print_test "Help command"
output=$(git ignore help 2>&1)
if echo "$output" | grep -q "Usage:"; then
print_pass "Help command works"
else
print_fail "Help command failed"
fi
# Test 15: Working outside git repository
print_test "Error handling outside repository"
cd /tmp
output=$(git ignore list 2>&1)
if echo "$output" | grep -qi "not in a git repository"; then
print_pass "Properly handles non-repository directories"
else
print_fail "Should error when not in a repository"
fi
# Summary
echo
echo "=============================="
echo "Test Summary"
echo "=============================="
echo -e "${GREEN}Passed:${NC} $TESTS_PASSED"
echo -e "${RED}Failed:${NC} $TESTS_FAILED"
echo -e "${YELLOW}Skipped:${NC} $TESTS_SKIPPED"
echo
if [[ $TESTS_FAILED -eq 0 ]]; then
echo -e "${GREEN}All tests passed successfully!${NC}"
exit 0
else
echo -e "${RED}Some tests failed. Please check the output above.${NC}"
exit 1
fi