Allowing paths in convert-file and changing test to not be sensitive to cwd

This commit is contained in:
Jay McCarthy 2011-08-20 08:14:19 -06:00
parent 9f6862d12e
commit 994092ea33
2 changed files with 8 additions and 5 deletions

View File

@ -237,12 +237,12 @@
;; convert-file : str (num -> num) str -> void
;; to read a number from file in, to convert it with f, and to write it to out
(define (convert-file in f out)
(check-arg 'convert-file (string? in) "string" "first" in)
(check-arg 'convert-file (path-string? in) "string" "first" in)
(check-arg 'convert-file (file-exists? in)
(format "name of existing file in ~a" (current-directory))
"first" in)
(check-proc 'convert-file f 1 "convert-file" "one argument")
(check-arg 'convert-file (string? out) "string" "third" out)
(check-arg 'convert-file (path-string? out) "string" "third" out)
;; [ -> Void] -> Void
;; perform the actual conversion on the file after optionally reading a prelude
(define (convert-file prefix)

View File

@ -1,12 +1,15 @@
#lang racket
(require racket/runtime-path
htdp/convert)
(require htdp/convert)
(define-runtime-path non-error-pth "convert-drracket-non-error.txt")
(define-runtime-path error-pth "convert-drracket-error.txt")
(define (Fahrenheit->Celsius x) (* (/ 100 180) (- x 32)))
(convert-file "convert-drracket-non-error.txt" Fahrenheit->Celsius "out.dat")
(convert-file non-error-pth Fahrenheit->Celsius "out.dat")
(with-handlers ((exn:fail:read? void))
"The input file contains a bad header. The next line should raise an exn."
(convert-file "convert-drracket-error.txt" Fahrenheit->Celsius "out.dat")
(convert-file error-pth Fahrenheit->Celsius "out.dat")
(raise `(test "this test should have failed but didn't")))