Skip to content
38 changes: 19 additions & 19 deletions drracket-test/tests/drracket/private/drracket-test-util.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@
;; filename is a string naming a file that should be typed into the dialog
(define (use-get/put-dialog open-dialog filename)
(not-on-eventspace-handler-thread 'use-get/put-dialog)
(let ([drs (wait-for-drracket-frame)])
(with-handlers ([(lambda (x) #t)
(lambda (x)
(fw:preferences:set 'framework:file-dialogs 'std)
(raise x))])
(fw:preferences:set 'framework:file-dialogs 'common)
(open-dialog)
(let ([dlg (wait-for-new-frame drs)])
(send (find-labelled-window "Filename:" #f (fw:test:get-active-top-level-window)) focus)
(fw:test:keystroke #\a (list (case (system-type)
[(windows) 'control]
[(macosx macos) 'meta]
[(unix) 'control]
[else (error 'use-get/put-dialog "unknown platform: ~s\n"
(system-type))])))
(for-each fw:test:keystroke (string->list (path->string filename)))
(fw:test:button-push "OK")
(wait-for-new-frame dlg))
(fw:preferences:set 'framework:file-dialogs 'std))))
(define drs (wait-for-drracket-frame))
(with-handlers ([(lambda (x) #t) (lambda (x)
(fw:preferences:set 'framework:file-dialogs 'std)
(raise x))])
(fw:preferences:set 'framework:file-dialogs 'common)
(open-dialog)
(let ([dlg (wait-for-new-frame drs)])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this let didn't go away?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been asking this a lot. I think one thing that would help is for the PR description to indicate if there's any limitation reached. If so, we wouldn't need to ask anymore if it's Resyntax's fault or not when some issues are not fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a great idea.

(send (find-labelled-window "Filename:" #f (fw:test:get-active-top-level-window)) focus)
(fw:test:keystroke
#\a
(list (case (system-type)
[(windows) 'control]
[(macosx macos) 'meta]
[(unix) 'control]
[else (error 'use-get/put-dialog "unknown platform: ~s\n" (system-type))])))
(for-each fw:test:keystroke (string->list (path->string filename)))
(fw:test:button-push "OK")
(wait-for-new-frame dlg))
(fw:preferences:set 'framework:file-dialogs 'std)))

(define (test-util-error fmt . args)
(raise (make-exn (apply fmt args) (current-continuation-marks))))
Expand Down
7 changes: 3 additions & 4 deletions drracket-test/tests/drracket/private/easter-egg-lib.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ and then loading the framework after that.

(define (verify-drracket-frame-frontmost function-name frame)
(on-eventspace-handler-thread 'verify-drracket-frame-frontmost)
(let ([tl (test:get-active-top-level-window)])
(unless (and (eq? frame tl)
(drracket-frame? tl))
(error function-name "drracket frame not frontmost: ~e (found ~e)" frame tl))))
(define tl (test:get-active-top-level-window))
(unless (and (eq? frame tl) (drracket-frame? tl))
(error function-name "drracket frame not frontmost: ~e (found ~e)" frame tl)))

(define (set-module-language! drr-frame)
(test:menu-select "Language" "Choose Language…")
Expand Down
50 changes: 24 additions & 26 deletions drracket-test/tests/drracket/private/module-lang-test-utils.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,30 @@
(define output-start-paragraph 2)

(when ints
(let ([after-execute-output
(queue-callback/res
(λ ()
(send interactions-text
get-text
(send interactions-text paragraph-start-position 2)
(send interactions-text paragraph-end-position 2))))])
(unless (or (test-all? test) (string=? "> " after-execute-output))
(eprintf (string-append
"FAILED (line ~a): ~a\n"
" ~a\n"
" expected no output after execution, got: ~s\n")
(test-line test)
(test-definitions test)
(or (test-interactions test) 'no-interactions)
after-execute-output)
(k (void)))
(insert-in-interactions drs ints)
;; set to be the paragraph right after the insertion.
(set! output-start-paragraph
(queue-callback/res
(λ () (+ (send interactions-text position-paragraph
(send interactions-text last-position))
1))))
(test:keystroke #\return '(alt))
(wait-for-computation drs)))
(define after-execute-output
(queue-callback/res (λ ()
(send interactions-text
get-text
(send interactions-text paragraph-start-position 2)
(send interactions-text paragraph-end-position 2)))))
(unless (or (test-all? test) (string=? "> " after-execute-output))
(eprintf (string-append "FAILED (line ~a): ~a\n"
" ~a\n"
" expected no output after execution, got: ~s\n")
(test-line test)
(test-definitions test)
(or (test-interactions test) 'no-interactions)
after-execute-output)
(k (void)))
(insert-in-interactions drs ints)
;; set to be the paragraph right after the insertion.
(set! output-start-paragraph
(queue-callback/res
(λ ()
(+ (send interactions-text position-paragraph (send interactions-text last-position))
1))))
(test:keystroke #\return '(alt))
(wait-for-computation drs))

(define text
(queue-callback/res
Expand Down
100 changes: 50 additions & 50 deletions drracket-test/tests/drracket/private/no-fw-test-util.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -66,52 +66,52 @@
;; change the preferences system so that it doesn't write to
;; a file; partly to avoid problems of concurrency in drdr
;; but also to make the test suite easier for everyone to run.
(let ([prefs-table (make-hash)])
(preferences:low-level-put-preferences
(λ (names vals)
(for ([name (in-list names)]
[val (in-list vals)])
(hash-set! prefs-table name val))))
(preferences:low-level-get-preference
(λ (name [fail (lambda () #f)])
(hash-ref prefs-table name fail)))

;; set all preferences to their defaults (some pref values may have
;; been read by this point, but hopefully that won't affect the
;; startup of drracket)
(preferences:restore-defaults)

;; initialize some preferences to simulate these
;; being saved already in the user's prefs file
;; call preferences:set too since the prefs file
;; may have been "read" already at this point
(for ([pref (in-list prefs)])
(define pref-key (list-ref pref 0))
(define pref-val (list-ref pref 1))
(define m (regexp-match #rx"^plt:framework-pref:(.*)$" (symbol->string pref-key)))
(cond
[m
(hash-set! prefs-table pref-key pref-val)
(define fw-pref-key (string->symbol (list-ref m 1)))
(when (preferences:default-set? fw-pref-key)
(preferences:set fw-pref-key pref-val))]
[else
;; this currently doesn't happen, and it is easy to forget
;; that prefix, so print a message here to remind
(printf "WARNING: setting a preference that isn't set via the framework: ~s\n"
pref-key)]))))
(define prefs-table (make-hash))
(preferences:low-level-put-preferences (λ (names vals)
(for ([name (in-list names)]
[val (in-list vals)])
(hash-set! prefs-table name val))))
(preferences:low-level-get-preference (λ (name [fail (lambda () #f)])
(hash-ref prefs-table name fail)))

;; set all preferences to their defaults (some pref values may have
;; been read by this point, but hopefully that won't affect the
;; startup of drracket)
(preferences:restore-defaults)

;; initialize some preferences to simulate these
;; being saved already in the user's prefs file
;; call preferences:set too since the prefs file
;; may have been "read" already at this point
(for ([pref (in-list prefs)])
(define pref-key (list-ref pref 0))
(define pref-val (list-ref pref 1))
(define m (regexp-match #rx"^plt:framework-pref:(.*)$" (symbol->string pref-key)))
(cond
[m
(hash-set! prefs-table pref-key pref-val)
(define fw-pref-key (string->symbol (list-ref m 1)))
(when (preferences:default-set? fw-pref-key)
(preferences:set fw-pref-key pref-val))]
[else
;; this currently doesn't happen, and it is easy to forget
;; that prefix, so print a message here to remind
(printf "WARNING: setting a preference that isn't set via the framework: ~s\n" pref-key)])))

(define (queue-callback/res thunk)
(not-on-eventspace-handler-thread
'queue-callback/res
#:more (λ () (format "\n thunk: ~e" thunk)))
(let ([c (make-channel)])
(queue-callback (λ () (channel-put c (with-handlers ((exn:fail? values))
(call-with-values thunk list))))
#f)
(define res (channel-get c))
(when (exn? res) (raise res))
(apply values res)))
(define c (make-channel))
(queue-callback (λ ()
(channel-put c
(with-handlers ([exn:fail? values])
(call-with-values thunk list))))
#f)
(define res (channel-get c))
(when (exn? res)
(raise res))
(apply values res))

;; poll-until : (-> alpha) number (-> alpha) -> alpha
;; waits until pred return a true value and returns that.
Expand All @@ -122,15 +122,15 @@
(error 'poll-until
"timeout after ~e secs, ~e never returned a true value"
secs pred))])
(let ([step 1/20])
(let loop ([counter secs])
(if (<= counter 0)
(fail)
(let ([result (pred)])
(or result
(begin
(sleep step)
(loop (- counter step)))))))))
(define step 1/20)
(let loop ([counter secs])
(if (<= counter 0)
(fail)
(let ([result (pred)])
(or result
(begin
(sleep step)
(loop (- counter step))))))))

(define (wait-for-events-in-frame-eventspace fr)
(define sema (make-semaphore 0))
Expand Down
126 changes: 62 additions & 64 deletions drracket-test/tests/drracket/private/repl-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1047,15 +1047,15 @@ This produces an ACK message
(define snip
(queue-callback/res
(lambda ()
(let* ([start (send ints-text paragraph-start-position 2)]
;; since the fraction is supposed to be one char wide, we just
;; select one char, so that, if the regular number prints out,
;; this test will fail.
[end (+ start 1)])
(send ints-text split-snip start)
(send ints-text split-snip end)
(define snip (send ints-text find-snip start 'after))
(and snip (send snip copy))))))
(define start (send ints-text paragraph-start-position 2))
;; since the fraction is supposed to be one char wide, we just
;; select one char, so that, if the regular number prints out,
;; this test will fail.
(define end (+ start 1))
(send ints-text split-snip start)
(send ints-text split-snip end)
(define snip (send ints-text find-snip start 'after))
(and snip (send snip copy)))))
(clear-definitions drr-frame)
(type-in-definitions drr-frame "(+ ")
(queue-callback/res
Expand Down Expand Up @@ -1318,16 +1318,16 @@ This produces an ACK message
(wait-for-drr-frame-computation)

(for-each test:keystroke (string->list "x"))
(let ([start (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(let* ([end (- (get-int-pos) 1)]
[output (fetch-output drr-frame start end)]
[expected #rx"x:.*cannot reference an identifier before its definition"])
(unless (regexp-match expected output)
(failure)
(eprintf "callcc-test: expected something matching ~s, got ~s\n" expected output)))))
(define start (+ 1 (queue-callback/res (λ () (send ints-text last-position)))))
(test:keystroke #\return)
(wait-for-drr-frame-computation)

(define end (- (get-int-pos) 1))
(define output (fetch-output drr-frame start end))
(define expected #rx"x:.*cannot reference an identifier before its definition")
(unless (regexp-match expected output)
(failure)
(eprintf "callcc-test: expected something matching ~s, got ~s\n" expected output)))

(define (random-seed-test)
(define expression
Expand All @@ -1338,57 +1338,55 @@ This produces an ACK message
(wait-for-drr-frame-computation)

(insert-in-interactions drr-frame expression)
(let ([start1 (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(let ([output1 (fetch-output drr-frame start1 (- (get-int-pos) 1))])
(insert-in-interactions drr-frame expression)
(let ([start2 (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(let ([output2 (fetch-output drr-frame start2 (- (get-int-pos) 1))])
(unless (equal? output1 output2)
(failure)
(eprintf "random-seed-test: expected\n ~s\nand\n ~s\nto be the same"
output1
output2)))))))
(define start1 (+ 1 (queue-callback/res (λ () (send ints-text last-position)))))
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(define output1 (fetch-output drr-frame start1 (- (get-int-pos) 1)))
(insert-in-interactions drr-frame expression)
(define start2 (+ 1 (queue-callback/res (λ () (send ints-text last-position)))))
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(define output2 (fetch-output drr-frame start2 (- (get-int-pos) 1)))
(unless (equal? output1 output2)
(failure)
(eprintf "random-seed-test: expected\n ~s\nand\n ~s\nto be the same" output1 output2)))

(define (top-interaction-test)
(clear-definitions drr-frame)
(do-execute drr-frame)
(wait-for-drr-frame-computation)
(let ([ints-just-after-welcome (queue-callback/res (λ () (+ 1 (send ints-text last-position))))])

(type-in-definitions
drr-frame
"(define-syntax #%top-interaction (syntax-rules () [(_ . e) 'e]))\n(+ 1 2)\n")
(test:menu-select "File" "Save Definitions")

(clear-definitions drr-frame)
(do-execute drr-frame)
(queue-callback/res (λ () (+ 1 (send ints-text last-position))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this can just go away!


(type-in-definitions
drr-frame
"(define-syntax #%top-interaction (syntax-rules () [(_ . e) 'e]))\n(+ 1 2)\n")
(test:menu-select "File" "Save Definitions")

(clear-definitions drr-frame)
(do-execute drr-frame)
(wait-for-drr-frame-computation)

(for-each test:keystroke (string->list (format "(load ~s)" tmp-load-short-filename)))
(let ([start (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)

(for-each test:keystroke (string->list (format "(load ~s)" tmp-load-short-filename)))
(let ([start (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(let* ([end (- (get-int-pos) 1)]
[output (fetch-output drr-frame start end)]
[expected "(+ 1 2)"])
(unless (equal? output expected)
(error 'top-interaction-test "expected.1 ~s, got ~s" expected output))
(next-test)))

(for-each test:keystroke (string->list "(+ 4 5)"))
(let ([start (+ 1 (queue-callback/res (λ () (send ints-text last-position))))])
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(let* ([end (- (get-int-pos) 1)]
[output (fetch-output drr-frame start end)]
[expected "(+ 4 5)"])
(unless (equal? output expected)
(error 'top-interaction-test "expected.2 ~s, got ~s" expected output))
(next-test)))))
(let* ([end (- (get-int-pos) 1)]
[output (fetch-output drr-frame start end)]
[expected "(+ 1 2)"])
(unless (equal? output expected)
(error 'top-interaction-test "expected.1 ~s, got ~s" expected output))
(next-test)))

(for-each test:keystroke (string->list "(+ 4 5)"))
(define start (+ 1 (queue-callback/res (λ () (send ints-text last-position)))))
(test:keystroke #\return)
(wait-for-drr-frame-computation)
(define end (- (get-int-pos) 1))
(define output (fetch-output drr-frame start end))
(define expected "(+ 4 5)")
(unless (equal? output expected)
(error 'top-interaction-test "expected.2 ~s, got ~s" expected output))
(next-test))

(when (file-exists? tmp-load-filename)
(delete-file tmp-load-filename))
Expand Down