From b985efc28c307b1a4b44de079060ea8d7b152dcf Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 30 Jun 2011 15:59:46 -0400 Subject: [PATCH 1/2] browser-harness.rkt to make it easier to run the tests --- tests/browser-evaluate.rkt | 6 ++ tests/browser-harness.rkt | 90 +++++++++++++++++++++++++++++ tests/more-tests/hello.expected | 1 + tests/more-tests/hello.rkt | 2 + tests/more-tests/run-more-tests.rkt | 5 ++ tests/test-all.rkt | 3 +- 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/browser-harness.rkt create mode 100644 tests/more-tests/hello.expected create mode 100644 tests/more-tests/hello.rkt create mode 100644 tests/more-tests/run-more-tests.rkt diff --git a/tests/browser-evaluate.rkt b/tests/browser-evaluate.rkt index fbcc48a..b13589d 100644 --- a/tests/browser-evaluate.rkt +++ b/tests/browser-evaluate.rkt @@ -225,7 +225,10 @@ var comet = function() { $(document.body).append(v); output.push($(v).text()); } }; + var successCalled = false; var onSuccess = function(v) { + if (successCalled) { return; } + successCalled = true; endTime = new Date(); sendRequest("/eval", function(req) { setTimeout(comet, 0); }, "v=" + encodeURIComponent(String(v)) + @@ -234,7 +237,10 @@ var comet = function() { "&b=" + encodeURIComponent(String(BrowserDetect.browser + ' ' + BrowserDetect.version + '/' + BrowserDetect.OS))); }; + var failCalled = false; var onFail = function(machine, e) { + if (failCalled) { return; } + failCalled = true; endTime = new Date(); sendRequest("/eval", function(req) { setTimeout(comet, 0); }, "e=" + encodeURIComponent(String(e.stack || e)) + diff --git a/tests/browser-harness.rkt b/tests/browser-harness.rkt new file mode 100644 index 0000000..09650e1 --- /dev/null +++ b/tests/browser-harness.rkt @@ -0,0 +1,90 @@ +#lang racket/base + + +;; Provides a harness for running programs on the browser and +;; examining their results. + +;; Provides a test form that expects the path of a program and its +;; expected output. + + +(require "browser-evaluate.rkt" + "../js-assembler/package.rkt" + "../make/make-structs.rkt" + racket/port + racket/path + racket/runtime-path + racket/runtime-path + (for-syntax racket/base + racket/port)) + +(define evaluate (make-evaluate + (lambda (program op) + + (fprintf op "(function () {") + + (displayln (get-runtime) op) + + (newline op) + + (fprintf op "var innerInvoke = ") + (package-anonymous program + #:should-follow-children? (lambda (src) #t) + #:output-port op) + (fprintf op "();\n") + + (fprintf op #<string)]) + (quasisyntax/loc #'stx + (begin + (printf "running test on ~s..." source-file-path) + (let* ([src-path (normalize-path source-file-path)] + [result (evaluate (make-MainModuleSource (make-ModuleSource src-path)))] + [output (evaluated-stdout result)]) + (cond [(string=? output exp) + (printf " ok (~a milliseconds)\n" (evaluated-t result))] + [else + (printf " error!\n") + (raise (make-exn:fail:error-on-test + (format "Expected ~s, got ~s" exp output) + (current-continuation-marks) + (srcloc '#,(syntax-source #'stx) + '#,(syntax-line #'stx) + '#,(syntax-column #'stx) + '#,(syntax-position #'stx) + '#,(syntax-span #'stx))))])))))])) + + + +(provide test) \ No newline at end of file diff --git a/tests/more-tests/hello.expected b/tests/more-tests/hello.expected new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/tests/more-tests/hello.expected @@ -0,0 +1 @@ +hello world diff --git a/tests/more-tests/hello.rkt b/tests/more-tests/hello.rkt new file mode 100644 index 0000000..b84ace1 --- /dev/null +++ b/tests/more-tests/hello.rkt @@ -0,0 +1,2 @@ +#lang planet dyoo/whalesong +(displayln "hello world") diff --git a/tests/more-tests/run-more-tests.rkt b/tests/more-tests/run-more-tests.rkt new file mode 100644 index 0000000..460ca52 --- /dev/null +++ b/tests/more-tests/run-more-tests.rkt @@ -0,0 +1,5 @@ +#lang racket + +(require "../browser-harness.rkt") + +(test "hello.rkt" "hello.expected") \ No newline at end of file diff --git a/tests/test-all.rkt b/tests/test-all.rkt index fd3e6a8..52c684e 100644 --- a/tests/test-all.rkt +++ b/tests/test-all.rkt @@ -10,7 +10,8 @@ "test-package.rkt" "test-conform-browser.rkt" "test-earley-browser.rkt" - "test-get-dependencies.rkt") + "test-get-dependencies.rkt" + "more-tests/run-more-tests.rkt") ;; This test takes a bit too much time. From e3aed9b884aff00e6924a166fc86628d8dfd1187 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 30 Jun 2011 16:14:47 -0400 Subject: [PATCH 2/2] motivating the need for make-struct-type --- tests/more-tests/run-more-tests.rkt | 3 ++- tests/more-tests/simple-structs.expected | 2 ++ tests/more-tests/simple-structs.rkt | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/more-tests/simple-structs.expected create mode 100644 tests/more-tests/simple-structs.rkt diff --git a/tests/more-tests/run-more-tests.rkt b/tests/more-tests/run-more-tests.rkt index 460ca52..95d2da9 100644 --- a/tests/more-tests/run-more-tests.rkt +++ b/tests/more-tests/run-more-tests.rkt @@ -2,4 +2,5 @@ (require "../browser-harness.rkt") -(test "hello.rkt" "hello.expected") \ No newline at end of file +(test "hello.rkt" "hello.expected") +(test "simple-structs.rkt" "simple-structs.expected") \ No newline at end of file diff --git a/tests/more-tests/simple-structs.expected b/tests/more-tests/simple-structs.expected new file mode 100644 index 0000000..b944734 --- /dev/null +++ b/tests/more-tests/simple-structs.expected @@ -0,0 +1,2 @@ +3 +4 diff --git a/tests/more-tests/simple-structs.rkt b/tests/more-tests/simple-structs.rkt new file mode 100644 index 0000000..35f21dc --- /dev/null +++ b/tests/more-tests/simple-structs.rkt @@ -0,0 +1,6 @@ +#lang planet dyoo/whalesong +(define-struct p (f r)) + +(define p1 (make-p 3 4)) +(p-f p1) +(p-r p1)