diff --git a/drracket-test/tests/drracket/language-test.rkt b/drracket-test/tests/drracket/language-test.rkt index 0d24786b0..172f25c59 100644 --- a/drracket-test/tests/drracket/language-test.rkt +++ b/drracket-test/tests/drracket/language-test.rkt @@ -505,24 +505,6 @@ the settings above should match r5rs (test-expression "(error 'a \"~a\" 1)" "a: ~a1") (test-expression "(error \"a\" \"a\")" "aa") - - (test-expression "(check-expect 1 1)" - "The test passed!" - "Both tests passed!") - (test-expression "(check-expect 1 1)\n(check-expect 2 2)\n(+ \"hello\" \"world\")\n(check-expect 3 3)\n" - (λ (got) - (define m (regexp-match #rx"(.*)0 tests passed(.*)" got)) - (cond - [m - (define before (list-ref m 1)) - (define after (list-ref m 2)) - (and (not (regexp-match? #rx"tests? passed" before)) - (not (regexp-match? #rx"tests? passed" after)))] - [else #f])) - (λ (got) #t)) ;; just skip the interactions test - (test-expression "(define (badfn x) (error \"hello\"))\n(check-expect (badfn 1) 1)\n(error \"hello\")" - #rx"0 tests passed[.].*hello" - (λ (got) #t)) (test-undefined-fn "(time 1)" "time") @@ -672,13 +654,6 @@ the settings above should match r5rs (test-error-after-definition) (prepare-for-test-expression) - - (test-expression "(check-expect 1 1)" - "The only test passed!" - "") ;; somewhat dubious -- it should either be a syntax error or work... - (test-expression "(check-expect 1 2)" - #rx"Actual value 1 differs from 2" - "") (test-expression "'|.|" "'|.|" @@ -898,23 +873,6 @@ the settings above should match r5rs (test-expression "(error 'a \"~a\" 1)" "a: ~a1") (test-expression "(error \"a\" \"a\")" "aa") - (test-expression "(check-expect 1 1)" - "The test passed!" - "Both tests passed!") - (test-expression "(check-expect 1 1)\n(check-expect 2 2)\n(+ \"hello\" \"world\")\n(check-expect 3 3)\n" - (λ (got) - (define m (regexp-match #rx"(.*)0 tests passed(.*)" got)) - (cond - [m - (define before (list-ref m 1)) - (define after (list-ref m 2)) - (and (not (regexp-match? #rx"tests? passed" before)) - (not (regexp-match? #rx"tests? passed" after)))] - [else #f])) - (λ (got) #t)) ;; just skip the interactions test - (test-expression "(define (badfn x) (error \"hello\"))\n(check-expect (badfn 1) 1)\n(error \"hello\")" - #rx"0 tests passed[.].*hello" - (λ (got) #t)) (test-undefined-fn "(time 1)" "time") @@ -1074,24 +1032,6 @@ the settings above should match r5rs (test-expression "(error 'a \"~a\" 1)" "a: ~a1") (test-expression "(error \"a\" \"a\")" "aa") - - (test-expression "(check-expect 1 1)" - "The test passed!" - "Both tests passed!") - (test-expression "(check-expect 1 1)\n(check-expect 2 2)\n(+ \"hello\" \"world\")\n(check-expect 3 3)\n" - (λ (got) - (define m (regexp-match #rx"(.*)0 tests passed(.*)" got)) - (cond - [m - (define before (list-ref m 1)) - (define after (list-ref m 2)) - (and (not (regexp-match? #rx"tests? passed" before)) - (not (regexp-match? #rx"tests? passed" after)))] - [else #f])) - (λ (got) #t)) ;; just skip the interactions test - (test-expression "(define (badfn x) (error \"hello\"))\n(check-expect (badfn 1) 1)\n(error \"hello\")" - #rx"0 tests passed[.].*hello" - (λ (got) #t)) (test-expression "(time 1)" #rx"cpu time: [0-9]+ real time: [0-9]+ gc time: [0-9]+\n1") @@ -1247,24 +1187,6 @@ the settings above should match r5rs (test-expression "(error 'a \"~a\" 1)" "a: ~a1") (test-expression "(error \"a\" \"a\")" "aa") - (test-expression "(check-expect 1 1)" - "The test passed!" - "Both tests passed!") - (test-expression "(check-expect 1 1)\n(check-expect 2 2)\n(+ \"hello\" \"world\")\n(check-expect 3 3)\n" - (λ (got) - (define m (regexp-match #rx"(.*)0 tests passed(.*)" got)) - (cond - [m - (define before (list-ref m 1)) - (define after (list-ref m 2)) - (and (not (regexp-match? #rx"tests? passed" before)) - (not (regexp-match? #rx"tests? passed" after)))] - [else #f])) - (λ (got) #t)) ;; just skip the interactions test - (test-expression "(define (badfn x) (error \"hello\"))\n(check-expect (badfn 1) 1)\n(error \"hello\")" - #rx"0 tests passed[.].*hello" - (λ (got) #t)) - (test-expression "(time 1)" #rx"cpu time: [0-9]+ real time: [0-9]+ gc time: [0-9]+\n1") @@ -1416,24 +1338,6 @@ the settings above should match r5rs (test-expression "(error 'a \"~a\" 1)" "a: ~a1") (test-expression "(error \"a\" \"a\")" "aa") - (test-expression "(check-expect 1 1)" - "The test passed!" - "Both tests passed!") - (test-expression "(check-expect 1 1)\n(check-expect 2 2)\n(+ \"hello\" \"world\")\n(check-expect 3 3)\n" - (λ (got) - (define m (regexp-match #rx"(.*)0 tests passed(.*)" got)) - (cond - [m - (define before (list-ref m 1)) - (define after (list-ref m 2)) - (and (not (regexp-match? #rx"tests? passed" before)) - (not (regexp-match? #rx"tests? passed" after)))] - [else #f])) - (λ (got) #t)) ;; just skip the interactions test - (test-expression "(define (badfn x) (error \"hello\"))\n(check-expect (badfn 1) 1)\n(error \"hello\")" - #rx"0 tests passed[.].*hello" - (λ (got) #t)) - (test-expression "(time 1)" #rx"cpu time: [0-9]+ real time: [0-9]+ gc time: [0-9]+\n1") diff --git a/drracket-test/tests/drracket/module-lang-test.rkt b/drracket-test/tests/drracket/module-lang-test.rkt index 1c66e107e..fa8bd0783 100644 --- a/drracket-test/tests/drracket/module-lang-test.rkt +++ b/drracket-test/tests/drracket/module-lang-test.rkt @@ -530,703 +530,6 @@ f: contract violation } ) -;; Test that big-bang is in the stacktrace if the state-expr errors at start time. -(test @t{ - #lang htdp/isl+ - - (require 2htdp/image) - (require 2htdp/universe) - - (big-bang (+ 2 #false) - (to-draw (lambda (s) (empty-scene 200 200)))) - -} - #f - #rx"[+]: expects a number(?: as 2nd argument)?, given #false" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:6:10" - (srcloc->string loc))) - ;; ^ (+ 2 #false) is in the backtrace - (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:6:0" - (srcloc->string loc))) - ;; ^ big-bang is in the backtrace, not some internal htdp modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(][+] 2.*false[)]" - (test-definitions test))) - ;; ^ (+ 2 #false) is highlighted - ))) - -;; Test that big-bang is highlighted for (initial) check-with errors -;; Note that, however, this only works when big-bang check-with fails at start time. -(test @t{ - #lang htdp/isl+ - - (require 2htdp/image) - (require 2htdp/universe) - - (big-bang -1 - (to-draw (lambda (s) (empty-scene 200 200))) - (check-with string?)) - -} - #f - #rx"check-with: the initial expression.*fails to pass.*string[?] test" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:6:0" - (srcloc->string loc))) - ;; ^ big-bang is in the backtrace, not some internal htdp modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]big-bang.*[(]check-with string[?][)][)]" - (test-definitions test))) - ;; ^ big-bang is highlighted - ))) - -;; Needs 2htdp/universe fixing: this does not work at the moment (v8.15) -;; check-with errors triggered by on-{tick,key} etc do not work. -#; -(test @t{ - #lang htdp/isl+ - - (require 2htdp/image) - (require 2htdp/universe) - - (big-bang -1 - (to-draw (lambda (n) (empty-scene 200 200))) - (on-tick (lambda (n) "oops")) - (check-with number?)) - -} - #f - #rx"check-with: on-tick handler.*fails to pass.*number[?] test" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:6:0" - (srcloc->string loc))) - ;; ^ user code is in the backtrace, not some internal htdp modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]big-bang.*[(]check-with number[?][)][)]" - (test-definitions test))) - ;; ^ user code is highlighted (if not on-tick, at least it should be big-bang) - ))) - -(test @t{ - #lang htdp/isl+ - - (check-expect (+ 123 45 6) even?) - -} - #f - #rx"check-expect.*function" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:3:0" - (srcloc->string loc))) - ;; ^ check-expect is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-expect.*[?][)]" - (test-definitions test))) - ;; ^ check-expect is highlighted - ))) - -(test @t{ - #lang htdp/isl+ - - (check-expect (sqrt 2) (sqrt 2)) - -} - #f - #rx"check-expect.*inexact" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:3:0" - (srcloc->string loc))) - ;; ^ check-expect is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-expect.*sqrt 2[)][)]" - (test-definitions test))) - ;; ^ check-expect is highlighted - ))) - -(test @t{ - #lang htdp/isl+ - (define p (make-posn 7 3)) - (check-expect posn-x 7) - -} - #f - #rx"Ran 1 test.\n0 tests passed." - #| - check-expect encountered the following error instead of the expected value, 7. - :: at line 3, column 0 first argument of equality cannot be a function, given posn-x - at line 3, column 0 - |# - #:extra-assert - (λ (defs ints #:test test) - (define re - (pregexp - (string-append - "check-expect[ a-z]+error.*[^\n]+\n" - ".*::.*at line 3, column 0 first argument.*function.*given posn-x[^\n]*\n" - "at line 3, column 0"))) - ;; Includes the flattened test result snips. - (define full-ints-text - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)) - (define passed? - (regexp-match? re full-ints-text)) - (unless passed? - (eprintf "FAILED line ~a: ~a\n extra assertion expected: ~s\n\n got: ~a\n" - (test-line test) - (test-definitions test) - re - full-ints-text)) - passed?)) - -(test @t{ - #lang htdp/isl+ - - - (check-random (+ (random 5) (sqrt 2)) - (+ (random 5) (sqrt 2))) - -} - #f - #rx"check-random.*inexact" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:4:0" - (srcloc->string loc))) - ;; ^ check-random is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-random.*sqrt 2[)][)][)]" - (test-definitions test))) - ;; ^ check-random is highlighted - ))) - -(test @t{ - #lang htdp/isl+ - - (check-within (sqrt 2) 3/2 "0.1") - -} - #f - #rx"check-within.*\"0[.]1\".*not inexact" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:3:1" - (srcloc->string loc))) - ;; ^ check-within is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-within.*0[.]1\"[)]" - (test-definitions test))) - ;; ^ check-within is highlighted - ))) - -;; NOTE. If check-satisfied no longer errs immediately in the future, -;; merge this test into the last check-satisfied test below. -(test @t{ - #lang htdp/isl+ - - (check-satisfied (+ 2 2) 4) - -} - #f - #rx"check-satisfied: expect.*function.*one argument.*second position.*iven 4" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:3:1" - (srcloc->string loc))) - ;; ^ check-satisfied is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-satisfied.*4[)]" - (test-definitions test))) - ;; ^ check-satisfied is highlighted - ))) - -;; NOTE. If the error-check printing bug is fixed, replace the printed procedure -;; # with (appropriately escaped) (lambda (a1 a2) ...) -(test @t{ - #lang htdp/isl+ - - (check-satisfied 4 (lambda (n bad) (even? n))) - -} - #f - #rx"check-satisfied: expect.*function.*one argument.*second position.*#" - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? #rx"unsaved-editor:3:1" - (srcloc->string loc))) - ;; ^ check-satisfied is in the backtrace, not some internal test-engine modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]check-satisfied.*[(]even[?] n[)][)][)]" - (test-definitions test))) - ;; ^ check-satisfied is highlighted - ))) - -;; NOTE. -;; 1. After the error-check printing bug is fixed, add the "function:" prefix -;; to all the functions in the error messsage in this test. -;; 2. The column numbers after "::" in each error could be further improved/refined, -;; but the srclocs should include at least the line numbers of the user code. -;; 3. Also remember to test this in a _saved_ buffer. -(test @t{#lang htdp/isl - - (define local-even - (local [(define (my-even m k) - (even? (+ m k)))] - my-even)) - - (define (real-my-even m k) - (even? (+ m k))) - - (check-satisfied (rest (list 3514)) empty) - (check-satisfied 4 local-even) - (check-satisfied 4 real-my-even)} - #f - #px"^Ran 3 tests[.]\\s+0 tests passed[.]" - #t - #:extra-assert - (λ (defs ints #:test test) - (define re - (pregexp - @t{^Ran 3 tests[.] - 0 tests passed[.] - - Check failures:\s* - +check-satisfied for empty encountered an error[.]\s* - +:: +at line 11, column 0 +function call: expect.+function.+open parenthesis.+received '[(][)]\s* - at line 11, column 0 - +check-satisfied for local-even encountered an error[.]\s* - +:: +at line 12, column 0 +my-even: expect.+2 arguments.+found only 1\s* - at line 12, column 0 - +check-satisfied for real-my-even encountered an error[.]\s* - +:: +at line 13, column 0 +check-satisfied: expect.+function.+one argument.+second position.+real-my-even\s* - at line 13, column 0 - > })) - ;; Includes the flattened test result snips. - (define full-ints-text - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)) - (define passed? - (regexp-match? re full-ints-text)) - (unless passed? - (eprintf "FAILED line ~a: ~a\n extra assertion expected: ~s\n\n got: ~a\n" - (test-line test) - (test-definitions test) - re - full-ints-text) - (flush-output (current-error-port)) - (sleep/yield 0.1)) - passed?)) - -(define (close-current-tab-and-open-new-tab filename) - (define path (in-here/path filename)) - (define drs (wait-for-drracket-frame)) - (test:menu-select "File" "New Tab") - (case (system-type 'os) - [(macosx windows) - (test:menu-select "Windows" (format "Tab 1: ~a" filename)) - (test:menu-select "File" "Close Tab")] - [(unix) - (test:menu-select "Tabs" (format "Tab 1: ~a" filename)) - (test:menu-select "File" "Close")]) - (when (file-exists? path) - (delete-file path))) - -(let ([filename @t{gh208-pr229-islplus.rkt}]) -(test #:before-execute (λ () (save-drracket-window-as - (string->path (in-here/path filename)))) - #:after-test (λ () (close-current-tab-and-open-new-tab filename)) - #:wait-for-drracket-frame-after-test? #t - @t{ - #lang htdp/isl+ - - (define (my-add1 n) (+ n 1)) - my-add1 - (check-expect my-add1 2) - - (let ([keep-parity (lambda (m) - (+ m 2))]) - keep-parity) - - (local [(define alt-parity (lambda (m) - (- 1 m)))] - alt-parity) - - (let () - (lambda (m) - (+ m 2))) - - (local [(define lam-in-if - (if (> (random 10) 5) - (lambda (x) (+ x 5)) - (lambda (y) (* y 2))))] - lam-in-if) - -} - #f - @rx{^my-add1 - keep-parity - alt-parity - [(]lambda [(]a1[)] [.][.][.][)] - lam-in-if - Ran 1 test[.] - 0 tests passed[.]} - #:extra-assert - (λ (defs ints #:test test) - (define ^\n "[^\n]+") - (define re - (pregexp - @t{::\s+in @(regexp-quote filename), line 5, column 0@|^\n|function@|^\n|given my-add1})) - ;; Includes the flattened test result snips. - (define full-ints-text - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)) - (define passed? - (regexp-match? re full-ints-text)) - (unless passed? - (eprintf "FAILED line ~a: ~a\n extra assertion expected: ~s\n\n got: ~a\n" - (test-line test) - (test-definitions test) - re - full-ints-text) - (flush-output (current-error-port)) - (sleep/yield 0.1)) - passed?))) - -;; Run the same test, but in an unsaved buffer. -(test @t{ - #lang htdp/isl+ - - (define (my-add1 n) (+ n 1)) - my-add1 - (check-expect my-add1 2) - - (let ([keep-parity (lambda (m) - (+ m 2))]) - keep-parity) - - (local [(define alt-parity (lambda (m) - (- 1 m)))] - alt-parity) - - (let () - (lambda (m) - (+ m 2))) - - (local [(define lam-in-if - (if (> (random 10) 5) - (lambda (x) (+ x 5)) - (lambda (y) (* y 2))))] - lam-in-if) - -} - #f - @rx{^my-add1 - keep-parity - alt-parity - [(]lambda [(]a1[)] [.][.][.][)] - lam-in-if - Ran 1 test[.] - 0 tests passed[.]} - #:extra-assert - (λ (defs ints) - (regexp-match? #px"::\\s+at line 5, column 0[^\n]+function[^\n]+given my-add1" - ;; Includes the flattened test result snips. - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)))) - -(let ([filename @t{gh208-pr229-isl.rkt}]) -(test #:before-execute (λ () (save-drracket-window-as - (string->path (in-here/path filename)))) - #:after-test (λ () (close-current-tab-and-open-new-tab filename)) - #:wait-for-drracket-frame-after-test? #t - @t{ - #lang htdp/isl - - (define (my-add1 n) (+ n 1)) - my-add1 - (check-expect my-add1 2) - - (let ([keep-parity (lambda (m) - (+ m 2))]) - keep-parity) - - (local [(define alt-parity (lambda (m) - (- 1 m)))] - alt-parity) - -} - #f - @rx{^function:my-add1 - function:keep-parity - function:alt-parity - Ran 1 test[.] - 0 tests passed[.]} - #:extra-assert - (λ (defs ints) - (define ^\n "[^\n]+") - (regexp-match? - (pregexp - @t{::\s+in @(regexp-quote filename), line 5, column 0@|^\n|function@|^\n|given function:my-add1}) - ;; Includes the flattened test result snips. - (send ints get-text (send ints paragraph-start-position 2) 'eof #t))))) - -;; Run the same test, but in an unsaved buffer. -(test @t{ - #lang htdp/isl - - (define (my-add1 n) (+ n 1)) - my-add1 - (check-expect my-add1 2) - - (let ([keep-parity (lambda (m) - (+ m 2))]) - keep-parity) - - (local [(define alt-parity (lambda (m) - (- 1 m)))] - alt-parity) - -} - #f - @rx{^function:my-add1 - function:keep-parity - function:alt-parity - Ran 1 test[.] - 0 tests passed[.]} - #:extra-assert - (λ (defs ints) - (regexp-match? #px"::\\s+at line 5, column 0[^\n]+function[^\n]+given function:my-add1" - ;; Includes the flattened test result snips. - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)))) - -(let ([filename @t{htdp-tests-intm-lam-map.rkt}]) -(test #:before-execute (λ () (save-drracket-window-as - (string->path (in-here/path filename)))) - #:after-test (λ () (close-current-tab-and-open-new-tab filename)) - #:wait-for-drracket-frame-after-test? #t - @t{ -#lang htdp/isl+ - (map (lambda (x y) (+ x y)) (list 2 3 4)) -} - #f - @rx{map: first argument must be a function that expects one argument, - given @regexp-quote{(lambda (a1 a2) ...)}} - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? @rx{@(regexp-quote filename):2:3} - (srcloc->string loc))) - ;; ^ foldr is in the backtrace, not some internal HtDP modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]map.*3 4[)][)]" - (test-definitions test))) - ;; ^ foldr is highlighted - )))) - -(let ([filename @t{htdp-tests-intm-lam-foldr2.rkt}]) -(test #:before-execute (λ () (save-drracket-window-as - (string->path (in-here/path filename)))) - #:after-test (λ () (close-current-tab-and-open-new-tab filename)) - #:wait-for-drracket-frame-after-test? #t - @t{ -#lang htdp/isl+ - (foldr (lambda (x y) (+ x y)) 0 (list 2 3 4) (list 2 3 4)) -} - #f - @rx{foldr: first argument must be a function that expects three arguments, - given @regexp-quote{(lambda (a1 a2) ...)}} - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? @rx{@(regexp-quote filename):2:3} - (srcloc->string loc))) - ;; ^ foldr is in the backtrace, not some internal HtDP modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]foldr.*3 4[)][)]" - (test-definitions test))) - ;; ^ foldr is highlighted - )))) - -(let ([filename @t{htdp-tests-intm-lam-foldr3.rkt}]) -(test #:before-execute (λ () (save-drracket-window-as - (string->path (in-here/path filename)))) - #:after-test (λ () (close-current-tab-and-open-new-tab filename)) - #:wait-for-drracket-frame-after-test? #t - @t{ -#lang htdp/isl+ - (foldr (lambda (x y z) (+ x y z)) 0 (list 2 3 4)) -} - #f - @rx{foldr: first argument must be a function that expects two arguments, - given @regexp-quote{(lambda (a1 a2 a3) ...)}} - #:extra-assert - (λ (defs ints #:stacks stacks #:test test) - (and (for*/or ([stack (in-list stacks)] - #:when stack - [loc (in-list (viewable-stack->red-arrows-backtrace-srclocs stack))]) - (regexp-match? @rx{@(regexp-quote filename):2:3} - (srcloc->string loc))) - ;; ^ foldr is in the backtrace, not some internal HtDP modules - (equal? - (remove-duplicates - (for/list ([range (send defs get-highlighted-ranges)]) - (cons (text:range-start range) (text:range-end range)))) - (regexp-match-positions #rx"[(]foldr.*3 4[)][)]" - (test-definitions test))) - ;; ^ foldr is highlighted - )))) - -(test @t{#lang htdp/isl - (check-expect (* 2 3) 6) - (check-expect (+ 2 3) 5)} - #f - #rx"^Both tests passed!$") - -(test @t{#lang htdp/isl} - ;; REPL - @t{(check-expect (* 2 3) 6) - (check-expect (+ 2 3) 5)} - #rx"^The test passed!\nThe test passed!$") - -(test @t{#lang htdp/isl - (check-expect (* 2 3) 6) - (check-expect (* 2 3) 5)} - #f - #rx"^Ran 2 tests[.]\n1 of the 2 tests failed[.].*Check failures:") - -(test @t{#lang htdp/isl} - ;; REPL - @t{(check-expect (* 2 3) 6) - (check-expect (* 2 3) 5)} - #rx"^The test passed!\nRan 1 test[.]\n0 tests passed[.].*Check failures:") - -(test @t{#lang htdp/isl} - ;; REPL - @t{(check-expect (* 2 3) 5) - (check-expect (* 2 3) 6)} - #rx"^Ran 1 test[.]\n0 tests passed[.].*Check failures:.*\nThe test passed!$") - -(test @t{#lang htdp/isl - (check-expect (* 2 3) 6) - (check-expect (* 2 3) 5) - (check-expect (+ 2 3) 5)} - ;; REPL - @t{(check-expect (+ 4 5) 9) - (check-expect (+ 6 7) 42) - (check-expect (* 8 9) 72) - (check-expect (error 'oops) 111)} - #px"^Ran 3 tests[.]\\s+1 of the 3 tests failed[.]" - #t - #:extra-assert - (λ (defs ints #:test test) - (define re - (pregexp - @t{^Ran 3 tests[.] - 1 of the 3 tests failed[.] - - Check failures:\s* - +Actual value 6 differs from 5, the expected value[.]\s* - at line 3, column 0 - > @(regexp-quote (test-interactions test)) - The test passed! - Ran 1 test[.] - 0 tests passed[.] - - Check failures:\s* - +Actual value 13 differs from 42, the expected value[.]\s* - at line 10, column 0 - The test passed! - Ran 1 test[.] - 0 tests passed[.] - - Check failures:\s* - +check-expect encountered the following error instead of the expected value, 111[.]\s* - +:: +at line 12, column 14 oops:\s* - at line 12, column 0 - > })) - ;; Includes the flattened test result snips. - (define full-ints-text - (send ints get-text (send ints paragraph-start-position 2) 'eof #t)) - (define passed? - (regexp-match? re full-ints-text)) - (unless passed? - (eprintf "FAILED line ~a: ~a\n extra assertion expected: ~s\n\n got: ~a\n" - (test-line test) - (test-definitions test) - re - full-ints-text) - (flush-output (current-error-port)) - (sleep/yield 0.1)) - passed?)) - (fire-up-drracket-and-run-tests run-test) ;; Test mode: diff --git a/drracket-test/tests/drracket/test-engine-test.rkt b/drracket-test/tests/drracket/test-engine-test.rkt deleted file mode 100644 index 79753ef97..000000000 --- a/drracket-test/tests/drracket/test-engine-test.rkt +++ /dev/null @@ -1,560 +0,0 @@ -#lang racket - -(require "private/drracket-test-util.rkt" - "private/gui.rkt" - mred - framework - (prefix-in fw: framework)) - -(define language (make-parameter "<>")) - -;; set-language : boolean -> void -(define (set-language close-dialog?) - (set-language-level! (language) close-dialog?)) - -(define (common-test-engine dmda?) - (test-expression "(check-expect 1 1)" - "The test passed!" - #:repl-expected "Both tests passed!") - - (test-expression "(check-within 1 1.1 0.5)" - "The test passed!" - #:repl-expected "Both tests passed!") - - (test-expression "(check-expect 1 2)" - "" - #:check-failures-expected - (list (make-check-expect-failure "1" "2" 1 0)) - #:repl-check-failures-expected - (list (make-check-expect-failure "1" "2" 3 2))) - - ; number snips - (test-expression "(check-within 1/3 5/3 1/2)" - "" - #:check-failures-expected - (list (make-check-within-failure "0.3" "0.5" "1.6" 1 0)) - #:repl-check-failures-expected - (list (make-check-within-failure "0.3" "0.5" "1.6" 3 2))) - - (define image-markup-test - (string-append - "(require 2htdp/image)\n" - "(check-expect" - " (circle 20 \"solid\" \"red\")" - " (circle 10 \"outline\" \"blue\"))")) - (test-expression image-markup-test - "" - ;; If image snips are in the output of test failure - ;; messages, they will be replaced by "." when extracting - ;; texts from the editor. - #:check-failures-expected - (list (make-check-expect-failure "." "." 2 0)) - #:repl-check-failures-expected - (list (make-check-expect-failure "." "." 4 0))) - - (unless dmda? - (test-expression (format "~s" '(check-error (first 212) "first: expects a non-empty list; given: 212")) - "The test passed!" - #:repl-expected "Both tests passed!")) - - (unless dmda? - (test-expression "(check-expect (car 0) 2)" - "" - #:check-failures-expected - (list (make-check-expect-error "2." ":: car: expects a pair, given 0" 1 0 1 14)) - #:repl-check-failures-expected - (list (make-check-expect-error "2." ":: car: expects a pair, given 0" 3 2 3 16))))) - -(define (common-signatures-*sl) - (test-expression "(: foo Integer) (define foo 5)" - "" - #:repl-expected "foo: this name was defined previously and cannot be re-defined") - (test-expression "(: foo Integer) (define foo \"bar\")" - "" - #:repl-expected "foo: this name was defined previously and cannot be re-defined" - #:signature-violations-expected - (list (make-signature-violation "\"bar\" at line 1, column 28" 1 7))) - (test-expression "(: foo (Integer -> Integer)) (define (foo x) x) (foo \"foo\")" - "\"foo\"" - #:repl-expected "foo: this name was defined previously and cannot be re-defined\n" - #:signature-violations-expected - (list (make-signature-violation "\"foo\" at line 1, column 48" 1 8)) - #:repl-signature-violations-expected - (list)) - (test-expression "(: foo (Integer -> Integer)) (define foo (lambda (x) x))" - "" - #:repl-expression "(foo \"foo\")" - #:repl-expected "\"foo\"" - #:repl-signature-violations-expected - (list (make-signature-violation "\"foo\" at line 3, column 2" 1 8)))) - -(define (common-signatures-sdp) - (test-expression "(: foo integer) (define foo 5)" - "" - #:repl-expected "define: Zweite Definition für denselben Namen") - (test-expression "(: foo integer) (define foo \"bar\")" - "" - #:repl-expected "define: Zweite Definition für denselben Namen" - #:signature-violations-expected - (list (make-signature-violation "\"bar\" at line 1, column 28" 1 7))) - (test-expression "(: foo (integer -> integer)) (define foo (lambda (x) x)) (foo \"foo\")" - "\"foo\"" - #:repl-expected "define: Zweite Definition für denselben Namen" - #:signature-violations-expected - (list (make-signature-violation "\"foo\" at line 1, column 57" 1 8)) - #:repl-signature-violations-expected - (list)) - (test-expression "(: foo (integer -> integer)) (define foo (lambda (x) x))" - "" - #:repl-expression "(foo \"foo\")" - #:repl-expected "\"foo\"" - #:repl-signature-violations-expected - (list (make-signature-violation "\"foo\" at line 3, column 2" 1 8)))) - - - -; -; ;;; ;; -; ;; ;; -; ;; -; ;;;;; ;;;; ;;;;;;;;; ;;; ;; ;;; ;; ;;;; ;;; ;; -; ;; ;; ;; ;; ;; ;; ;; ;;; ;; ;;; ;; ;; ;; ;;;;; -; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; -; ;; ;; ;;;;;; ;;;; ;; ;; ;; ;; ;; ;;;;;; ;; -; ;; ;; ;; ; ;; ;; ;; ;; ;; ;; ;; -; ;; ;; ;; ; ;;;;; ;; ;; ;; ;; ;; ;; ; ;; -; ;;;;; ;;;; ;;;;;;;;;; ;;;; ;;; ;;;; ;;; ;;;; ;;;; -; ;; ;; -; ;; ;; -; ;;;;; - -(define (beginner) - (parameterize ([language (list #rx"Beginning Student(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #f))) - - -; -; ;;; ;;; ;;; -; ;; ; ;; ;; -; ;; ; ;; ;; -; ;;;;; ;;;; ;;;;;; ; ;;;; ;;;;; ;;;;; ;;; ;; ;;;; ;;; ;;; -; ;; ;; ;; ;; ;; ;; ; ;; ;; ;; ;; ;; ;;;;; ;; ;; ;; ; -; ;; ;; ;; ;; ;; ;; ; ;; ;; ;; ;; ;; ;; ;; ;; ;; ; -; ;; ;; ;;;;;; ;;;; ; ;;;;; ;; ;; ;; ;; ;; ;;;;;; ;;; -; ;; ;; ;; ; ; ;; ;; ;; ;; ;; ;; ;; ;; ;;; -; ;; ;; ;; ; ;;;;; ; ;; ;; ;; ;; ;; ;; ;; ;; ; ;;; -; ;;;;; ;;;; ;;;;;; ; ;;;;;; ;;;;; ;;;;; ;;;; ;;;; ; -; ;; ;;; -; ;; ;;; -; ;;;;; - - -(define (beginner/abbrev) - (parameterize ([language (list #rx"Beginning Student with List Abbreviations(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #f))) - - -; -; ;; ;;; ;; -; ;; ;; ;; ;; ;; -; ;; ;; ;; -; ;;; ;;; ;; ;;;;; ;;;; ;;; ;; ;;; ;; ;; ;;;; ;;;;; ;;; ;;;; ;;;;; ;;;; -; ;; ;;; ;; ;; ;; ;; ;;;;; ;;; ;;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; -; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; -; ;; ;; ;; ;; ;;;;;; ;; ;; ;; ;; ;;;;;; ;; ;; ;; ;;;;; ;; ;;;;;; -; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; -; ;; ;; ;; ;; ;; ; ;; ;; ;; ;; ;; ; ;; ;; ;; ;; ;; ;; ;; ; -; ;;;; ;;;; ;;; ;;; ;;;; ;;;; ;;;; ;;; ;;; ;;;; ;;;;;; ;;;; ;;;;;; ;;; ;;;; -; -; -; - - -(define (intermediate) - (parameterize ([language (list #rx"Intermediate Student(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #f))) - -; -; -; -; ;; ; ;;;;;; ;;;; ;;;; -; ;; ;; ;;;;;; ;;;; ;;;; -; ;;;; ;;; ;;;;; ;;;;;; ;;;;;;; ;;;;;;; ;;;; ;;;;;;; ;;;;;;; ;;;;;;; -; ;;;; ;;;;;;;;; ;;;;;; ;;;;;; ;;;;;;;; ;;;;;;;;;;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; -; ;;;; ;;;; ;;;; ;;;; ;;;;;; ;;;; ;;;; ;;; ;;;; ;;;;;;;;; ;;;;;;;;; ;;;; -; ;;;; ;;;; ;;;; ;;;; ;; ;;;; ;;;;;;; ;;;; ;;; ;;;; ;;;; ;;;; ;;;; ;;;; ;;;;;;; -; ;;;; ;;;; ;;;; ;;;;; ;; ;;;; ;; ;;;; ;;;; ;;; ;;;; ;;;;;;;;; ;;;;;;;;; ;; ;;;; -; ;;;; ;;;; ;;;; ;;;;; ;; ;;;; ;;;;;;;; ;;;; ;;; ;;;; ;;;;;;;; ;;;;;;;; ;;;;;;;; -; ;;;; ;;;; ;;;; ;;;; ;; ;;;; ;; ;;;; ;;;; ;;; ;;;; ;;;;;;; ;;;;;;; ;; ;;;; -; ;; -; -; - - -(define (intermediate/lambda) - (parameterize ([language (list #rx"Intermediate Student with lambda(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #f))) - - -; -; -; -; ;;;; ;;;; -; ;;;; ;;;; -; ;;;;;;; ;;;;;;; ;;; ;;; ;;;;;;; ;;;; ;;; ;;;;; ;;; ;;;;;;; -; ;;;;;;;; ;;;;;;;; ;;; ;;; ;;;;;;;; ;;;;;;;;; ;;;;;; ;;;;; ;;;;;;;; -; ;;;; ;;;;;;;;; ;;;;;; ;;;; ;;;; ;;;; ;;;;;;; ;;;; ;; ;;;;;;;;; -; ;;;;;;; ;;;; ;;;; ;;;;;; ;;;;;;; ;;;; ;;;; ;;;; ;;;;;;; ;;;; ;;;; -; ;; ;;;; ;;;;;;;;; ;;;;;; ;; ;;;; ;;;; ;;;; ;;;;;;; ;;;;; ;;;;;;;;; -; ;;;;;;;; ;;;;;;;; ;;;; ;;;;;;;; ;;;; ;;;; ;;;;;; ;;;;;; ;;;;;;;; -; ;; ;;;; ;;;;;;; ;;;; ;; ;;;; ;;;; ;;;; ;;;;; ;;;; ;;;;;;; -; -; -; - - -(define (advanced) - (parameterize ([language (list #rx"Advanced Student(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #f) - (common-signatures-*sl))) - - -(define (sdp-beginner) - (parameterize ([language (list #rx"Schreibe Dein Programm! - Anfänger(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #t) - (common-signatures-sdp))) - -(define (sdp-vanilla) - (parameterize ([language (list #rx"Schreibe Dein Programm!(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #t) - (common-signatures-sdp))) - -(define (sdp-advanced) - (parameterize ([language (list #rx"Schreibe Dein Programm! - fortgeschritten(;|$)")]) - (prepare-for-test-expression) - (common-test-engine #t) - (common-signatures-sdp))) - -(define (prepare-for-test-expression) - (let ([drs (wait-for-drracket-frame)]) - (clear-definitions drs) - (set-language #t) - (sleep 1) ;; this shouldn't be neccessary.... - (do-execute drs))) - -;; test-setting : (-> void) string string string -> void -;; opens the language dialog, runs `set-setting' -;; closes the language dialog, executes, -;; makes sure that `expression' produces -;; `result'. `set-setting' is expected to click around -;; in the language dialog. -;; `setting-name' is used in the error message when the test fails. -(define (test-setting set-setting setting-name expression result) - (set-language #f) - (set-setting) - (let ([f (test:get-active-top-level-window)]) - (fw:test:button-push "OK") - (wait-for-new-frame f)) - (let* ([drs (test:get-active-top-level-window)] - [interactions (send drs get-interactions-text)]) - (clear-definitions drs) - (insert-in-definitions drs expression) - (do-execute drs) - (let ([got (fetch-output/should-be-tested drs)]) - (unless (string=? result got) - (eprintf "FAILED: ~s ~s ~s test\n expected: ~s\n got: ~s\n" - (language) setting-name expression result got))))) - -(define (fetch-output/should-be-tested . args) - (regexp-replace (regexp - (string-append - (regexp-quote "") - "$")) - (apply fetch-output args) - "")) - -(define re:out-of-sync - (regexp - "WARNING: Interactions window is out of sync with the definitions window\\.")) - -(define (parse-number txt) - (cond - ((not txt) 0) - ((string=? txt "No") 0) - ((string=? txt "One") 1) - ((string=? txt "Two") 2) - (else (string->number txt)))) - -(define (parse-test-failure-header txt) - (cond - ((regexp-match #rx"^Ran ([NoOneTwo0-9]+) tests?.\n([NoOneTwo0-9]+) tests? passed.\n(([NoOneTwo0-9]+) signature violations?.)?" - txt) - => (lambda (match) - (let-values (((_ test-count-text test-passed-count-text __ signature-violations-count-text) - (apply values match))) - (values (parse-number test-count-text) - (parse-number test-passed-count-text) - (parse-number signature-violations-count-text))))) - ((regexp-match #rx"^This program must be tested!\n(([NoOneTwo0-9]+) signature violations?.)?" txt) - => (lambda (match) - (values 0 0 (parse-number (caddr match))))) - (else - (error 'parse-test-failure-header "bad test failure header" txt)))) - -(define (parse-test-failures txt) - (let-values (((test-count test-passed-count signature-violations-count) - (parse-test-failure-header txt))) - (let ((check-failures - (cond - ((regexp-match #rx"Check failures:\n(.*)" txt) - => (lambda (res) - (parse-check-failures (cadr res)))) - (else '()))) - (signature-violations - (cond - ((regexp-match #rx"Signature violations:\n(.*)" txt) - => (lambda (res) - (parse-signature-violations (cadr res)))) - (else '())))) - (values test-count test-passed-count signature-violations-count - check-failures - signature-violations)))) - -(define-struct check-expect-failure - (actual expected line column) - #:transparent) - -(define-struct check-within-failure - (actual within expected line column) - #:transparent) - -(define-struct check-expect-error - (value message line column expr-line expr-column) - #:transparent) - -(define (parse-check-failures txt) - (cond - ((string=? txt "") '()) - ((regexp-match #rx"^Signature violations:" txt) - '()) - ((regexp-match #rx"^[ \t]*\n(.*)" txt) - => (lambda (match) - (parse-check-failures (cadr match)))) - ((regexp-match #rx"^[ \t]+Actual value ([^\n]+) differs from ([^\n]+), the expected value.\nat line ([0-9]+), column ([0-9]+)(.*)" - txt) - => (lambda (match) - (let-values (((_ actual expected line-text col-text rest) (apply values match))) - (cons - (make-check-expect-failure actual expected - (string->number line-text) - (string->number col-text)) - (parse-check-failures rest))))) - ((regexp-match #rx"^[ \t]+check-expect encountered the following error instead of the expected value, ([^\n]*). *\n[ \t]*([^\n]*)\n[^\n]*line ([0-9]+), column ([0-9]+)[^\n]*line ([0-9]+), column ([0-9]+)(.*)" - txt) - => (lambda (match) - (define-values (_ value message line-text col-text line-expr col-expr rest) (apply values match)) - (cons - (make-check-expect-error value - message - (string->number line-text) - (string->number col-text) - (string->number line-expr) - (string->number col-expr)) - (parse-check-failures rest)))) - ((regexp-match #rx"^[ \t]+Actual value ([^\n]+) is not within ([^\n]+) of expected value ([^\n]+).\nat line ([0-9]+), column ([0-9]+)(.*)" - txt) - => (lambda (match) - (define-values (_ actual within expected line-text col-text rest) (apply values match)) - (cons - (make-check-within-failure actual within expected - (string->number line-text) - (string->number col-text)) - (parse-check-failures rest)))) - (else - (error "unknown check failure" txt (string-ref txt 0))))) - -(define-struct signature-violation - (got line column) - #:transparent) - -(define (parse-signature-violations txt) - (cond - ((string=? txt "") '()) - ((regexp-match #rx"^[ \t]*\n(.*)" txt) - => (lambda (match) - (parse-signature-violations (cadr match)))) - ((regexp-match "got ([^\n]+), signature at line ([0-9]+), column ([0-9]+)(.*)" - txt) - => (lambda (match) - (let-values (((_ got line-text col-text rest) (apply values match))) - (cons - (make-signature-violation got - (string->number line-text) - (string->number col-text)) - (parse-signature-violations rest))))) - (else '()))) - - -;; types an expression in the definitions window, executes it and tests the output -;; types an expression in the REPL and tests the output from the REPL. -(define (test-expression expression defs-expected - #:repl-expression (repl-expression expression) - #:repl-expected (repl-expected defs-expected) - #:check-failures-expected (check-failures-expected '()) - #:signature-violations-expected (signature-violations-expected '()) - #:repl-check-failures-expected (repl-check-failures-expected '()) - #:repl-signature-violations-expected (repl-signature-violations-expected '())) - (let* ([drs (wait-for-drracket-frame)] - [interactions-text (queue-callback/res (λ () (send drs get-interactions-text)))] - [definitions-text (queue-callback/res (λ () (send drs get-definitions-text)))] - [handle-definition-insertion - (lambda (item) - (insert-in-definitions drs item))] - [handle-interaction-insertion - (lambda (item) - (insert-in-interactions drs item))] - [check-expectation - (lambda (expected got) - (cond - [(string? expected) - (whitespace-string=? expected got)] - [(regexp? expected) - (regexp-match expected got)] - [(procedure? expected) - (expected got)]))] - [check-failures - (lambda (where signature-violations-expected check-failures-expected) - (let ((text - (cond - ((send (send definitions-text get-tab) get-test-editor) - => (lambda (test-editor) - (let ((text (send test-editor get-text 0 'eof #t))) - (if (string=? text "") - #f - text)))) - (else #f)))) - - (cond - ((and (null? signature-violations-expected) - (null? check-failures-expected)) - (when text - (eprintf "FAILED: ~s ~s expected ~s to produce no check failures or signature violations:\ngot:\n~a\ninstead\n" - where (language) expression text))) - (text - (let-values (((test-count test-passed-count signature-violation-count check-failures signature-violations) - (parse-test-failures text))) - (when (not (equal? check-failures check-failures-expected)) - (eprintf "FAILED: ~s ~s expected ~s to produce check failures:\n~s\ngot:\n~s\ninstead\n" - where (language) expression check-failures-expected check-failures)) - (when (not (equal? signature-violations signature-violations-expected)) - (eprintf "FAILED: ~s ~s expected ~s to produce signature violations:\n~s\ngot:\n~s\ninstead\n" - where (language) expression signature-violations-expected signature-violations)))) - (else - (eprintf "expected ~a check failures and ~a signature violations but got none" - (length check-failures-expected) (length signature-violations-expected))))))] - - [make-err-msg - (lambda (expected) - (cond - [(string? expected) - "FAILED: ~s ~s expected ~s to produce:\n ~s\ngot:\n ~s\ninstead\n"] - [(regexp? expected) - "FAILED: ~s ~s expected ~s to match ~s, got ~s instead\n"] - [(procedure? expected) - "FAILED: ~s ~s expected ~s to pass predicate ~s, got ~s\n"]))]) - (clear-definitions drs) - (cond - [(pair? expression) (for-each handle-definition-insertion expression)] - [else (handle-definition-insertion expression)]) - (do-execute drs) - - (let ([got - (fetch-output - drs - (queue-callback/res (λ () (send interactions-text paragraph-start-position 2))) - (queue-callback/res - (λ () - (send interactions-text paragraph-end-position - (- (send interactions-text last-paragraph) 1)))))]) - (when (regexp-match re:out-of-sync got) - (error 'test-expression "got out of sync message")) - (unless (check-expectation defs-expected got) - (eprintf (make-err-msg defs-expected) - 'definitions (language) expression defs-expected got))) - - (check-failures 'definitions signature-violations-expected check-failures-expected) - - (cond - [(pair? repl-expression) (for-each handle-interaction-insertion repl-expression)] - [else (handle-interaction-insertion repl-expression)]) - - (let ([last-para (queue-callback/res (lambda () (send interactions-text last-paragraph)))]) - (alt-return-in-interactions drs) - (wait-for-computation drs) - (let ([got - (fetch-output - drs - (queue-callback/res - (λ () - (send interactions-text paragraph-start-position (+ last-para 1)))) - (queue-callback/res - (λ () - (send interactions-text paragraph-end-position - (- (send interactions-text last-paragraph) 1)))))]) - (when (regexp-match re:out-of-sync got) - (error 'test-expression "got out of sync message")) - (unless (check-expectation repl-expected got) - (eprintf (make-err-msg repl-expected) 'interactions (language) expression repl-expected got)))) - - ;; the failures from the definition window stick around - (check-failures 'interactions - (append signature-violations-expected repl-signature-violations-expected) - (append check-failures-expected repl-check-failures-expected)))) - -(define (test-disabling-tests) - (define drs (wait-for-drracket-frame)) - - (parameterize ([language (list #rx"Beginning Student(;|$)")]) - (prepare-for-test-expression) - (test:menu-select "Racket" "Disable Tests") - (test-expression "(check-expect 1 2)" "Tests disabled.") - (test:menu-select "Racket" "Enable Tests")) - - (parameterize ([language (list #rx"Schreibe Dein Programm! - Anfänger(;|$)")]) - (prepare-for-test-expression) - (test:menu-select "Racket" "Disable Tests") - (test-expression "(check-expect 1 2)" "Tests disabled.") - (test:menu-select "Racket" "Enable Tests"))) - -(define-syntax (go stx) - (syntax-case stx () - [(_ arg) - (identifier? (syntax arg)) - (syntax (begin (printf ">> starting ~a\n" 'arg) - (arg) - (printf ">> finished ~a\n" 'arg)))])) - -(define (run-test) - (preferences:set 'test-engine:test-window:docked? #t) - (go beginner) - (go beginner/abbrev) - (go intermediate) - (go intermediate/lambda) - (go advanced) - (go sdp-beginner) - (go sdp-vanilla) - (go sdp-advanced) - (go test-disabling-tests)) - -(fire-up-drracket-and-run-tests run-test) - -(module+ test - (module config info - (define timeout 480)))