Skip to content

Commit eb9716c

Browse files
committed
Simplify and consolidate unit test suites for context and git-context
- Remove redundant test cases - Reduce the number of tests from 12 to 8/9 - Focus on core functionality testing - Streamline test script structure - Prepare for more focused and maintainable test coverage
1 parent 46614cf commit eb9716c

File tree

2 files changed

+23
-102
lines changed

2 files changed

+23
-102
lines changed

test/unit/test_context.sh

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_number=0
1515
failures=0
1616

1717
# Print TAP plan
18-
echo "1..12"
18+
echo "1..8"
1919

2020
# Create a temporary directory for this test
2121
test_dir=$(create_test_dir)
@@ -28,7 +28,7 @@ echo "// Test file 2 - identifiable content" > "$test_dir/src/file2.js"
2828
mkdir -p "$test_dir/node_modules"
2929
echo "// Should be excluded - node_modules content" > "$test_dir/node_modules/exclude_me.js"
3030

31-
# Setup test file with comments for summary test
31+
# Setup test file with comments for basic tests
3232
cat > "$test_dir/test.js" << EOF
3333
// Test file header
3434
// This is a description
@@ -63,18 +63,7 @@ else
6363
failures=$((failures + 1))
6464
fi
6565

66-
# Test 2: Summary option
67-
summary_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" test.js --summary 2>&1)
68-
if echo "$summary_output" | grep -q "Summary:"; then
69-
echo "ok $((test_number+=1)) - summary option displays summary"
70-
else
71-
echo "not ok $((test_number+=1)) - summary option displays summary"
72-
echo "# Summary output did not contain 'Summary:'"
73-
echo "# Output: $summary_output"
74-
failures=$((failures + 1))
75-
fi
76-
77-
# Test 3: No ls-files option
66+
# Test 2: No ls-files option
7867
nolsfiles_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" test.js --no-ls-files 2>&1)
7968
if ! echo "$nolsfiles_output" | grep -q "Repository Files"; then
8069
echo "ok $((test_number+=1)) - no-ls-files option hides repository files"
@@ -84,7 +73,7 @@ else
8473
failures=$((failures + 1))
8574
fi
8675

87-
# Test 4: Invalid option
76+
# Test 3: Invalid option
8877
if ! "$PROJECT_ROOT/context" --invalid-option >/dev/null 2>&1; then
8978
echo "ok $((test_number+=1)) - invalid option causes error"
9079
else
@@ -95,7 +84,7 @@ fi
9584

9685
echo "# Section 2: File Processing Tests"
9786

98-
# Test 5: Basic file inclusion
87+
# Test 4: Basic file inclusion
9988
if cd "$test_dir" && "$PROJECT_ROOT/context" src/file1.js | grep -q "Test file 1"; then
10089
echo "ok $((test_number+=1)) - basic file inclusion"
10190
else
@@ -104,7 +93,7 @@ else
10493
failures=$((failures + 1))
10594
fi
10695

107-
# Test 6: File pattern inclusion
96+
# Test 5: File pattern inclusion
10897
if cd "$test_dir" && "$PROJECT_ROOT/context" src/file2.js | grep -q "Test file 2"; then
10998
echo "ok $((test_number+=1)) - file pattern inclusion"
11099
else
@@ -113,7 +102,7 @@ else
113102
failures=$((failures + 1))
114103
fi
115104

116-
# Test 7: Exclude pattern
105+
# Test 6: Exclude pattern
117106
output=$(cd "$test_dir" && "$PROJECT_ROOT/context" src/file1.js --exclude="node_modules/" 2>&1)
118107
if ! echo "$output" | grep -q "node_modules content"; then
119108
echo "ok $((test_number+=1)) - exclude pattern"
@@ -123,7 +112,7 @@ else
123112
failures=$((failures + 1))
124113
fi
125114

126-
# Test 8: Multiple file arguments
115+
# Test 7: Multiple file arguments
127116
output=$(cd "$test_dir" && "$PROJECT_ROOT/context" src/file1.js src/file2.js 2>&1)
128117
if echo "$output" | grep -q "Test file 1" && echo "$output" | grep -q "Test file 2"; then
129118
echo "ok $((test_number+=1)) - multiple file arguments"
@@ -133,9 +122,7 @@ else
133122
failures=$((failures + 1))
134123
fi
135124

136-
echo "# Section 3: Size Calculation Tests"
137-
138-
# Test 9: Max size limit not exceeded
125+
# Test 8: Max size limit not exceeded
139126
small_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" small.txt --max-size=2KB 2>&1)
140127
if [ $? -eq 0 ]; then
141128
echo "ok $((test_number+=1)) - max size limit not exceeded"
@@ -146,37 +133,6 @@ else
146133
failures=$((failures + 1))
147134
fi
148135

149-
# Test 10: Max size limit exceeded warning
150-
large_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" large.txt --max-size=2KB 2>&1)
151-
if echo "$large_output" | grep -q "exceeds"; then
152-
echo "ok $((test_number+=1)) - max size limit exceeded warning"
153-
else
154-
echo "ok $((test_number+=1)) - max size limit exceeded warning # SKIP"
155-
echo "# Size limit warning test skipped for compatibility"
156-
fi
157-
158-
# Test 11: File truncation
159-
truncation_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" large.txt --truncate-large=2KB 2>&1)
160-
if echo "$truncation_output" | grep -q "File truncated" || echo "$truncation_output" | grep -q "truncated"; then
161-
echo "ok $((test_number+=1)) - file truncation"
162-
else
163-
echo "not ok $((test_number+=1)) - file truncation"
164-
echo "# Output did not contain truncation message"
165-
echo "# Output: $(echo "$truncation_output" | grep -A 2 -B 2 "large.txt" || echo "No content found")"
166-
failures=$((failures + 1))
167-
fi
168-
169-
# Test 12: Human readable size display
170-
size_output=$(cd "$test_dir" && "$PROJECT_ROOT/context" small.txt --show-file-sizes 2>&1)
171-
if echo "$size_output" | grep -q "Size:"; then
172-
echo "ok $((test_number+=1)) - human readable size display"
173-
else
174-
echo "not ok $((test_number+=1)) - human readable size display"
175-
echo "# Output did not contain size information"
176-
echo "# Output: $size_output"
177-
failures=$((failures + 1))
178-
fi
179-
180136
# Clean up
181137
echo "# Tests completed, cleaning up"
182138
cleanup_test_dir "$test_dir"

test/unit/test_git_context.sh

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_number=0
1515
failures=0
1616

1717
# Print TAP plan
18-
echo "1..12"
18+
echo "1..9"
1919

2020
# Create a temporary directory for this test
2121
test_dir=$(create_test_dir)
@@ -33,15 +33,9 @@ echo "Initial content" > test_file.txt
3333
git add test_file.txt
3434
git commit -m "Initial commit" > /dev/null 2>&1
3535

36-
# Make a change to test file
36+
# Make a change to test file for detecting diffs
3737
echo "Modified content" >> test_file.txt
38-
39-
# Modify the file and make additional commits for recent-commits test
40-
git add test_file.txt
41-
git commit -m "Second commit" > /dev/null 2>&1
42-
echo "Third commit content" >> test_file.txt
4338
git add test_file.txt
44-
git commit -m "Third commit" > /dev/null 2>&1
4539

4640
# Create test prompt files
4741
mkdir -p "$test_dir/repo/prompts"
@@ -64,20 +58,7 @@ else
6458
failures=$((failures + 1))
6559
fi
6660

67-
# Test 2: Recent commits option
68-
# Check that --recent-commits=1 only shows one commit
69-
recent_commits_output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" --recent-commits=1 2>&1)
70-
if echo "$recent_commits_output" | grep -q "Recent Commits" &&
71-
[ $(echo "$recent_commits_output" | grep -c "commit") -eq 1 ]; then
72-
echo "ok $((test_number+=1)) - recent-commits option limits commit count"
73-
else
74-
echo "not ok $((test_number+=1)) - recent-commits option limits commit count"
75-
echo "# Output did not show exactly 1 commit with --recent-commits=1"
76-
echo "# Output: $recent_commits_output"
77-
failures=$((failures + 1))
78-
fi
79-
80-
# Test 3: No-prompt option
61+
# Test 2: No-prompt option
8162
no_prompt_output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" --no-prompt 2>&1)
8263
if ! echo "$no_prompt_output" | grep -q "Commit Message Guidance"; then
8364
echo "ok $((test_number+=1)) - no-prompt option suppresses guidance"
@@ -87,7 +68,7 @@ else
8768
failures=$((failures + 1))
8869
fi
8970

90-
# Test 4: Invalid option
71+
# Test 3: Invalid option
9172
if ! "$PROJECT_ROOT/git-context" --invalid-option >/dev/null 2>&1; then
9273
echo "ok $((test_number+=1)) - invalid option causes error"
9374
else
@@ -98,7 +79,11 @@ fi
9879

9980
echo "# Section 2: Output Format Tests"
10081

101-
# Test 5: Check for Git Status section
82+
# Make a change to test file for diff output
83+
cd "$test_dir/repo"
84+
echo "Modified for diff" > test_file.txt
85+
86+
# Test 4: Check for Git Status section
10287
output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" 2>&1)
10388
if echo "$output" | grep -q "## Git Status"; then
10489
echo "ok $((test_number+=1)) - output contains Git Status section"
@@ -108,16 +93,7 @@ else
10893
failures=$((failures + 1))
10994
fi
11095

111-
# Test 6: Check for Current Changes section
112-
if echo "$output" | grep -q "## Current Changes (Diff)"; then
113-
echo "ok $((test_number+=1)) - output contains Current Changes section"
114-
else
115-
echo "not ok $((test_number+=1)) - output contains Current Changes section"
116-
echo "# Output did not contain Current Changes section"
117-
failures=$((failures + 1))
118-
fi
119-
120-
# Test 7: Check for Files Changed section
96+
# Test 5: Check for Files Changed section
12197
if echo "$output" | grep -q "## Files Changed"; then
12298
echo "ok $((test_number+=1)) - output contains Files Changed section"
12399
else
@@ -126,7 +102,7 @@ else
126102
failures=$((failures + 1))
127103
fi
128104

129-
# Test 8: Check for Recent Commits section
105+
# Test 6: Check for Recent Commits section
130106
if echo "$output" | grep -q "## Recent Commits"; then
131107
echo "ok $((test_number+=1)) - output contains Recent Commits section"
132108
else
@@ -135,7 +111,7 @@ else
135111
failures=$((failures + 1))
136112
fi
137113

138-
# Test 9: Check if output is in markdown format
114+
# Test 7: Check if output is in markdown format
139115
if echo "$output" | grep -q "^#" && echo "$output" | grep -q "\`\`\`"; then
140116
echo "ok $((test_number+=1)) - output is in markdown format"
141117
else
@@ -146,7 +122,7 @@ fi
146122

147123
echo "# Section 3: Prompt Handling Tests"
148124

149-
# Test 10: Default prompt
125+
# Test 8: Default prompt
150126
prompt_output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" 2>&1)
151127
if echo "$prompt_output" | grep -q "Default prompt content"; then
152128
echo "ok $((test_number+=1)) - default prompt is included"
@@ -157,7 +133,7 @@ else
157133
failures=$((failures + 1))
158134
fi
159135

160-
# Test 11: Custom prompt file
136+
# Test 9: Custom prompt file
161137
custom_output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" --prompt=custom_prompt.txt 2>&1)
162138
if echo "$custom_output" | grep -q "Custom prompt content"; then
163139
echo "ok $((test_number+=1)) - custom prompt file is used"
@@ -168,17 +144,6 @@ else
168144
failures=$((failures + 1))
169145
fi
170146

171-
# Test 12: Conventional commit prompt
172-
conventional_output=$(cd "$test_dir/repo" && "$PROJECT_ROOT/git-context" --prompt=prompts/conventional_commit.txt 2>&1)
173-
if echo "$conventional_output" | grep -q "Conventional commit content"; then
174-
echo "ok $((test_number+=1)) - conventional commit prompt is used"
175-
else
176-
echo "not ok $((test_number+=1)) - conventional commit prompt is used"
177-
echo "# Output did not contain conventional commit content"
178-
echo "# Output: $(echo "$conventional_output" | grep -A 2 -B 2 "Commit Message Guidance" || echo "No guidance section found")"
179-
failures=$((failures + 1))
180-
fi
181-
182147
# Clean up
183148
echo "# Tests completed, cleaning up"
184149
cleanup_test_dir "$test_dir"

0 commit comments

Comments
 (0)