Skip to content

Commit 0a9fb03

Browse files
Copilotjackfirth
andcommitted
Add CLI support for analyzer timeout and test demonstration
Co-authored-by: jackfirth <[email protected]>
1 parent 495198f commit 0a9fb03

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

cli.rkt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
(define-enum-type resyntax-output-format (plain-text github-pull-request-review git-commit-message json))
3939
(define-enum-type resyntax-fix-method (modify-files create-multiple-git-commits))
40-
(define-record-type resyntax-analyze-options (targets suite output-format output-destination))
40+
(define-record-type resyntax-analyze-options (targets suite output-format output-destination analyzer-timeout-ms))
4141

4242

4343
(define-record-type resyntax-fix-options
@@ -48,7 +48,8 @@
4848
max-fixes
4949
max-modified-files
5050
max-modified-lines
51-
max-pass-count))
51+
max-pass-count
52+
analyzer-timeout-ms))
5253

5354

5455
(define all-lines (range-set (unbounded-range #:comparator natural<=>)))
@@ -60,6 +61,7 @@
6061
(define selected-rule #false)
6162
(define output-format plain-text)
6263
(define output-destination 'console)
64+
(define analyzer-timeout-ms 10000)
6365

6466
(command-line
6567
#:program "resyntax analyze"
@@ -105,6 +107,11 @@ changed relative to baseref are analyzed."
105107
(define rule-sym (string->symbol rule-name))
106108
(set! selected-rule rule-sym))
107109

110+
("--analyzer-timeout"
111+
timeout-ms
112+
"The timeout in milliseconds for expansion analyzers. Defaults to 10000 (10 seconds)."
113+
(set! analyzer-timeout-ms (string->number timeout-ms)))
114+
108115
("--output-to-file"
109116
outputpath
110117
"Store results in a file instead of printing them to the console."
@@ -128,7 +135,8 @@ determined by the GITHUB_REPOSITORY and GITHUB_REF environment variables."
128135
#:targets (build-vector targets)
129136
#:suite suite
130137
#:output-format output-format
131-
#:output-destination output-destination))
138+
#:output-destination output-destination
139+
#:analyzer-timeout-ms analyzer-timeout-ms))
132140

133141

134142
(define (resyntax-fix-parse-command-line)
@@ -143,6 +151,7 @@ determined by the GITHUB_REPOSITORY and GITHUB_REF environment variables."
143151
(define max-pass-count 10)
144152
(define max-modified-files +inf.0)
145153
(define max-modified-lines +inf.0)
154+
(define analyzer-timeout-ms 10000)
146155

147156
(command-line
148157
#:program "resyntax fix"
@@ -197,6 +206,11 @@ changed relative to baseref are analyzed and fixed."
197206
(define rule-sym (string->symbol rule-name))
198207
(set! selected-rule rule-sym))
199208

209+
("--analyzer-timeout"
210+
timeout-ms
211+
"The timeout in milliseconds for expansion analyzers. Defaults to 10000 (10 seconds)."
212+
(set! analyzer-timeout-ms (string->number timeout-ms)))
213+
200214
("--max-pass-count"
201215
passcount
202216
"The maximum number of times Resyntax will fix each file. By default, Resyntax runs at most 10 \
@@ -235,7 +249,8 @@ are needed when applying a fix unlocks further fixes."
235249
#:max-fixes max-fixes
236250
#:max-modified-files max-modified-files
237251
#:max-modified-lines max-modified-lines
238-
#:max-pass-count max-pass-count))
252+
#:max-pass-count max-pass-count
253+
#:analyzer-timeout-ms analyzer-timeout-ms))
239254

240255

241256
(define (resyntax-run)
@@ -273,7 +288,8 @@ For help on these, use 'analyze --help' or 'fix --help'."
273288
(define analysis
274289
(resyntax-analyze-all sources
275290
#:suite (resyntax-analyze-options-suite options)
276-
#:max-passes 1))
291+
#:max-passes 1
292+
#:timeout-ms (resyntax-analyze-options-analyzer-timeout-ms options)))
277293
(define results
278294
(transduce (resyntax-analysis-all-results analysis)
279295
(append-mapping in-hash-values)
@@ -322,7 +338,8 @@ For help on these, use 'analyze --help' or 'fix --help'."
322338
#:max-fixes (resyntax-fix-options-max-fixes options)
323339
#:max-passes (resyntax-fix-options-max-pass-count options)
324340
#:max-modified-sources max-modified-files
325-
#:max-modified-lines max-modified-lines))
341+
#:max-modified-lines max-modified-lines
342+
#:timeout-ms (resyntax-fix-options-analyzer-timeout-ms options)))
326343
(match fix-method
327344
[(== modify-files)
328345
(resyntax-analysis-write-file-changes! analysis)]

main.rkt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#:max-fixes (or/c exact-nonnegative-integer? +inf.0)
2525
#:max-passes exact-nonnegative-integer?
2626
#:max-modified-sources (or/c exact-nonnegative-integer? +inf.0)
27-
#:max-modified-lines (or/c exact-nonnegative-integer? +inf.0))
27+
#:max-modified-lines (or/c exact-nonnegative-integer? +inf.0)
28+
#:timeout-ms exact-nonnegative-integer?)
2829
resyntax-analysis?)]
2930
[reysntax-analyze-for-properties-only
3031
(->* (source?) (#:suite refactoring-suite? #:timeout-ms exact-nonnegative-integer?) syntax-property-bundle?)]
@@ -265,7 +266,8 @@
265266
#:max-fixes [max-fixes +inf.0]
266267
#:max-passes [max-passes 10]
267268
#:max-modified-sources [max-modified-sources +inf.0]
268-
#:max-modified-lines [max-modified-lines +inf.0])
269+
#:max-modified-lines [max-modified-lines +inf.0]
270+
#:timeout-ms [timeout-ms 10000])
269271
(log-resyntax-info "--- analyzing code ---")
270272
(for/fold ([pass-result-lists '()]
271273
[sources sources]
@@ -279,7 +281,8 @@
279281
#:suite suite
280282
#:max-fixes max-fixes
281283
#:max-modified-sources max-modified-sources
282-
#:max-modified-lines max-modified-lines))
284+
#:max-modified-lines max-modified-lines
285+
#:timeout-ms timeout-ms))
283286
(define pass-fix-count (count-total-results pass-results))
284287
(define new-max-fixes (- max-fixes pass-fix-count))]
285288
#:break (hash-empty? pass-results)
@@ -303,7 +306,8 @@
303306
#:suite suite
304307
#:max-fixes max-fixes
305308
#:max-modified-sources max-modified-sources
306-
#:max-modified-lines max-modified-lines)
309+
#:max-modified-lines max-modified-lines
310+
#:timeout-ms timeout-ms)
307311
(transduce (in-hash-entries sources) ; entries with source keys and line range set values
308312

309313
;; The following steps perform a kind of layered shuffle: the files to refactor are
@@ -331,7 +335,7 @@
331335
(append-mapping
332336
(λ (e)
333337
(match-define (entry source lines) e)
334-
(define result-set (resyntax-analyze source #:suite suite #:lines lines))
338+
(define result-set (resyntax-analyze source #:suite suite #:lines lines #:timeout-ms timeout-ms))
335339
(refactoring-result-set-results result-set)))
336340
(limiting max-modified-lines
337341
#:by (λ (result)
@@ -529,6 +533,7 @@
529533
;; Test with multipass analyze
530534
(define analysis
531535
(resyntax-analyze-all (hash test-source (range-set (unbounded-range #:comparator natural<=>)))
532-
#:suite breaking-suite))
536+
#:suite breaking-suite
537+
#:timeout-ms 10000))
533538
(check-equal? (resyntax-analysis-total-fixes analysis) 0
534539
"Breaking suggestions should be filtered from resyntax-analyze-all")))

test.rkt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,19 @@
149149
#:with (id ...) (list #'current-line-mask)
150150
#:with (value ...) (list #'line-set))
151151

152-
(pattern (~seq (#:option #:analyzer-timeout-millis timeout:number))
152+
(pattern (~seq (#:option #:analyzer-timeout-millis timeout-value:number))
153153
#:with (id ...) (list #'current-analyzer-timeout-millis)
154-
#:with (value ...) (list #'timeout))
154+
#:with (value ...) (list #`'#,(syntax-e #'timeout-value)))
155155

156156
(pattern (~seq (#:option #:lines (~and line-set (#:range-set _ ...)))
157-
(#:option #:analyzer-timeout-millis timeout:number))
157+
(#:option #:analyzer-timeout-millis timeout-value:number))
158158
#:with (id ...) (list #'current-line-mask #'current-analyzer-timeout-millis)
159-
#:with (value ...) (list #'line-set #'timeout))
159+
#:with (value ...) (list #'line-set #`'#,(syntax-e #'timeout-value)))
160160

161-
(pattern (~seq (#:option #:analyzer-timeout-millis timeout:number)
161+
(pattern (~seq (#:option #:analyzer-timeout-millis timeout-value:number)
162162
(#:option #:lines (~and line-set (#:range-set _ ...))))
163163
#:with (id ...) (list #'current-analyzer-timeout-millis #'current-line-mask)
164-
#:with (value ...) (list #'timeout #'line-set)))
164+
#:with (value ...) (list #`'#,(syntax-e #'timeout-value) #'line-set)))
165165

166166
(define-splicing-syntax-class code-block-test-args
167167
#:attributes ([check 1])

test/analyzer-timeout-test.rkt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#lang resyntax/test
2+
3+
4+
header:
5+
------------------------------
6+
#lang racket/base
7+
------------------------------
8+
9+
10+
test: "timeout parameter can be customized in tests"
11+
@analyzer-timeout-millis 5000
12+
- (or 1 (or 2 3))
13+
- (or 1 2 3)
14+
15+
16+
no-change-test: "timeout parameter works with no-change-test"
17+
@analyzer-timeout-millis 5000
18+
- (define x 42)

0 commit comments

Comments
 (0)