@chongdashu/cc-statusline 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,336 +1,336 @@
1
- #!/bin/bash
2
-
3
- # Test script for cc-statusline installation scenarios
4
- # Tests both global and project-level installations
5
-
6
- # Colors for output
7
- GREEN='\033[0;32m'
8
- RED='\033[0;31m'
9
- YELLOW='\033[1;33m'
10
- CYAN='\033[0;36m'
11
- GRAY='\033[0;90m'
12
- NC='\033[0m' # No Color
13
-
14
- # Test configuration
15
- TEST_DIR="$(dirname "$0")/test-workspace"
16
- FAKE_HOME="$TEST_DIR/fake-home"
17
- FAKE_PROJECT="$TEST_DIR/fake-project"
18
- FAKE_GLOBAL_CLAUDE="$FAKE_HOME/.claude"
19
- FAKE_PROJECT_CLAUDE="$FAKE_PROJECT/.claude"
20
-
21
- # Counter for tests
22
- TESTS_RUN=0
23
- TESTS_PASSED=0
24
- TESTS_FAILED=0
25
-
26
- # Helper functions
27
- setup_test_env() {
28
- echo -e "${CYAN}Setting up test environment...${NC}"
29
- rm -rf "$TEST_DIR" 2>/dev/null
30
- mkdir -p "$FAKE_HOME"
31
- mkdir -p "$FAKE_PROJECT"
32
- }
33
-
34
- cleanup_test_env() {
35
- echo -e "${GRAY}Cleaning up test environment...${NC}"
36
- rm -rf "$TEST_DIR" 2>/dev/null
37
- }
38
-
39
- test_scenario() {
40
- local scenario_name="$1"
41
- local test_function="$2"
42
-
43
- echo -e "\n${CYAN}Testing: $scenario_name${NC}"
44
- TESTS_RUN=$((TESTS_RUN + 1))
45
-
46
- # Clean environment for each test
47
- rm -rf "$FAKE_GLOBAL_CLAUDE" 2>/dev/null
48
- rm -rf "$FAKE_PROJECT_CLAUDE" 2>/dev/null
49
-
50
- # Run the test
51
- if $test_function; then
52
- echo -e "${GREEN}✓ PASSED${NC}"
53
- TESTS_PASSED=$((TESTS_PASSED + 1))
54
- else
55
- echo -e "${RED}✗ FAILED${NC}"
56
- TESTS_FAILED=$((TESTS_FAILED + 1))
57
- fi
58
- }
59
-
60
- assert_file_exists() {
61
- local file="$1"
62
- local description="$2"
63
-
64
- if [ -f "$file" ]; then
65
- echo -e " ${GREEN}✓${NC} $description exists"
66
- return 0
67
- else
68
- echo -e " ${RED}✗${NC} $description does not exist"
69
- return 1
70
- fi
71
- }
72
-
73
- assert_file_not_exists() {
74
- local file="$1"
75
- local description="$2"
76
-
77
- if [ ! -f "$file" ]; then
78
- echo -e " ${GREEN}✓${NC} $description does not exist"
79
- return 0
80
- else
81
- echo -e " ${RED}✗${NC} $description exists (unexpected)"
82
- return 1
83
- fi
84
- }
85
-
86
- assert_file_contains() {
87
- local file="$1"
88
- local content="$2"
89
- local description="$3"
90
-
91
- if grep -q "$content" "$file" 2>/dev/null; then
92
- echo -e " ${GREEN}✓${NC} $description"
93
- return 0
94
- else
95
- echo -e " ${RED}✗${NC} $description not found"
96
- return 1
97
- fi
98
- }
99
-
100
- assert_json_field() {
101
- local file="$1"
102
- local field="$2"
103
- local expected="$3"
104
- local description="$4"
105
-
106
- if [ -f "$file" ]; then
107
- local actual=$(jq -r "$field" "$file" 2>/dev/null)
108
- if [ "$actual" = "$expected" ]; then
109
- echo -e " ${GREEN}✓${NC} $description: $expected"
110
- return 0
111
- else
112
- echo -e " ${RED}✗${NC} $description: expected '$expected', got '$actual'"
113
- return 1
114
- fi
115
- else
116
- echo -e " ${RED}✗${NC} $description: file does not exist"
117
- return 1
118
- fi
119
- }
120
-
121
- # Test scenarios
122
-
123
- test_no_files_global() {
124
- echo -e "${GRAY} Scenario: No files exist, installing globally${NC}"
125
-
126
- # Create the directory
127
- mkdir -p "$FAKE_GLOBAL_CLAUDE"
128
-
129
- # Simulate installation
130
- echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
131
- echo 'echo "test statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
132
- chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
133
-
134
- # Create settings.json
135
- cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
136
- {
137
- "statusLine": {
138
- "type": "command",
139
- "command": "~/.claude/statusline.sh",
140
- "padding": 0
141
- }
142
- }
143
- EOF
144
-
145
- # Verify
146
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
147
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json" && \
148
- assert_json_field "$FAKE_GLOBAL_CLAUDE/settings.json" ".statusLine.command" "~/.claude/statusline.sh" "statusLine command"
149
- }
150
-
151
- test_no_files_project() {
152
- echo -e "${GRAY} Scenario: No files exist, installing in project${NC}"
153
-
154
- # Create the directory
155
- mkdir -p "$FAKE_PROJECT_CLAUDE"
156
-
157
- # Simulate installation
158
- echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
159
- echo 'echo "test statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
160
- chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
161
-
162
- # Create settings.json
163
- cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
164
- {
165
- "statusLine": {
166
- "type": "command",
167
- "command": ".claude/statusline.sh",
168
- "padding": 0
169
- }
170
- }
171
- EOF
172
-
173
- # Verify
174
- assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
175
- assert_file_exists "$FAKE_PROJECT_CLAUDE/settings.json" "Project settings.json" && \
176
- assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".statusLine.command" ".claude/statusline.sh" "statusLine command"
177
- }
178
-
179
- test_statusline_exists_global() {
180
- echo -e "${GRAY} Scenario: statusline.sh exists, no settings.json (global)${NC}"
181
-
182
- # Create existing statusline
183
- mkdir -p "$FAKE_GLOBAL_CLAUDE"
184
- echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
185
- echo 'echo "old statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
186
- chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
187
-
188
- # Simulate installation (would prompt for overwrite, we assume no)
189
- # So statusline.sh should remain unchanged
190
-
191
- # Create settings.json (would be created regardless)
192
- cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
193
- {
194
- "statusLine": {
195
- "type": "command",
196
- "command": "~/.claude/statusline.sh",
197
- "padding": 0
198
- }
199
- }
200
- EOF
201
-
202
- # Verify
203
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
204
- assert_file_contains "$FAKE_GLOBAL_CLAUDE/statusline.sh" "old statusline" "Original statusline preserved" && \
205
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json"
206
- }
207
-
208
- test_both_exist_global() {
209
- echo -e "${GRAY} Scenario: Both files exist (global)${NC}"
210
-
211
- # Create existing files
212
- mkdir -p "$FAKE_GLOBAL_CLAUDE"
213
- echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
214
- echo 'echo "old statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
215
- chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
216
-
217
- cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
218
- {
219
- "statusLine": {
220
- "type": "command",
221
- "command": "~/.claude/statusline.sh",
222
- "padding": 0
223
- },
224
- "otherSetting": "preserved"
225
- }
226
- EOF
227
-
228
- # Simulate installation (would prompt for overwrite, we assume no)
229
- # Both files should remain unchanged
230
-
231
- # Verify
232
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
233
- assert_file_contains "$FAKE_GLOBAL_CLAUDE/statusline.sh" "old statusline" "Original statusline preserved" && \
234
- assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json" && \
235
- assert_json_field "$FAKE_GLOBAL_CLAUDE/settings.json" ".otherSetting" "preserved" "Other settings preserved"
236
- }
237
-
238
- test_different_statusline_configured() {
239
- echo -e "${GRAY} Scenario: Different statusline configured (project)${NC}"
240
-
241
- # Create settings with different statusline
242
- mkdir -p "$FAKE_PROJECT_CLAUDE"
243
- cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
244
- {
245
- "statusLine": {
246
- "type": "command",
247
- "command": "custom-statusline.sh",
248
- "padding": 2
249
- },
250
- "otherSetting": "preserved"
251
- }
252
- EOF
253
-
254
- # Simulate installation
255
- echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
256
- echo 'echo "new statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
257
- chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
258
-
259
- # Settings should be preserved (not overwritten)
260
-
261
- # Verify
262
- assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
263
- assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".statusLine.command" "custom-statusline.sh" "Custom statusLine preserved" && \
264
- assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".otherSetting" "preserved" "Other settings preserved"
265
- }
266
-
267
- test_create_in_empty_directory() {
268
- echo -e "${GRAY} Scenario: Create .claude directory if it doesn't exist${NC}"
269
-
270
- # Don't create directory beforehand
271
- rm -rf "$FAKE_PROJECT_CLAUDE" 2>/dev/null
272
-
273
- # Simulate installation
274
- mkdir -p "$FAKE_PROJECT_CLAUDE"
275
- echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
276
- echo 'echo "test statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
277
- chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
278
-
279
- cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
280
- {
281
- "statusLine": {
282
- "type": "command",
283
- "command": ".claude/statusline.sh",
284
- "padding": 0
285
- }
286
- }
287
- EOF
288
-
289
- # Verify
290
- assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
291
- assert_file_exists "$FAKE_PROJECT_CLAUDE/settings.json" "Project settings.json"
292
- }
293
-
294
- # Main test execution
295
- main() {
296
- echo -e "${CYAN}================================${NC}"
297
- echo -e "${CYAN}CC-Statusline Installation Tests${NC}"
298
- echo -e "${CYAN}================================${NC}"
299
-
300
- # Check for jq dependency
301
- if ! command -v jq &> /dev/null; then
302
- echo -e "${YELLOW}Warning: jq not found. Some tests may fail.${NC}"
303
- echo -e "${GRAY}Install with: apt-get install jq (Ubuntu) or brew install jq (macOS)${NC}"
304
- fi
305
-
306
- setup_test_env
307
-
308
- # Run all test scenarios
309
- test_scenario "No files exist (Global)" test_no_files_global
310
- test_scenario "No files exist (Project)" test_no_files_project
311
- test_scenario "statusline.sh exists, no settings.json (Global)" test_statusline_exists_global
312
- test_scenario "Both files exist (Global)" test_both_exist_global
313
- test_scenario "Different statusline configured (Project)" test_different_statusline_configured
314
- test_scenario "Create .claude directory if doesn't exist" test_create_in_empty_directory
315
-
316
- # Summary
317
- echo -e "\n${CYAN}================================${NC}"
318
- echo -e "${CYAN}Test Summary${NC}"
319
- echo -e "${CYAN}================================${NC}"
320
- echo -e "Total: $TESTS_RUN"
321
- echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
322
- echo -e "${RED}Failed: $TESTS_FAILED${NC}"
323
-
324
- cleanup_test_env
325
-
326
- if [ $TESTS_FAILED -gt 0 ]; then
327
- echo -e "\n${RED}Some tests failed!${NC}"
328
- exit 1
329
- else
330
- echo -e "\n${GREEN}All tests passed!${NC}"
331
- exit 0
332
- fi
333
- }
334
-
335
- # Run the tests
1
+ #!/bin/bash
2
+
3
+ # Test script for cc-statusline installation scenarios
4
+ # Tests both global and project-level installations
5
+
6
+ # Colors for output
7
+ GREEN='\033[0;32m'
8
+ RED='\033[0;31m'
9
+ YELLOW='\033[1;33m'
10
+ CYAN='\033[0;36m'
11
+ GRAY='\033[0;90m'
12
+ NC='\033[0m' # No Color
13
+
14
+ # Test configuration
15
+ TEST_DIR="$(dirname "$0")/test-workspace"
16
+ FAKE_HOME="$TEST_DIR/fake-home"
17
+ FAKE_PROJECT="$TEST_DIR/fake-project"
18
+ FAKE_GLOBAL_CLAUDE="$FAKE_HOME/.claude"
19
+ FAKE_PROJECT_CLAUDE="$FAKE_PROJECT/.claude"
20
+
21
+ # Counter for tests
22
+ TESTS_RUN=0
23
+ TESTS_PASSED=0
24
+ TESTS_FAILED=0
25
+
26
+ # Helper functions
27
+ setup_test_env() {
28
+ echo -e "${CYAN}Setting up test environment...${NC}"
29
+ rm -rf "$TEST_DIR" 2>/dev/null
30
+ mkdir -p "$FAKE_HOME"
31
+ mkdir -p "$FAKE_PROJECT"
32
+ }
33
+
34
+ cleanup_test_env() {
35
+ echo -e "${GRAY}Cleaning up test environment...${NC}"
36
+ rm -rf "$TEST_DIR" 2>/dev/null
37
+ }
38
+
39
+ test_scenario() {
40
+ local scenario_name="$1"
41
+ local test_function="$2"
42
+
43
+ echo -e "\n${CYAN}Testing: $scenario_name${NC}"
44
+ TESTS_RUN=$((TESTS_RUN + 1))
45
+
46
+ # Clean environment for each test
47
+ rm -rf "$FAKE_GLOBAL_CLAUDE" 2>/dev/null
48
+ rm -rf "$FAKE_PROJECT_CLAUDE" 2>/dev/null
49
+
50
+ # Run the test
51
+ if $test_function; then
52
+ echo -e "${GREEN}✓ PASSED${NC}"
53
+ TESTS_PASSED=$((TESTS_PASSED + 1))
54
+ else
55
+ echo -e "${RED}✗ FAILED${NC}"
56
+ TESTS_FAILED=$((TESTS_FAILED + 1))
57
+ fi
58
+ }
59
+
60
+ assert_file_exists() {
61
+ local file="$1"
62
+ local description="$2"
63
+
64
+ if [ -f "$file" ]; then
65
+ echo -e " ${GREEN}✓${NC} $description exists"
66
+ return 0
67
+ else
68
+ echo -e " ${RED}✗${NC} $description does not exist"
69
+ return 1
70
+ fi
71
+ }
72
+
73
+ assert_file_not_exists() {
74
+ local file="$1"
75
+ local description="$2"
76
+
77
+ if [ ! -f "$file" ]; then
78
+ echo -e " ${GREEN}✓${NC} $description does not exist"
79
+ return 0
80
+ else
81
+ echo -e " ${RED}✗${NC} $description exists (unexpected)"
82
+ return 1
83
+ fi
84
+ }
85
+
86
+ assert_file_contains() {
87
+ local file="$1"
88
+ local content="$2"
89
+ local description="$3"
90
+
91
+ if grep -q "$content" "$file" 2>/dev/null; then
92
+ echo -e " ${GREEN}✓${NC} $description"
93
+ return 0
94
+ else
95
+ echo -e " ${RED}✗${NC} $description not found"
96
+ return 1
97
+ fi
98
+ }
99
+
100
+ assert_json_field() {
101
+ local file="$1"
102
+ local field="$2"
103
+ local expected="$3"
104
+ local description="$4"
105
+
106
+ if [ -f "$file" ]; then
107
+ local actual=$(jq -r "$field" "$file" 2>/dev/null)
108
+ if [ "$actual" = "$expected" ]; then
109
+ echo -e " ${GREEN}✓${NC} $description: $expected"
110
+ return 0
111
+ else
112
+ echo -e " ${RED}✗${NC} $description: expected '$expected', got '$actual'"
113
+ return 1
114
+ fi
115
+ else
116
+ echo -e " ${RED}✗${NC} $description: file does not exist"
117
+ return 1
118
+ fi
119
+ }
120
+
121
+ # Test scenarios
122
+
123
+ test_no_files_global() {
124
+ echo -e "${GRAY} Scenario: No files exist, installing globally${NC}"
125
+
126
+ # Create the directory
127
+ mkdir -p "$FAKE_GLOBAL_CLAUDE"
128
+
129
+ # Simulate installation
130
+ echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
131
+ echo 'echo "test statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
132
+ chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
133
+
134
+ # Create settings.json
135
+ cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
136
+ {
137
+ "statusLine": {
138
+ "type": "command",
139
+ "command": "~/.claude/statusline.sh",
140
+ "padding": 0
141
+ }
142
+ }
143
+ EOF
144
+
145
+ # Verify
146
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
147
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json" && \
148
+ assert_json_field "$FAKE_GLOBAL_CLAUDE/settings.json" ".statusLine.command" "~/.claude/statusline.sh" "statusLine command"
149
+ }
150
+
151
+ test_no_files_project() {
152
+ echo -e "${GRAY} Scenario: No files exist, installing in project${NC}"
153
+
154
+ # Create the directory
155
+ mkdir -p "$FAKE_PROJECT_CLAUDE"
156
+
157
+ # Simulate installation
158
+ echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
159
+ echo 'echo "test statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
160
+ chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
161
+
162
+ # Create settings.json
163
+ cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
164
+ {
165
+ "statusLine": {
166
+ "type": "command",
167
+ "command": ".claude/statusline.sh",
168
+ "padding": 0
169
+ }
170
+ }
171
+ EOF
172
+
173
+ # Verify
174
+ assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
175
+ assert_file_exists "$FAKE_PROJECT_CLAUDE/settings.json" "Project settings.json" && \
176
+ assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".statusLine.command" ".claude/statusline.sh" "statusLine command"
177
+ }
178
+
179
+ test_statusline_exists_global() {
180
+ echo -e "${GRAY} Scenario: statusline.sh exists, no settings.json (global)${NC}"
181
+
182
+ # Create existing statusline
183
+ mkdir -p "$FAKE_GLOBAL_CLAUDE"
184
+ echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
185
+ echo 'echo "old statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
186
+ chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
187
+
188
+ # Simulate installation (would prompt for overwrite, we assume no)
189
+ # So statusline.sh should remain unchanged
190
+
191
+ # Create settings.json (would be created regardless)
192
+ cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
193
+ {
194
+ "statusLine": {
195
+ "type": "command",
196
+ "command": "~/.claude/statusline.sh",
197
+ "padding": 0
198
+ }
199
+ }
200
+ EOF
201
+
202
+ # Verify
203
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
204
+ assert_file_contains "$FAKE_GLOBAL_CLAUDE/statusline.sh" "old statusline" "Original statusline preserved" && \
205
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json"
206
+ }
207
+
208
+ test_both_exist_global() {
209
+ echo -e "${GRAY} Scenario: Both files exist (global)${NC}"
210
+
211
+ # Create existing files
212
+ mkdir -p "$FAKE_GLOBAL_CLAUDE"
213
+ echo '#!/bin/bash' > "$FAKE_GLOBAL_CLAUDE/statusline.sh"
214
+ echo 'echo "old statusline"' >> "$FAKE_GLOBAL_CLAUDE/statusline.sh"
215
+ chmod +x "$FAKE_GLOBAL_CLAUDE/statusline.sh"
216
+
217
+ cat > "$FAKE_GLOBAL_CLAUDE/settings.json" <<EOF
218
+ {
219
+ "statusLine": {
220
+ "type": "command",
221
+ "command": "~/.claude/statusline.sh",
222
+ "padding": 0
223
+ },
224
+ "otherSetting": "preserved"
225
+ }
226
+ EOF
227
+
228
+ # Simulate installation (would prompt for overwrite, we assume no)
229
+ # Both files should remain unchanged
230
+
231
+ # Verify
232
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/statusline.sh" "Global statusline.sh" && \
233
+ assert_file_contains "$FAKE_GLOBAL_CLAUDE/statusline.sh" "old statusline" "Original statusline preserved" && \
234
+ assert_file_exists "$FAKE_GLOBAL_CLAUDE/settings.json" "Global settings.json" && \
235
+ assert_json_field "$FAKE_GLOBAL_CLAUDE/settings.json" ".otherSetting" "preserved" "Other settings preserved"
236
+ }
237
+
238
+ test_different_statusline_configured() {
239
+ echo -e "${GRAY} Scenario: Different statusline configured (project)${NC}"
240
+
241
+ # Create settings with different statusline
242
+ mkdir -p "$FAKE_PROJECT_CLAUDE"
243
+ cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
244
+ {
245
+ "statusLine": {
246
+ "type": "command",
247
+ "command": "custom-statusline.sh",
248
+ "padding": 2
249
+ },
250
+ "otherSetting": "preserved"
251
+ }
252
+ EOF
253
+
254
+ # Simulate installation
255
+ echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
256
+ echo 'echo "new statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
257
+ chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
258
+
259
+ # Settings should be preserved (not overwritten)
260
+
261
+ # Verify
262
+ assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
263
+ assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".statusLine.command" "custom-statusline.sh" "Custom statusLine preserved" && \
264
+ assert_json_field "$FAKE_PROJECT_CLAUDE/settings.json" ".otherSetting" "preserved" "Other settings preserved"
265
+ }
266
+
267
+ test_create_in_empty_directory() {
268
+ echo -e "${GRAY} Scenario: Create .claude directory if it doesn't exist${NC}"
269
+
270
+ # Don't create directory beforehand
271
+ rm -rf "$FAKE_PROJECT_CLAUDE" 2>/dev/null
272
+
273
+ # Simulate installation
274
+ mkdir -p "$FAKE_PROJECT_CLAUDE"
275
+ echo '#!/bin/bash' > "$FAKE_PROJECT_CLAUDE/statusline.sh"
276
+ echo 'echo "test statusline"' >> "$FAKE_PROJECT_CLAUDE/statusline.sh"
277
+ chmod +x "$FAKE_PROJECT_CLAUDE/statusline.sh"
278
+
279
+ cat > "$FAKE_PROJECT_CLAUDE/settings.json" <<EOF
280
+ {
281
+ "statusLine": {
282
+ "type": "command",
283
+ "command": ".claude/statusline.sh",
284
+ "padding": 0
285
+ }
286
+ }
287
+ EOF
288
+
289
+ # Verify
290
+ assert_file_exists "$FAKE_PROJECT_CLAUDE/statusline.sh" "Project statusline.sh" && \
291
+ assert_file_exists "$FAKE_PROJECT_CLAUDE/settings.json" "Project settings.json"
292
+ }
293
+
294
+ # Main test execution
295
+ main() {
296
+ echo -e "${CYAN}================================${NC}"
297
+ echo -e "${CYAN}CC-Statusline Installation Tests${NC}"
298
+ echo -e "${CYAN}================================${NC}"
299
+
300
+ # Check for jq dependency
301
+ if ! command -v jq &> /dev/null; then
302
+ echo -e "${YELLOW}Warning: jq not found. Some tests may fail.${NC}"
303
+ echo -e "${GRAY}Install with: apt-get install jq (Ubuntu) or brew install jq (macOS)${NC}"
304
+ fi
305
+
306
+ setup_test_env
307
+
308
+ # Run all test scenarios
309
+ test_scenario "No files exist (Global)" test_no_files_global
310
+ test_scenario "No files exist (Project)" test_no_files_project
311
+ test_scenario "statusline.sh exists, no settings.json (Global)" test_statusline_exists_global
312
+ test_scenario "Both files exist (Global)" test_both_exist_global
313
+ test_scenario "Different statusline configured (Project)" test_different_statusline_configured
314
+ test_scenario "Create .claude directory if doesn't exist" test_create_in_empty_directory
315
+
316
+ # Summary
317
+ echo -e "\n${CYAN}================================${NC}"
318
+ echo -e "${CYAN}Test Summary${NC}"
319
+ echo -e "${CYAN}================================${NC}"
320
+ echo -e "Total: $TESTS_RUN"
321
+ echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
322
+ echo -e "${RED}Failed: $TESTS_FAILED${NC}"
323
+
324
+ cleanup_test_env
325
+
326
+ if [ $TESTS_FAILED -gt 0 ]; then
327
+ echo -e "\n${RED}Some tests failed!${NC}"
328
+ exit 1
329
+ else
330
+ echo -e "\n${GREEN}All tests passed!${NC}"
331
+ exit 0
332
+ fi
333
+ }
334
+
335
+ # Run the tests
336
336
  main