From 13d9f636108ba94785667328bf3e27c9705d012e Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Fri, 4 May 2012 16:55:09 -0400 Subject: [PATCH] [Style] added sub-modules for testing to 'unit' section, Eli's email from 30 April 2012 --- collects/scribblings/style/retiquette.html | 2 +- collects/scribblings/style/unit.scrbl | 41 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/collects/scribblings/style/retiquette.html b/collects/scribblings/style/retiquette.html index 6d1ee8d8c8..5482f3d89c 100644 --- a/collects/scribblings/style/retiquette.html +++ b/collects/scribblings/style/retiquette.html @@ -18,7 +18,7 @@ Racketeers are expected to live up to the following rules: is to create a new example that re-creates the problem without involvement of their code; -
  • more +
    diff --git a/collects/scribblings/style/unit.scrbl b/collects/scribblings/style/unit.scrbl index 3b0453840c..8f663791b5 100644 --- a/collects/scribblings/style/unit.scrbl +++ b/collects/scribblings/style/unit.scrbl @@ -284,7 +284,7 @@ Pick a rule for consistently naming and ordering the parameters of your an abstract data type (ADT), all functions on the ADT should consume the ADT-argument first or last. -@subsection{Sections} +@subsection{Sections and Sub-modules} Finally, a module consists of sections. It is good practice to separate the sections with comment lines. You may want to write down purpose statements @@ -297,6 +297,45 @@ With @racketmodname[rackunit], test suites can be defined within the test section at the end of the module and @racket[require] the necessary pieces for testing specifically for the test suites. +As of version 5.3, Racket supports sub-modules. Use sub-modules to + formulate sections, especially test sections. With sub-modules it is now + possible to break up sections into distinct parts (labeled with the same + name) and leave it to the language to stitch pieces together. + +@;% +@codebox[ +@(begin +#reader scribble/comment-reader + (racketmod #:file + @tt{fahrenheit.rkt} + racket + +(module+ test + (require rackunit)) + +(provide/contract + (code:comment #, @t{convert a fahrenheit temperature to a celsius temperature}) + [fahrenheit->celsius (-> number? number?)]) + +(define (fahrenheit->celsius f) + (/ (* 5 (- f 32)) 9)) + +(module+ test + (check-equal? (fahrenheit->celsius -40) -40) + (check-equal? (fahrenheit->celsius 32) 0) + (check-equal? (fahrenheit->celsius 212) 100)) +))] +@;% + If you develop your code in DrRacket, it will run the test sub-module + every time you click ``run'' unless you explicitly disable this + functionality in the language selection menu. If you have a file and you + just wish to run the tests, use @tt{raco} to do so: +@verbatim[#:indent 2]{ +$ raco test fahrenheit.rkt +} + Running this command in a shell will require and evaluate the test + sub-module from the @tt{fahrenheit.rkt}. + @; ----------------------------------------------------------------------------- @section{Classes & Units}