Commit 72525b6
fix: Prevent early exit in directory comparison with --exit-code flag
**Issue**: When using --exit-code flag with directory comparison, the
program would exit immediately upon finding the first file with
differences, preventing comparison of remaining files and display of
the summary.
**Root Cause**: Both compareFiles() and compareDirectories() were
calling os.Exit(1) directly when --exit-code was set and changes were
found. When compareFiles() was called from compareDirectories(), this
caused premature termination.
**Previous Behavior**:
1. Start comparing directory files
2. First file with differences triggers os.Exit(1) in compareFiles()
3. Program terminates immediately
4. Remaining files never compared
5. Summary never displayed
**Fixed Behavior**:
1. All files are compared
2. Summary is displayed
3. Then exit with code 1 if any changes were found
**Changes**:
- Refactored compareFiles() to return bool indicating if changes found
- Refactored compareDirectories() to return bool indicating if changes found
- Moved exit code handling to compare() function (main entry point)
- Both functions now return results instead of calling os.Exit directly
- The compare() function aggregates results and handles os.Exit
**Tests Added**:
- TestCompareFilesReturnValue: Verifies compareFiles returns correct boolean
- TestDirectoryComparisonDoesNotExitEarly: Ensures all files are compared
before exit, even with --exit-code flag set
**Verification**:
- All existing tests pass
- New tests verify the fix
- Manual testing confirms all files compared before exit
- Coverage remains above threshold (84.1%)
Fixes issue #2 from PR review comments.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 9d34e3f commit 72525b6
2 files changed
+154
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
| |||
33 | 43 | | |
34 | 44 | | |
35 | 45 | | |
36 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
37 | 57 | | |
38 | 58 | | |
39 | | - | |
40 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
41 | 62 | | |
42 | 63 | | |
43 | 64 | | |
| |||
64 | 85 | | |
65 | 86 | | |
66 | 87 | | |
67 | | - | |
| 88 | + | |
68 | 89 | | |
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
72 | 93 | | |
73 | | - | |
| 94 | + | |
74 | 95 | | |
75 | 96 | | |
76 | 97 | | |
77 | 98 | | |
78 | 99 | | |
79 | | - | |
| 100 | + | |
80 | 101 | | |
81 | 102 | | |
82 | 103 | | |
83 | 104 | | |
84 | 105 | | |
85 | | - | |
| 106 | + | |
86 | 107 | | |
87 | 108 | | |
88 | 109 | | |
| |||
92 | 113 | | |
93 | 114 | | |
94 | 115 | | |
95 | | - | |
| 116 | + | |
96 | 117 | | |
97 | 118 | | |
98 | 119 | | |
| |||
105 | 126 | | |
106 | 127 | | |
107 | 128 | | |
108 | | - | |
| 129 | + | |
109 | 130 | | |
110 | 131 | | |
111 | 132 | | |
112 | 133 | | |
113 | 134 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 135 | + | |
| 136 | + | |
120 | 137 | | |
121 | 138 | | |
122 | | - | |
123 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
124 | 142 | | |
125 | 143 | | |
126 | 144 | | |
127 | | - | |
| 145 | + | |
128 | 146 | | |
129 | 147 | | |
130 | 148 | | |
131 | 149 | | |
132 | | - | |
| 150 | + | |
133 | 151 | | |
134 | 152 | | |
135 | 153 | | |
| |||
163 | 181 | | |
164 | 182 | | |
165 | 183 | | |
166 | | - | |
| 184 | + | |
167 | 185 | | |
168 | 186 | | |
169 | 187 | | |
170 | 188 | | |
171 | 189 | | |
172 | 190 | | |
173 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
174 | 195 | | |
175 | 196 | | |
176 | 197 | | |
| |||
195 | 216 | | |
196 | 217 | | |
197 | 218 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 219 | + | |
| 220 | + | |
204 | 221 | | |
205 | 222 | | |
206 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
229 | | - | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
0 commit comments