Added a /dev/null-like output port to unstable.

This commit is contained in:
Vincent St-Amour 2010-05-24 18:32:33 -04:00
parent 3b90cdb872
commit 9c12b7d2e7
5 changed files with 61 additions and 0 deletions

View File

@ -1802,6 +1802,7 @@ path/s is either such a string or a list of them.
"collects/tests/units/test-unit.rktl" drdr:command-line (racket "-f" *)
"collects/tests/unstable/byte-counting-port.rkt" responsible (jay)
"collects/tests/unstable/generics.rkt" responsible (jay)
"collects/tests/unstable/port.rkt" responsible (stamourv)
"collects/tests/unstable/srcloc.rktl" responsible (cce) drdr:command-line (racket "-f" *)
"collects/tests/utils" responsible (unknown)
"collects/tests/utils/gui.rkt" drdr:command-line (gracket-text "-t" *)
@ -1848,12 +1849,14 @@ path/s is either such a string or a list of them.
"collects/unstable/match.rkt" responsible (samth)
"collects/unstable/mutated-vars.rkt" responsible (samth)
"collects/unstable/poly-c.rkt" responsible (samth)
"collects/unstable/port.rkt" responsible (stamourv)
"collects/unstable/scribblings/byte-counting-port.scrbl" responsible (jay)
"collects/unstable/scribblings/debug.scrbl" responsible (samth)
"collects/unstable/scribblings/hash.scrbl" responsible (samth)
"collects/unstable/scribblings/match.scrbl" responsible (samth)
"collects/unstable/scribblings/mutated-vars.scrbl" responsible (samth)
"collects/unstable/scribblings/poly-c.scrbl" responsible (samth)
"collects/unstable/scribblings/port.scrbl" responsible (stamourv)
"collects/unstable/scribblings/sequence.scrbl" responsible (samth)
"collects/unstable/scribblings/utils.rkt" responsible (samth)
"collects/unstable/sequence.rkt" responsible (samth)

View File

@ -0,0 +1,23 @@
#lang racket
(require unstable/port
test-engine/scheme-tests)
(check-expect (port? null-output-port)
#t)
(check-expect (with-output-to-string
(lambda ()
(parameterize ([current-output-port null-output-port])
(display "can't see me"))))
"")
(check-expect (with-output-to-string
(lambda ()
(display "now you see me")
(parameterize ([current-output-port null-output-port])
(display "now you don't"))
(display "you can see me again")))
"now you see meyou can see me again")
(test)

View File

@ -0,0 +1,18 @@
#lang racket/base
(provide null-output-port)
;; taken from section 12.1.9 of the reference
;; -- stamourv
(define null-output-port
(make-output-port
'null
always-evt
(lambda (s start end non-block? breakable?) (- end start))
void
(lambda (special non-block? breakable?) #t)
(lambda (s start end) (wrap-evt
always-evt
(lambda (x)
(- end start))))
(lambda (special) always-evt)))

View File

@ -0,0 +1,16 @@
#lang scribble/doc
@(require scribble/base
scribble/manual
"utils.rkt"
(for-label unstable/port
racket/base))
@title[#:tag "port"]{Port}
@defmodule[unstable/port]
@unstable[@author+email["Vincent St-Amour" "stamourv@ccs.neu.edu"]]
@defthing[null-output-port output-port?]{
Output port that discards everything written to it.
}

View File

@ -90,6 +90,7 @@ Keep documentation and tests up to date.
@include-section["sequence.scrbl"]
@include-section["hash.scrbl"]
@include-section["match.scrbl"]
@include-section["port.scrbl"]
@include-section["skip-list.scrbl"]
@include-section["interval-map.scrbl"]
@include-section["generics.scrbl"]