|
59 | 59 | ;; filename is a string naming a file that should be typed into the dialog
|
60 | 60 | (define (use-get/put-dialog open-dialog filename)
|
61 | 61 | (not-on-eventspace-handler-thread 'use-get/put-dialog)
|
62 |
| - (let ([drs (wait-for-drracket-frame)]) |
63 |
| - (with-handlers ([(lambda (x) #t) |
64 |
| - (lambda (x) |
65 |
| - (fw:preferences:set 'framework:file-dialogs 'std) |
66 |
| - (raise x))]) |
67 |
| - (fw:preferences:set 'framework:file-dialogs 'common) |
68 |
| - (open-dialog) |
69 |
| - (let ([dlg (wait-for-new-frame drs)]) |
70 |
| - (send (find-labelled-window "Filename:" #f (fw:test:get-active-top-level-window)) focus) |
71 |
| - (fw:test:keystroke #\a (list (case (system-type) |
72 |
| - [(windows) 'control] |
73 |
| - [(macosx macos) 'meta] |
74 |
| - [(unix) 'control] |
75 |
| - [else (error 'use-get/put-dialog "unknown platform: ~s\n" |
76 |
| - (system-type))]))) |
77 |
| - (for-each fw:test:keystroke (string->list (path->string filename))) |
78 |
| - (fw:test:button-push "OK") |
79 |
| - (wait-for-new-frame dlg)) |
80 |
| - (fw:preferences:set 'framework:file-dialogs 'std)))) |
| 62 | + (define drs (wait-for-drracket-frame)) |
| 63 | + (with-handlers ([(lambda (x) #t) (lambda (x) |
| 64 | + (fw:preferences:set 'framework:file-dialogs 'std) |
| 65 | + (raise x))]) |
| 66 | + (fw:preferences:set 'framework:file-dialogs 'common) |
| 67 | + (open-dialog) |
| 68 | + (let ([dlg (wait-for-new-frame drs)]) |
| 69 | + (send (find-labelled-window "Filename:" #f (fw:test:get-active-top-level-window)) focus) |
| 70 | + (fw:test:keystroke |
| 71 | + #\a |
| 72 | + (list (case (system-type) |
| 73 | + [(windows) 'control] |
| 74 | + [(macosx macos) 'meta] |
| 75 | + [(unix) 'control] |
| 76 | + [else (error 'use-get/put-dialog "unknown platform: ~s\n" (system-type))]))) |
| 77 | + (for-each fw:test:keystroke (string->list (path->string filename))) |
| 78 | + (fw:test:button-push "OK") |
| 79 | + (wait-for-new-frame dlg)) |
| 80 | + (fw:preferences:set 'framework:file-dialogs 'std))) |
81 | 81 |
|
82 | 82 | (define (test-util-error fmt . args)
|
83 | 83 | (raise (make-exn (apply fmt args) (current-continuation-marks))))
|
|
180 | 180 |
|
181 | 181 | (define (verify-drracket-frame-frontmost function-name frame)
|
182 | 182 | (on-eventspace-handler-thread 'verify-drracket-frame-frontmost)
|
183 |
| - (let ([tl (fw:test:get-active-top-level-window)]) |
184 |
| - (unless (and (eq? frame tl) |
185 |
| - (drracket-frame? tl)) |
186 |
| - (error function-name "drracket frame not frontmost: ~e (found ~e)" frame tl)))) |
| 183 | + (define tl (fw:test:get-active-top-level-window)) |
| 184 | + (unless (and (eq? frame tl) (drracket-frame? tl)) |
| 185 | + (error function-name "drracket frame not frontmost: ~e (found ~e)" frame tl))) |
187 | 186 |
|
188 | 187 | (define (clear-definitions frame)
|
189 | 188 | (queue-callback/res (λ () (verify-drracket-frame-frontmost 'clear-definitions frame)))
|
190 | 189 | (fw:test:new-window (queue-callback/res (λ () (send frame get-definitions-canvas))))
|
191 | 190 | (let ([window (queue-callback/res (λ () (send frame get-edit-target-window)))])
|
192 |
| - (let-values ([(cw ch) (queue-callback/res (λ () (send window get-client-size)))] |
193 |
| - [(w h) (queue-callback/res (λ () (send window get-size)))]) |
194 |
| - (fw:test:mouse-click 'left |
195 |
| - (inexact->exact (floor (+ cw (/ (- w cw) 2)))) |
196 |
| - (inexact->exact (floor (+ ch (/ (- h ch) 2))))))) |
| 191 | + (define-values (cw ch) (queue-callback/res (λ () (send window get-client-size)))) |
| 192 | + (define-values (w h) (queue-callback/res (λ () (send window get-size)))) |
| 193 | + (fw:test:mouse-click 'left |
| 194 | + (inexact->exact (floor (+ cw (/ (- w cw) 2)))) |
| 195 | + (inexact->exact (floor (+ ch (/ (- h ch) 2)))))) |
197 | 196 | (fw:test:menu-select "Edit" "Select All")
|
198 | 197 | (fw:test:menu-select "Edit" (if (eq? (system-type) 'macos)
|
199 | 198 | "Clear"
|
|
216 | 215 | (not-on-eventspace-handler-thread 'put-in-frame)
|
217 | 216 | (unless (and (object? frame) (is-a? frame top-level-window<%>))
|
218 | 217 | (error who "expected a frame or a dialog as the first argument, got ~e" frame))
|
219 |
| - (let ([str (if (string? str/sexp) |
220 |
| - str/sexp |
221 |
| - (let ([port (open-output-string)]) |
222 |
| - (parameterize ([current-output-port port]) |
223 |
| - (write str/sexp port)) |
224 |
| - (get-output-string port)))]) |
225 |
| - (queue-callback/res (λ () (verify-drracket-frame-frontmost who frame))) |
226 |
| - (let ([canvas (queue-callback/res (λ () (get-canvas frame)))]) |
227 |
| - (fw:test:new-window canvas) |
228 |
| - (let ([editor (queue-callback/res (λ () (send canvas get-editor)))]) |
229 |
| - (cond |
230 |
| - [just-insert? |
231 |
| - (let ([s (make-semaphore 0)]) |
232 |
| - (queue-callback |
233 |
| - (λ () |
234 |
| - (send editor set-caret-owner #f) |
235 |
| - (send editor insert str) |
236 |
| - (semaphore-post s))) |
237 |
| - (unless (sync/timeout 3 s) |
238 |
| - (error who "callback didn't run for 3 seconds; trying to insert ~s" str/sexp)))] |
239 |
| - [else |
240 |
| - (queue-callback/res (λ () (send editor set-caret-owner #f))) |
241 |
| - (type-string str)]))))) |
| 218 | + (define str |
| 219 | + (if (string? str/sexp) |
| 220 | + str/sexp |
| 221 | + (let ([port (open-output-string)]) |
| 222 | + (parameterize ([current-output-port port]) |
| 223 | + (write str/sexp port)) |
| 224 | + (get-output-string port)))) |
| 225 | + (queue-callback/res (λ () (verify-drracket-frame-frontmost who frame))) |
| 226 | + (define canvas (queue-callback/res (λ () (get-canvas frame)))) |
| 227 | + (fw:test:new-window canvas) |
| 228 | + (define editor (queue-callback/res (λ () (send canvas get-editor)))) |
| 229 | + (cond |
| 230 | + [just-insert? |
| 231 | + (let ([s (make-semaphore 0)]) |
| 232 | + (queue-callback (λ () |
| 233 | + (send editor set-caret-owner #f) |
| 234 | + (send editor insert str) |
| 235 | + (semaphore-post s))) |
| 236 | + (unless (sync/timeout 3 s) |
| 237 | + (error who "callback didn't run for 3 seconds; trying to insert ~s" str/sexp)))] |
| 238 | + [else |
| 239 | + (queue-callback/res (λ () (send editor set-caret-owner #f))) |
| 240 | + (type-string str)])) |
242 | 241 |
|
243 | 242 | (define (alt-return-in-interactions frame)
|
244 | 243 | (not-on-eventspace-handler-thread 'alt-return-in-interactions)
|
245 | 244 | (queue-callback/res (λ () (verify-drracket-frame-frontmost 'alt-return-in-interactions frame)))
|
246 |
| - (let ([canvas (send frame get-interactions-canvas)]) |
247 |
| - (fw:test:new-window canvas) |
248 |
| - (let ([editor (send canvas get-editor)]) |
249 |
| - (send editor set-caret-owner #f) |
250 |
| - (fw:test:keystroke #\return '(alt))))) |
| 245 | + (define canvas (send frame get-interactions-canvas)) |
| 246 | + (fw:test:new-window canvas) |
| 247 | + (define editor (send canvas get-editor)) |
| 248 | + (send editor set-caret-owner #f) |
| 249 | + (fw:test:keystroke #\return '(alt))) |
251 | 250 |
|
252 | 251 | ;; type-string : string -> void
|
253 | 252 | ;; to call test:keystroke repeatedly with the characters
|
254 | 253 | (define (type-string str)
|
255 | 254 | (not-on-eventspace-handler-thread 'type-string)
|
256 |
| - (let ([len (string-length str)]) |
257 |
| - (let loop ([i 0]) |
258 |
| - (unless (>= i len) |
259 |
| - (let ([c (string-ref str i)]) |
260 |
| - (fw:test:keystroke |
261 |
| - (if (char=? c #\newline) |
262 |
| - #\return |
263 |
| - c))) |
264 |
| - (loop (+ i 1)))))) |
| 255 | + (define len (string-length str)) |
| 256 | + (let loop ([i 0]) |
| 257 | + (unless (>= i len) |
| 258 | + (let ([c (string-ref str i)]) (fw:test:keystroke (if (char=? c #\newline) #\return c))) |
| 259 | + (loop (+ i 1))))) |
265 | 260 |
|
266 | 261 | (define wait
|
267 | 262 | (case-lambda
|
|
309 | 304 |
|
310 | 305 | (define (get-text-pos text)
|
311 | 306 | (on-eventspace-handler-thread 'get-text-pos)
|
312 |
| - (let* ([last-pos (send text last-position)] |
313 |
| - [last-line (send text position-line last-pos)]) |
314 |
| - (send text line-start-position last-line))) |
| 307 | + (define last-pos (send text last-position)) |
| 308 | + (define last-line (send text position-line last-pos)) |
| 309 | + (send text line-start-position last-line)) |
315 | 310 |
|
316 | 311 | ; poll for enabled button
|
317 | 312 |
|
|
430 | 425 |
|
431 | 426 | (define (set-module-language! [close-dialog? #t])
|
432 | 427 | (not-on-eventspace-handler-thread 'set-module-language!)
|
433 |
| - (let ([drs-frame (fw:test:get-active-top-level-window)]) |
434 |
| - (fw:test:menu-select "Language" "Choose Language…") |
435 |
| - (let* ([language-dialog (wait-for-new-frame drs-frame)]) |
436 |
| - (fw:test:set-radio-box-item! #rx"The Racket Language") |
437 |
| - |
438 |
| - (with-handlers ([exn:fail? (lambda (x) (void))]) |
439 |
| - (fw:test:button-push "Show Details")) |
440 |
| - |
441 |
| - (fw:test:button-push "Revert to Language Defaults") |
442 |
| - |
443 |
| - (when close-dialog? |
444 |
| - (fw:test:button-push "OK") |
445 |
| - (let ([new-frame (wait-for-new-frame language-dialog)]) |
446 |
| - (unless (eq? new-frame drs-frame) |
447 |
| - (error 'set-module-language! |
448 |
| - "didn't get drracket frame back, got: ~s (drs-frame ~s)\n" |
449 |
| - new-frame |
450 |
| - drs-frame))))))) |
| 428 | + (define drs-frame (fw:test:get-active-top-level-window)) |
| 429 | + (fw:test:menu-select "Language" "Choose Language…") |
| 430 | + (define language-dialog (wait-for-new-frame drs-frame)) |
| 431 | + (fw:test:set-radio-box-item! #rx"The Racket Language") |
| 432 | + |
| 433 | + (with-handlers ([exn:fail? (lambda (x) (void))]) |
| 434 | + (fw:test:button-push "Show Details")) |
| 435 | + |
| 436 | + (fw:test:button-push "Revert to Language Defaults") |
| 437 | + |
| 438 | + (when close-dialog? |
| 439 | + (fw:test:button-push "OK") |
| 440 | + (let ([new-frame (wait-for-new-frame language-dialog)]) |
| 441 | + (unless (eq? new-frame drs-frame) |
| 442 | + (error 'set-module-language! |
| 443 | + "didn't get drracket frame back, got: ~s (drs-frame ~s)\n" |
| 444 | + new-frame |
| 445 | + drs-frame))))) |
451 | 446 |
|
452 | 447 | (provide (contract-out [check-language-level ((or/c string? regexp?) . -> . void?)]))
|
453 | 448 | ;; checks that the language in the drracket window is set to the given one.
|
454 | 449 | ;; clears the definitions, clicks execute and checks the interactions window.
|
455 | 450 | (define (check-language-level lang-spec)
|
456 | 451 | (not-on-eventspace-handler-thread 'check-language-level!)
|
457 |
| - (let* ([drs-frame (wait-for-drracket-frame)] |
458 |
| - [interactions (send drs-frame get-interactions-text)] |
459 |
| - [definitions-canvas (send drs-frame get-definitions-canvas)]) |
460 |
| - (fw:test:new-window definitions-canvas) |
461 |
| - (fw:test:menu-select "Edit" "Select All") |
462 |
| - (fw:test:menu-select "Edit" "Delete") |
463 |
| - (do-execute drs-frame) |
464 |
| - (let ([lang-line (queue-callback/res |
465 |
| - (λ () |
466 |
| - (send interactions get-text |
467 |
| - (send interactions line-start-position 1) |
468 |
| - (send interactions line-end-position 1))))]) |
469 |
| - (unless (regexp-match lang-spec lang-line) |
470 |
| - (error 'check-language-level "expected ~s to match ~s" |
471 |
| - lang-line lang-spec))))) |
| 452 | + (define drs-frame (wait-for-drracket-frame)) |
| 453 | + (define interactions (send drs-frame get-interactions-text)) |
| 454 | + (define definitions-canvas (send drs-frame get-definitions-canvas)) |
| 455 | + (fw:test:new-window definitions-canvas) |
| 456 | + (fw:test:menu-select "Edit" "Select All") |
| 457 | + (fw:test:menu-select "Edit" "Delete") |
| 458 | + (do-execute drs-frame) |
| 459 | + (define lang-line |
| 460 | + (queue-callback/res (λ () |
| 461 | + (send interactions get-text |
| 462 | + (send interactions line-start-position 1) |
| 463 | + (send interactions line-end-position 1))))) |
| 464 | + (unless (regexp-match lang-spec lang-line) |
| 465 | + (error 'check-language-level "expected ~s to match ~s" lang-line lang-spec))) |
472 | 466 |
|
473 | 467 |
|
474 | 468 | (define (repl-in-edit-sequence?)
|
475 | 469 | (not-on-eventspace-handler-thread 'repl-in-edit-sequence?)
|
476 |
| - (let ([drr (wait-for-drracket-frame)]) |
477 |
| - (queue-callback/res |
478 |
| - (λ () |
479 |
| - (send (send drr get-interactions-text) refresh-delayed?))))) |
| 470 | + (define drr (wait-for-drracket-frame)) |
| 471 | + (queue-callback/res (λ () (send (send drr get-interactions-text) refresh-delayed?)))) |
480 | 472 |
|
481 | 473 | ;; has-error? : frame -> (union #f string)
|
482 | 474 | ;; returns the text of an error in the interactions window of the frame or #f if there is none.
|
|
486 | 478 | (run-one/sync
|
487 | 479 | (lambda ()
|
488 | 480 | (verify-drracket-frame-frontmost 'had-error? frame)
|
489 |
| - (let* ([interactions-text (send frame get-interactions-text)] |
490 |
| - [last-para (send interactions-text last-paragraph)]) |
491 |
| - (unless (>= last-para 2) |
492 |
| - (error 'has-error? "expected at least 2 paragraphs in interactions window, found ~a" |
493 |
| - (+ last-para 1))) |
494 |
| - (let ([start (send interactions-text paragraph-start-position 2)] |
495 |
| - [end (send interactions-text paragraph-end-position |
496 |
| - (- (send interactions-text last-paragraph) 1))]) |
497 |
| - (send interactions-text split-snip start) |
498 |
| - (send interactions-text split-snip end) |
499 |
| - (let loop ([pos start]) |
500 |
| - (cond |
501 |
| - [(<= end pos) #f] |
502 |
| - [else |
503 |
| - (let ([snip (send interactions-text find-snip pos 'after-or-none)]) |
504 |
| - (cond |
505 |
| - [(not snip) #f] |
506 |
| - [else |
507 |
| - (let ([color (send (send snip get-style) get-foreground)]) |
508 |
| - (if (and (= 255 (send color red)) |
509 |
| - (= 0 (send color blue) (send color green))) |
510 |
| - |
511 |
| - ;; return the text of the entire line containing the red text |
512 |
| - (let ([para (send interactions-text position-paragraph pos)]) |
513 |
| - (unless (exact-nonnegative-integer? para) |
514 |
| - (error 'has-error? |
515 |
| - "got back a bad result from position-paragraph: ~s ~s\n" |
516 |
| - para |
517 |
| - (list pos (send interactions-text last-position)))) |
518 |
| - (send interactions-text get-text |
519 |
| - (send interactions-text paragraph-start-position para) |
520 |
| - (send interactions-text paragraph-end-position para))) |
521 |
| - |
522 |
| - (loop (+ pos (send snip get-count)))))]))]))))))) |
| 481 | + (define interactions-text (send frame get-interactions-text)) |
| 482 | + (define last-para (send interactions-text last-paragraph)) |
| 483 | + (unless (>= last-para 2) |
| 484 | + (error 'has-error? |
| 485 | + "expected at least 2 paragraphs in interactions window, found ~a" |
| 486 | + (+ last-para 1))) |
| 487 | + (define start (send interactions-text paragraph-start-position 2)) |
| 488 | + (define end |
| 489 | + (send interactions-text paragraph-end-position |
| 490 | + (- (send interactions-text last-paragraph) 1))) |
| 491 | + (send interactions-text split-snip start) |
| 492 | + (send interactions-text split-snip end) |
| 493 | + (let loop ([pos start]) |
| 494 | + (cond |
| 495 | + [(<= end pos) #f] |
| 496 | + [else |
| 497 | + (let ([snip (send interactions-text find-snip pos 'after-or-none)]) |
| 498 | + (cond |
| 499 | + [(not snip) #f] |
| 500 | + [else |
| 501 | + (let ([color (send (send snip get-style) get-foreground)]) |
| 502 | + (if (and (= 255 (send color red)) (= 0 (send color blue) (send color green))) |
| 503 | + |
| 504 | + ;; return the text of the entire line containing the red text |
| 505 | + (let ([para (send interactions-text position-paragraph pos)]) |
| 506 | + (unless (exact-nonnegative-integer? para) |
| 507 | + (error 'has-error? |
| 508 | + "got back a bad result from position-paragraph: ~s ~s\n" |
| 509 | + para |
| 510 | + (list pos (send interactions-text last-position)))) |
| 511 | + (send interactions-text get-text |
| 512 | + (send interactions-text paragraph-start-position para) |
| 513 | + (send interactions-text paragraph-end-position para))) |
| 514 | + |
| 515 | + (loop (+ pos (send snip get-count)))))]))]))))) |
523 | 516 |
|
524 | 517 | (define fetch-output
|
525 | 518 | (case-lambda
|
|
0 commit comments