Closed bennn closed 8 years ago
The change looks reasonable, but I'd be more comfortable with a test case.
Found a test case. We definitely get a bytes->string
contract error without this PR.
But the test isn't part of the "automated" suite because I don't see how to catch reader errors in an r6rs module. Any suggestions? Or can we just merge this change and the orphan test file.
Can't you put it in a string, and call read
?
I think you're right. Looks like I was missing a "\" when I put it in a string the first time.
Thanks Sam.
This test case is closer but it's still not right. I haven't figured out how to tell apart the right exception ("out of range escape") from the wrong one (bytes->string
).
I generally use a regexp-match on the exn-message field of the exception record that gets raised.
That's my problem, I haven't found the equivalent of exn-message
in r6rs.
I think you want condition-message
.
Yes I did try that:
(test
(condition-message (read (open-string-input-port "\\xDDDD;")))
"hi")
and got:
Expression:
(condition-message (read (open-string-input-port "\\xDDDD;")))
Result:
#(struct:err #(struct:exn:fail:read "out of range escape: `\\xDDDD;'" #<continuation-mark-set> (#(struct:srcloc #f #f #f 1 7))))
Expected:
"hi"
That result certainly seems to have enough information to test using @rfindler's suggestion.
Why not write the test in racket and just have it call into r6rs's read
?
Here's a start on an r6 program, in case it helps.
#lang r6rs
(import (rnrs conditions (6))
(rnrs io simple (6))
(rnrs io ports (6))
(rnrs exceptions (6))
(rnrs base (6)))
(guard (con
((violation? con)
(display (condition-message con))
'violation))
(read (open-string-input-port "\\xDDDD;")))
@rfindler thank you that's exactly what I needed
(@stamourv ok to merge?)
Sure, LGTM
thing
is defined as a string on L446, so calling(bytes->string/utf-8 thing)
on L478 would raise a contract error.Though I don't have a test case that proves it.