-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_config_parser.sh
More file actions
executable file
·295 lines (250 loc) · 8.01 KB
/
Copy pathverify_config_parser.sh
File metadata and controls
executable file
·295 lines (250 loc) · 8.01 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# Verification script for TOML-based configuration parser
# This script tests the configuration parser implementation
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counter
TESTS_PASSED=0
TESTS_FAILED=0
# Function to print test result
print_result() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}✓${NC} $2"
((TESTS_PASSED++))
else
echo -e "${RED}✗${NC} $2"
((TESTS_FAILED++))
fi
}
# Function to print section header
print_section() {
echo ""
echo -e "${YELLOW}==>${NC} $1"
echo ""
}
# Print banner
echo "=========================================="
echo "FloatWM Config Parser Verification"
echo "=========================================="
# Check if Rust/Cargo is available
if ! command -v cargo &> /dev/null; then
echo -e "${RED}Error: cargo not found${NC}"
echo "This script requires Rust and Cargo to be installed."
exit 1
fi
# Build the project
print_section "Building FloatWM with config-support feature"
if cargo build --features config-support 2>&1 | tee build.log; then
print_result 0 "Build successful"
else
print_result 1 "Build failed"
echo "Check build.log for details"
exit 1
fi
# Run unit tests
print_section "Running configuration parser unit tests"
if cargo test config_parser --features config-support 2>&1 | tee test_output.log; then
print_result 0 "Unit tests passed"
else
print_result 1 "Unit tests failed"
echo "Check test_output.log for details"
fi
# Test loading default config
print_section "Testing default configuration loading"
cat > /tmp/test_default_config.rs << 'EOF'
use floatwm::config::Config;
fn main() {
let config = Config::default();
println!("Default config loaded successfully");
println!("Focus behavior: {:?}", config.focus_behavior);
println!("Spatial enabled: {}", config.spatial_settings.enabled);
println!("Keybindings: {} terminal bindings", config.keybindings.spawn_terminal.len());
}
EOF
if cargo run --example test_default_config --features config-support 2>&1 | grep -q "Default config loaded"; then
print_result 0 "Default configuration test passed"
else
print_result 1 "Default configuration test failed"
fi
# Test TOML parsing
print_section "Testing TOML configuration parsing"
# Create a test config file
TEST_CONFIG_DIR="/tmp/floatwm_test_config"
TEST_CONFIG_FILE="$TEST_CONFIG_DIR/floatwm.toml"
mkdir -p "$TEST_CONFIG_DIR"
cat > "$TEST_CONFIG_FILE" << 'EOF'
[spatial_settings]
enabled = true
sensitivity = 2.5
max_range = 300
smoothing = 0.7
[keybindings]
spawn_terminal = ["Super+Return", "Control+Shift+Enter"]
close_window = ["Super+Shift+q"]
move_left = ["Super+h"]
move_right = ["Super+l"]
move_up = ["Super+k"]
move_down = ["Super+j"]
toggle_spatial = ["Super+s"]
[[window_rules]]
class = "Firefox"
position = [100, 100]
size = [1920, 1080]
float = true
[[window_rules]]
class = "Terminal"
workspace = 2
EOF
# Create a test program to load the config
cat > /tmp/test_load_config.rs << EOF
use floatwm::config::Config;
fn main() {
match Config::load_from_path("$TEST_CONFIG_FILE") {
Ok(config) => {
println!("Config loaded successfully");
println!("Spatial enabled: {}", config.spatial_settings.enabled);
println!("Sensitivity: {}", config.spatial_settings.sensitivity);
println!("Keybindings: {} terminal bindings", config.keybindings.spawn_terminal.len());
println!("Window rules: {}", config.window_rules.len());
assert_eq!(config.spatial_settings.enabled, true);
assert_eq!(config.spatial_settings.sensitivity, 2.5);
assert_eq!(config.window_rules.len(), 2);
}
Err(e) => {
eprintln!("Failed to load config: {}", e);
std::process::exit(1);
}
}
}
EOF
if cargo run --example test_load_config --features config-support 2>&1 | grep -q "Config loaded successfully"; then
print_result 0 "TOML parsing test passed"
else
print_result 1 "TOML parsing test failed"
fi
# Test validation - invalid sensitivity
print_section "Testing configuration validation"
cat > "$TEST_CONFIG_FILE" << 'EOF'
[spatial_settings]
sensitivity = 15.0
EOF
cat > /tmp/test_validation.rs << EOF
use floatwm::config::Config;
fn main() {
match Config::load_from_path("$TEST_CONFIG_FILE") {
Ok(_) => {
eprintln!("Should have failed validation");
std::process::exit(1);
}
Err(_) => {
println!("Validation correctly rejected invalid config");
}
}
}
EOF
if cargo run --example test_validation --features config-support 2>&1 | grep -q "Validation correctly rejected"; then
print_result 0 "Validation test passed"
else
print_result 1 "Validation test failed"
fi
# Test config saving
print_section "Testing configuration saving"
cat > /tmp/test_save_config.rs << EOF
use floatwm::config::Config;
fn main() {
let mut config = Config::default();
config.spatial_settings.enabled = true;
config.spatial_settings.sensitivity = 2.0;
let save_path = "/tmp/floatwm_save_test/config.toml";
match config.save_to_path(save_path) {
Ok(_) => {
println!("Config saved successfully");
// Load it back
match Config::load_from_path(save_path) {
Ok(loaded) => {
assert_eq!(loaded.spatial_settings.enabled, true);
assert_eq!(loaded.spatial_settings.sensitivity, 2.0);
println!("Config loaded back successfully");
}
Err(e) => {
eprintln!("Failed to load saved config: {}", e);
std::process::exit(1);
}
}
}
Err(e) => {
eprintln!("Failed to save config: {}", e);
std::process::exit(1);
}
}
}
EOF
if cargo run --example test_save_config --features config-support 2>&1 | grep -q "Config loaded back successfully"; then
print_result 0 "Config save/load test passed"
else
print_result 1 "Config save/load test failed"
fi
# Test example configuration file
print_section "Testing example configuration file"
if [ -f "docs/floatwm.toml.example" ]; then
if cargo run --example basic_usage --features config-support 2>&1 | grep -q "FloatWM Configuration"; then
print_result 0 "Example config is valid"
else
print_result 1 "Example config test failed"
fi
else
print_result 1 "Example config file not found"
fi
# Test XDG_CONFIG_HOME support
print_section "Testing XDG_CONFIG_HOME support"
export XDG_CONFIG_HOME="/tmp/test_xdg_config"
cat > /tmp/test_xdg_path.rs << 'EOF'
use floatwm::config::Config;
use std::path::PathBuf;
fn main() {
let path = Config::config_path();
assert!(path.to_str().unwrap().contains("test_xdg_config"));
println!("XDG_CONFIG_HOME path: {:?}", path);
}
EOF
if XDG_CONFIG_HOME="/tmp/test_xdg_custom" cargo run --example test_xdg_path --features config-support 2>&1 | grep -q "test_xdg_custom"; then
print_result 0 "XDG_CONFIG_HOME support works"
else
print_result 1 "XDG_CONFIG_HOME support test failed"
fi
# Test documentation
print_section "Checking documentation"
if [ -f "docs/config_parser.md" ]; then
print_result 0 "Config parser documentation exists"
else
print_result 1 "Config parser documentation missing"
fi
if [ -f "docs/floatwm.toml.example" ]; then
print_result 0 "Example configuration file exists"
else
print_result 1 "Example configuration file missing"
fi
# Cleanup
print_section "Cleaning up test files"
rm -rf "$TEST_CONFIG_DIR"
rm -f /tmp/test_*.rs
rm -f build.log test_output.log
# Print summary
echo ""
echo "=========================================="
echo "Verification Summary"
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