diff --git a/collects/rackunit/private/check-info.rkt b/collects/rackunit/private/check-info.rkt index f518b5e..127c2cb 100644 --- a/collects/rackunit/private/check-info.rkt +++ b/collects/rackunit/private/check-info.rkt @@ -1,12 +1,21 @@ #lang racket/base - -(provide (all-defined-out)) +(require racket/contract + "location.rkt" + (for-syntax racket/base + unstable/syntax)) ;; Structures -------------------------------------------------- ;; struct check-info : symbol any (define-struct check-info (name value)) +(provide/contract + [struct check-info ([name symbol?] + [value any/c])] + [check-info-mark symbol?] + [check-info-stack (continuation-mark-set? . -> . (listof check-info?))] + [with-check-info* ((listof check-info?) (-> any) . -> . any)]) +(provide with-check-info) ;; Infrastructure ---------------------------------------------- @@ -22,43 +31,34 @@ (define current-marks (continuation-mark-set-first #f check-info-mark)) (with-continuation-mark - check-info-mark - (append (if current-marks current-marks null) info) - (thunk))) + check-info-mark + (append (if current-marks current-marks null) info) + (thunk))) (define-syntax with-check-info (syntax-rules () [(_ ((name val) ...) body ...) (with-check-info* - (list (make-check-info name val) ...) - (lambda () body ...))])) + (list (make-check-info name val) ...) + (lambda () body ...))])) -(define (make-check-name name) - (make-check-info 'name name)) -(define (make-check-params params) - (make-check-info 'params params)) -(define (make-check-location stx) - (make-check-info 'location stx)) -(define (make-check-expression msg) - (make-check-info 'expression msg)) -(define (make-check-message msg) - (make-check-info 'message msg)) -(define (make-check-actual param) - (make-check-info 'actual param)) -(define (make-check-expected param) - (make-check-info 'expected param)) +(define-syntax (define-check-type stx) + (syntax-case stx () + [(_ id contract) + (with-syntax + ([make-check-id (format-id #'id "make-check-~a" #'id)] + [check-id? (format-id #'id "check-~a?" #'id)]) + (syntax/loc stx + (begin (define (make-check-id a) (make-check-info 'id a)) + (define (check-id? info) (eq? (check-info-name info) 'id)) + (provide/contract + [make-check-id (contract . -> . check-info?)] + [check-id? (check-info? . -> . boolean?)]))))])) -(define (check-name? info) - (eq? (check-info-name info) 'name)) -(define (check-params? info) - (eq? (check-info-name info) 'params)) -(define (check-location? info) - (eq? (check-info-name info) 'location)) -(define (check-expression? info) - (eq? (check-info-name info) 'expression)) -(define (check-message? info) - (eq? (check-info-name info) 'message)) -(define (check-actual? info) - (eq? (check-info-name info) 'actual)) -(define (check-expected? info) - (eq? (check-info-name info) 'expected)) +(define-check-type name any/c) +(define-check-type params any/c) +(define-check-type location location/c) +(define-check-type expression any/c) +(define-check-type message any/c) +(define-check-type actual any/c) +(define-check-type expected any/c) diff --git a/collects/rackunit/private/check.rkt b/collects/rackunit/private/check.rkt index 2e504a5..c67285d 100644 --- a/collects/rackunit/private/check.rkt +++ b/collects/rackunit/private/check.rkt @@ -119,7 +119,7 @@ (syntax (lambda (formal ... [message #f] - #:location [location 'unknown] + #:location [location (list 'unknown #f #f #f #f)] #:expression [expression 'unknown]) ((current-check-around) (lambda () diff --git a/collects/rackunit/private/gui/config.rkt b/collects/rackunit/private/gui/config.rkt index de80e95..74d22b4 100644 --- a/collects/rackunit/private/gui/config.rkt +++ b/collects/rackunit/private/gui/config.rkt @@ -14,11 +14,11 @@ ;; Some of these are obsolete, given the preferences above. (define DETAILS-CANVAS-INIT-WIDTH 400) -(define FRAME-LABEL "RacUnit") +(define FRAME-LABEL "RackUnit") (define FRAME-INIT-HEIGHT 400) (define TREE-INIT-WIDTH 240) (define TREE-COLORIZE-CASES #t) -(define DIALOG-ERROR-TITLE "RacUnit: Error") +(define DIALOG-ERROR-TITLE "RackUnit: Error") (define STATUS-SUCCESS 'success) (define STATUS-FAILURE 'failure) (define STATUS-ERROR 'error) diff --git a/collects/rackunit/private/gui/controller.rkt b/collects/rackunit/private/gui/controller.rkt index 9d45086..4742523 100644 --- a/collects/rackunit/private/gui/controller.rkt +++ b/collects/rackunit/private/gui/controller.rkt @@ -25,9 +25,9 @@ ;; check-ready : -> void (define/private (check-ready) (unless view - (error 'racunit "The RacUnit GUI is no longer running.")) + (error 'rackunit "The RackUnit GUI is no longer running.")) (when (get-locked?) - (error 'racunit "The RacUnit GUI is locked and not accepting tests."))) + (error 'rackunit "The RackUnit GUI is locked and not accepting tests."))) ;; create-model : test suite<%>/#f -> result<%> (define/public (create-model test parent) diff --git a/collects/rackunit/private/gui/view.rkt b/collects/rackunit/private/gui/view.rkt index 84aec27..0372b99 100644 --- a/collects/rackunit/private/gui/view.rkt +++ b/collects/rackunit/private/gui/view.rkt @@ -308,11 +308,11 @@ still be there, just not visible? (super-new (width width) (height height)) (send (get-help-menu) delete) - (let ([racunit-menu + (let ([rackunit-menu (new menu% - (label "RacUnit") + (label "RackUnit") (parent (get-menu-bar)))]) - (menu-option/notify-box racunit-menu + (menu-option/notify-box rackunit-menu "Lock" (get-field locked? controller))) diff --git a/collects/rackunit/private/location.rkt b/collects/rackunit/private/location.rkt index 2a9fa1b..cace08e 100644 --- a/collects/rackunit/private/location.rkt +++ b/collects/rackunit/private/location.rkt @@ -1,17 +1,10 @@ #lang racket/base - -(require racket/list) - -(provide location-source - location-line - location-column - location-position - location-span - syntax->location - location->string) +(require racket/list + racket/contract) ;; type location = (list any number/#f number/#f number/#f number/#f) ;; location : source line column position span +(define location/c (list/c any/c (or/c number? false/c) (or/c number? false/c) (or/c number? false/c) (or/c number? false/c))) (define location-source first) (define location-line second) @@ -19,6 +12,16 @@ (define location-position fourth) (define location-span fifth) +(provide/contract + [location/c contract?] + [location-source (location/c . -> . any/c)] + [location-line (location/c . -> . (or/c number? false/c))] + [location-column (location/c . -> . (or/c number? false/c))] + [location-position (location/c . -> . (or/c number? false/c))] + [location-span (location/c . -> . (or/c number? false/c))] + [syntax->location (syntax? . -> . location/c)] + [location->string (location/c . -> . string?)]) + ;; syntax->location : syntax -> location (define (syntax->location stx) (list (syntax-source stx) diff --git a/collects/rackunit/scribblings/acknowledgements.scrbl b/collects/rackunit/scribblings/acknowledgements.scrbl index bdab109..dff31b0 100644 --- a/collects/rackunit/scribblings/acknowledgements.scrbl +++ b/collects/rackunit/scribblings/acknowledgements.scrbl @@ -3,7 +3,7 @@ @title{Acknowlegements} -The following people have contributed to RacUnit: +The following people have contributed to RackUnit: @itemize[ @item{Robby Findler pushed me to release version 3} @@ -12,7 +12,7 @@ The following people have contributed to RacUnit: suggested renaming @racket[test/text-ui]} @item{Dave Gurnell reported a bug in check-not-exn and - suggested improvements to RacUnit} + suggested improvements to RackUnit} @item{Danny Yoo reported a bug in and provided a fix for trim-current-directory} @@ -30,7 +30,7 @@ The following people have contributed to RacUnit: @item{Jose A. Ortega Ruiz alerted me a problem in the packaging system and helped fix it.} - @item{Sebastian H. Seidel provided help packaging RacUnit + @item{Sebastian H. Seidel provided help packaging RackUnit into a .plt} @item{Don Blaheta provided the method for grabbing line number diff --git a/collects/rackunit/scribblings/api.scrbl b/collects/rackunit/scribblings/api.scrbl index ea3467d..75dee08 100644 --- a/collects/rackunit/scribblings/api.scrbl +++ b/collects/rackunit/scribblings/api.scrbl @@ -1,7 +1,7 @@ #lang scribble/doc @(require "base.rkt") -@title[#:tag "api"]{RacUnit API} +@title[#:tag "api"]{RackUnit API} @defmodule[rackunit #:use-sources (rackunit)] diff --git a/collects/rackunit/scribblings/check.scrbl b/collects/rackunit/scribblings/check.scrbl index 5c50ce3..869bfc2 100644 --- a/collects/rackunit/scribblings/check.scrbl +++ b/collects/rackunit/scribblings/check.scrbl @@ -3,7 +3,7 @@ @title{Checks} -Checks are the basic building block of RacUnit. A check +Checks are the basic building block of RackUnit. A check checks some condition. If the condition holds the check evaluates to @racket[#t]. If the condition doesn't hold the check raises an instance of @racket[exn:test:check] with @@ -16,7 +16,7 @@ their arguments. You can use check as first class functions, though you will lose precision in the reported source locations if you do so. -The following are the basic checks RacUnit provides. You +The following are the basic checks RackUnit provides. You can create your own checks using @racket[define-check]. @defproc[(check (op (-> any any any)) diff --git a/collects/rackunit/scribblings/compound-testing.scrbl b/collects/rackunit/scribblings/compound-testing.scrbl index 8a0fb71..8b5016e 100644 --- a/collects/rackunit/scribblings/compound-testing.scrbl +++ b/collects/rackunit/scribblings/compound-testing.scrbl @@ -147,7 +147,7 @@ creates test cases within the suite, with the given names and body expressions. As far I know no-one uses this macro, so it might disappear -in future versions of RacUnit.} +in future versions of RackUnit.} } diff --git a/collects/rackunit/scribblings/control-flow.scrbl b/collects/rackunit/scribblings/control-flow.scrbl index 59758d4..56a7307 100644 --- a/collects/rackunit/scribblings/control-flow.scrbl +++ b/collects/rackunit/scribblings/control-flow.scrbl @@ -48,5 +48,5 @@ file. The after action deletes it. This somewhat curious macro evaluates the given tests in a context where @racket[current-test-case-around] is parameterized to @racket[test-suite-test-case-around]. This -has been useful in testing RacUnit. It might be useful +has been useful in testing RackUnit. It might be useful for you if you create test cases that create test cases.} diff --git a/collects/rackunit/scribblings/misc.scrbl b/collects/rackunit/scribblings/misc.scrbl index f3cdf3b..2b0c3f3 100644 --- a/collects/rackunit/scribblings/misc.scrbl +++ b/collects/rackunit/scribblings/misc.scrbl @@ -14,7 +14,7 @@ Note that @racket[require/expose] can be a bit fragile, especially when mixed with compiled code. Use at your own risk! } -This example gets @racket[make-failure-test], which is defined in a RacUnit test: +This example gets @racket[make-failure-test], which is defined in a RackUnit test: @racketblock[ (require/expose rackunit/private/check-test (make-failure-test)) diff --git a/collects/rackunit/scribblings/overview.scrbl b/collects/rackunit/scribblings/overview.scrbl index 8645271..bc3aec4 100644 --- a/collects/rackunit/scribblings/overview.scrbl +++ b/collects/rackunit/scribblings/overview.scrbl @@ -1,9 +1,9 @@ #lang scribble/doc @(require "base.rkt") -@title{Overview of RacUnit} +@title{Overview of RackUnit} -There are three basic data types in RacUnit: +There are three basic data types in RackUnit: @itemize[ diff --git a/collects/rackunit/scribblings/philosophy.scrbl b/collects/rackunit/scribblings/philosophy.scrbl index bf776e6..4d0434c 100644 --- a/collects/rackunit/scribblings/philosophy.scrbl +++ b/collects/rackunit/scribblings/philosophy.scrbl @@ -1,10 +1,10 @@ #lang scribble/doc @(require "base.rkt") -@title[#:tag "philosophy"]{The Philosophy of RacUnit} +@title[#:tag "philosophy"]{The Philosophy of RackUnit} -RacUnit is designed to allow tests to evolve in step with -the evolution of the program under testing. RacUnit +RackUnit is designed to allow tests to evolve in step with +the evolution of the program under testing. RackUnit scales from the unstructed checks suitable for simple programs to the complex structure necessary for large projects. @@ -25,9 +25,9 @@ checking are of the form: (equal? (length '(a b)) 2) ] -RacUnit directly supports this style of testing. A check +RackUnit directly supports this style of testing. A check on its own is a valid test. So the above examples may be -written in RacUnit as: +written in RackUnit as: @racketblock[ (check-equal? (length null) 0) @@ -35,7 +35,7 @@ written in RacUnit as: (check-equal? (length '(a b)) 2) ] -Simple programs now get all the benefits of RacUnit with +Simple programs now get all the benefits of RackUnit with very little overhead. There are limitations to this style of testing that more @@ -45,7 +45,7 @@ it does not make sense to evaluate some expressions if earlier ones have failed. This type of program needs a way to group expressions so that a failure in one group causes evaluation of that group to stop and immediately proceed to -the next group. In RacUnit all that is required is to +the next group. In RackUnit all that is required is to wrap a @racket[test-begin] expression around a group of expressions: @@ -62,7 +62,7 @@ be evaluated. Notice that all the previous tests written in the simple style are still valid. Introducing grouping is a local -change only. This is a key feature of RacUnit's support +change only. This is a key feature of RackUnit's support for the evolution of the program. The programmer may wish to name a group of tests. This is @@ -79,7 +79,7 @@ Most programs will stick with this style. However, programmers writing very complex programs may wish to maintain separate groups of tests for different parts of the program, or run their tests in different ways to the normal -RacUnit manner (for example, test results may be logged +RackUnit manner (for example, test results may be logged for the purpose of improving software quality, or they may be displayed on a website to indicate service quality). For these programmers it is necessary to delay the execution of @@ -104,15 +104,15 @@ outside the suite continue to evaluate as before. @section{Historical Context} Most testing frameworks, including earlier versions of -RacUnit, support only the final form of testing. This is +RackUnit, support only the final form of testing. This is likely due to the influence of the SUnit testing framework, -which is the ancestor of RacUnit and the most widely used +which is the ancestor of RackUnit and the most widely used frameworks in Java, .Net, Python, and Ruby, and many other languages. That this is insufficient for all users is apparent if one considers the proliferation of ``simpler'' testing frameworks in Racket such as SRFI-78, or the practice of beginner programmers. Unfortunately these simpler methods are inadequate for testing larger -systems. To the best of my knowledge RacUnit is the only +systems. To the best of my knowledge RackUnit is the only testing framework that makes a conscious effort to support the testing style of all levels of programmer. diff --git a/collects/rackunit/scribblings/quick-start.scrbl b/collects/rackunit/scribblings/quick-start.scrbl index a7088ed..ed4c80f 100644 --- a/collects/rackunit/scribblings/quick-start.scrbl +++ b/collects/rackunit/scribblings/quick-start.scrbl @@ -1,7 +1,7 @@ #lang scribble/doc @(require "base.rkt") -@title[#:tag "quick-start"]{Quick Start Guide for RacUnit} +@title[#:tag "quick-start"]{Quick Start Guide for RackUnit} Suppose we have code contained in @tt{file.rkt}, which implements buggy versions of @racket[+] and @racket[-] @@ -24,10 +24,10 @@ racket/base my-*) ] -We want to test this code with RacUnit. We start by +We want to test this code with RackUnit. We start by creating a file called @tt{file-test.rkt} to contain our tests. At the top of @tt{file-test.rkt} we import -RacUnit and @tt{file.rkt}: +RackUnit and @tt{file.rkt}: @racketmod[ racket/base @@ -43,7 +43,7 @@ Now we add some tests to check our library: (check-equal? (my-* 1 2) 2 "Simple multiplication") ] -This is all it takes to define tests in RacUnit. Now +This is all it takes to define tests in RackUnit. Now evaluate this file and see if the library is correct. Here's the result I get: @@ -63,13 +63,13 @@ expected: 2 The first @racket[#t] indicates the first test passed. The second test failed, as shown by the message. -Requiring RacUnit and writing checks is all you need to +Requiring RackUnit and writing checks is all you need to get started testing, but let's take a little bit more time to look at some features beyond the essentials. Let's say we want to check that a number of properties hold. How do we do this? So far we've only seen checks of a -single expression. In RacUnit a check is always a single +single expression. In RackUnit a check is always a single expression, but we can group checks into units called test cases. Here's a simple test case written using the @racket[test-begin] form: @@ -147,7 +147,7 @@ tests, allowing you to choose how you run your tests. You might, for example, print the results to the screen or log them to a file. -Let's run our tests, using RacUnit's simple textual user +Let's run our tests, using RackUnit's simple textual user interface (there are fancier interfaces available but this will do for our example). In @tt{file-test.rkt} add the following lines: @@ -161,6 +161,6 @@ following lines: Now evaluate the file and you should see similar output again. -These are the basics of RacUnit. Refer to the +These are the basics of RackUnit. Refer to the documentation below for more advanced topics, such as defining your own checks. Have fun! diff --git a/collects/rackunit/scribblings/rackunit.scrbl b/collects/rackunit/scribblings/rackunit.scrbl index aa98ed2..c8bdc2b 100644 --- a/collects/rackunit/scribblings/rackunit.scrbl +++ b/collects/rackunit/scribblings/rackunit.scrbl @@ -1,12 +1,12 @@ #lang scribble/doc @(require "base.rkt") -@title{@bold{RacUnit}: Unit Testing for Racket} +@title{@bold{RackUnit}: Unit Testing for Racket} @author[(author+email "Noel Welsh" "noelwelsh@gmail.com") (author+email "Ryan Culpepper" "ryan_sml@yahoo.com")] -RacUnit is a unit-testing framework for Racket. It +RackUnit is a unit-testing framework for Racket. It is designed to handle the needs of all Racket programmers, from novices to experts. diff --git a/collects/rackunit/scribblings/release-notes.scrbl b/collects/rackunit/scribblings/release-notes.scrbl index 2015dc4..a4f0bed 100644 --- a/collects/rackunit/scribblings/release-notes.scrbl +++ b/collects/rackunit/scribblings/release-notes.scrbl @@ -12,7 +12,7 @@ There are also miscellaneous Scribble fixes. @section{Version 3} -This version of RacUnit is largely backwards compatible +This version of RackUnit is largely backwards compatible with version 2 but there are significant changes to the underlying model, justifying incrementing the major version number. These changes are best explained in diff --git a/collects/rackunit/scribblings/ui.scrbl b/collects/rackunit/scribblings/ui.scrbl index 3015f1d..f77e6cc 100644 --- a/collects/rackunit/scribblings/ui.scrbl +++ b/collects/rackunit/scribblings/ui.scrbl @@ -3,7 +3,7 @@ @title[#:tag "ui"]{User Interfaces} -RacUnit provides a textual and a graphical user interface +RackUnit provides a textual and a graphical user interface @section{Textual User Interface} @@ -35,13 +35,13 @@ information. @defmodule[rackunit/gui] -RacUnit also provides a GUI test runner, available from the +RackUnit also provides a GUI test runner, available from the @racketmodname[rackunit/gui] module. @defproc[(test/gui [test (or/c test-case? test-suite?)] ...) any]{ -Creates a new RacUnit GUI window and runs each @racket[test]. The +Creates a new RackUnit GUI window and runs each @racket[test]. The GUI is updated as tests complete. } @@ -49,7 +49,7 @@ GUI is updated as tests complete. @defproc[(make-gui-runner) (-> (or/c test-case? test-suite?) ... any)]{ -Creates a new RacUnit GUI window and returns a procedure that, when +Creates a new RackUnit GUI window and returns a procedure that, when applied, runs the given tests and displays the results in the GUI. } diff --git a/collects/tests/rackunit/all-rackunit-tests.rkt b/collects/tests/rackunit/all-rackunit-tests.rkt index 2cb4b03..86fe329 100644 --- a/collects/tests/rackunit/all-rackunit-tests.rkt +++ b/collects/tests/rackunit/all-rackunit-tests.rkt @@ -22,7 +22,7 @@ (define all-rackunit-tests (test-suite - "All RacUnit Tests" + "All RackUnit Tests" check-tests base-tests check-info-tests diff --git a/collects/tests/rackunit/check-info-test.rkt b/collects/tests/rackunit/check-info-test.rkt index a95ffe6..15e3cbc 100644 --- a/collects/tests/rackunit/check-info-test.rkt +++ b/collects/tests/rackunit/check-info-test.rkt @@ -2,22 +2,22 @@ ;;; ---- Tests for check-util ;;; Time-stamp: <2009-06-11 17:03:21 noel> ;;; -;;; Copyright (C) 2003 by Noel Welsh. +;;; Copyright (C) 2003 by Noel Welsh. ;;; -;;; This file is part of RacUnit. +;;; This file is part of RackUnit. -;;; RacUnit is free software; you can redistribute it and/or +;;; RackUnit is free software; you can redistribute it and/or ;;; modify it under the terms of the GNU Lesser General Public ;;; License as published by the Free Software Foundation; either ;;; version 2.1 of the License, or (at your option) any later version. -;;; RacUnitis distributed in the hope that it will be useful, +;;; RackUnit is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; Lesser General Public License for more details. ;;; You should have received a copy of the GNU Lesser General Public -;;; License along with RacUnit; if not, write to the Free Software +;;; License along with RackUnit; if not, write to the Free Software ;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;;; Author: Noel Welsh diff --git a/collects/tests/rackunit/pr10950.rkt b/collects/tests/rackunit/pr10950.rkt new file mode 100644 index 0000000..1663aaa --- /dev/null +++ b/collects/tests/rackunit/pr10950.rkt @@ -0,0 +1,16 @@ +#lang racket/base +(require rackunit + rackunit/text-ui + racket/port + tests/eli-tester) + +(test + (with-output-to-string + (lambda () + (parameterize ([current-error-port (current-output-port)]) + (define-check (check3) + (fail-check)) + + (run-tests (test-suite "tests" (let ((foo check3)) (foo))))))) + => + "--------------------\ntests > #f\nUnnamed test \nFAILURE\nname: check3\nlocation: unknown:?:?\nparams: \n--------------------\n0 success(es) 1 failure(s) 0 error(s) 1 test(s) run\n") \ No newline at end of file