-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·242 lines (203 loc) · 6.94 KB
/
test.sh
File metadata and controls
executable file
·242 lines (203 loc) · 6.94 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/bash
# Comprehensive test script for Copybuffer
# This script tests all major features to ensure they work correctly
# Don't exit on error - we want to count failures
# set -e # Exit on error
echo "======================================"
echo " Copybuffer Comprehensive Test"
echo "======================================"
echo ""
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counter
TESTS_PASSED=0
TESTS_FAILED=0
# Function to run a test
run_test() {
local test_name="$1"
local command="$2"
echo -n "Testing: $test_name... "
if eval "$command" > /tmp/test_output.log 2>&1; then
echo -e "${GREEN}PASSED${NC}"
((TESTS_PASSED++))
else
echo -e "${RED}FAILED${NC}"
echo " Error output:"
cat /tmp/test_output.log | head -5
((TESTS_FAILED++))
fi
}
# Function to verify output contains text
verify_output() {
local test_name="$1"
local command="$2"
local expected="$3"
echo -n "Testing: $test_name... "
if eval "$command" 2>&1 | grep -q "$expected"; then
echo -e "${GREEN}PASSED${NC}"
((TESTS_PASSED++))
else
echo -e "${RED}FAILED${NC}"
echo " Expected to find: $expected"
((TESTS_FAILED++))
fi
}
# Ensure clean state
rm -rf ~/.copybuffer
rm -f /tmp/test-*.json
echo "1. Build Tests"
echo "--------------"
run_test "TypeScript compilation" "npm run build"
run_test "ESLint validation" "npm run lint"
echo ""
echo "2. CLI Tests"
echo "------------"
run_test "CLI help command" "node dist/cli.js --help"
run_test "CLI version command" "node dist/cli.js --version"
verify_output "Status command shows in help" "node dist/cli.js --help" "status"
echo ""
echo "3. Status Tests"
echo "--------------"
verify_output "Status when not running" "node dist/cli.js status" "not running"
echo ""
echo "4. Configuration Tests"
echo "---------------------"
verify_output "Default config creation" "node dist/cli.js config" "dataDir"
verify_output "Config contains maxHistorySize" "node dist/cli.js config" "maxHistorySize"
verify_output "Config contains hotkeys" "node dist/cli.js config" "hotkeys"
run_test "Set config value" "node dist/cli.js config-set maxHistorySize 500"
verify_output "Verify config update" "node dist/cli.js config" '"maxHistorySize": "500"'
echo ""
echo "5. Storage Tests"
echo "---------------"
# Create test data
cat > /tmp/test-import.json << 'EOF'
[
{
"id": "test-001",
"content": "Test entry 1",
"timestamp": 1698601200000,
"type": "text"
},
{
"id": "test-002",
"content": "Test entry 2 with keyword",
"timestamp": 1698601260000,
"type": "text"
},
{
"id": "test-003",
"content": "Another test entry",
"timestamp": 1698601320000,
"type": "text",
"tags": ["test", "example"]
}
]
EOF
run_test "Import history" "node dist/cli.js import /tmp/test-import.json"
verify_output "List shows entries" "node dist/cli.js list" "Test entry 1"
run_test "Export history" "node dist/cli.js export /tmp/test-export.json"
run_test "Exported file exists" "test -f /tmp/test-export.json"
echo ""
echo "6. Search Tests"
echo "--------------"
verify_output "Search finds entry" "node dist/cli.js search 'keyword'" "Test entry 2"
verify_output "Search with limit" "node dist/cli.js search 'test' --limit 2" "Test entry"
verify_output "Search no results" "node dist/cli.js search 'nonexistent'" "No results found"
echo ""
echo "7. Delete Tests"
echo "--------------"
run_test "Delete entry" "node dist/cli.js delete test-001"
verify_output "Entry deleted" "node dist/cli.js search 'Test entry 1'" "No results found"
echo ""
echo "8. List Tests"
echo "------------"
verify_output "List default limit" "node dist/cli.js list" "Showing"
verify_output "List with custom limit" "node dist/cli.js list --limit 5" "Showing"
echo ""
echo "9. Clear Tests"
echo "-------------"
run_test "Clear history" "node dist/cli.js clear --yes"
verify_output "History cleared" "node dist/cli.js list" "No clipboard history found"
echo ""
echo "10. File Structure Tests"
echo "----------------------"
run_test "Config directory exists" "test -d ~/.copybuffer"
run_test "Config file exists" "test -f ~/.copybuffer/config.json"
run_test "History file exists" "test -f ~/.copybuffer/history.json"
echo ""
echo "11. Module Tests"
echo "---------------"
# Create a simple test script to verify imports
cat > /tmp/test-imports.js << 'EOF'
const path = require('path');
const projectDir = '/home/runner/work/Copybuffer/Copybuffer';
const { storageManager, searchManager, configManager } = require(path.join(projectDir, 'dist/exports'));
// Test that modules export correctly
console.log('storageManager:', typeof storageManager);
console.log('searchManager:', typeof searchManager);
console.log('configManager:', typeof configManager);
// Test basic functionality
const config = configManager.getConfig();
console.log('Config loaded:', config.dataDir ? 'yes' : 'no');
const history = storageManager.loadHistory();
console.log('History loaded:', Array.isArray(history) ? 'yes' : 'no');
const recent = searchManager.getRecent(10);
console.log('Recent retrieved:', Array.isArray(recent) ? 'yes' : 'no');
EOF
run_test "Module imports work" "node /tmp/test-imports.js"
echo ""
echo "12. Hotkey Manager Tests"
echo "------------------------"
# Create a test script to verify hotkey manager handles unsupported OS gracefully
cat > /tmp/test-hotkey.js << 'EOF'
const path = require('path');
const projectDir = '/home/runner/work/Copybuffer/Copybuffer';
const { hotkeyManager } = require(path.join(projectDir, 'dist/hotkeys/HotkeyManager'));
// Capture console output
let consoleOutput = '';
const originalLog = console.log;
console.log = (...args) => {
consoleOutput += args.join(' ') + '\n';
originalLog(...args);
};
// Test initialization (should not throw)
try {
hotkeyManager.initialize();
// Check if initialization failed gracefully
if (consoleOutput.includes('could not be initialized') ||
consoleOutput.includes('initialized') ||
consoleOutput.includes('requires X11 display server')) {
console.log = originalLog;
console.log('Hotkey manager handled initialization correctly');
process.exit(0);
} else {
console.log = originalLog;
console.error('Unexpected console output:', consoleOutput);
process.exit(1);
}
} catch (error) {
console.log = originalLog;
console.error('Hotkey manager should not throw errors during initialization:', error);
process.exit(1);
}
EOF
run_test "Hotkey manager initialization gracefully handles unsupported OS" "node /tmp/test-hotkey.js"
echo ""
echo "======================================"
echo " Test Summary"
echo "======================================"
echo ""
echo -e "Tests Passed: ${GREEN}${TESTS_PASSED}${NC}"
echo -e "Tests Failed: ${RED}${TESTS_FAILED}${NC}"
echo ""
if [ $TESTS_FAILED -eq 0 ]; then
echo -e "${GREEN}All tests passed!${NC}"
exit 0
else
echo -e "${RED}Some tests failed!${NC}"
exit 1
fi