racket / r6rs

Other
6 stars 9 forks source link

fix bytes->string error #1

Closed bennn closed 8 years ago

bennn commented 8 years ago

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.

stamourv commented 8 years ago

The change looks reasonable, but I'd be more comfortable with a test case.

bennn commented 8 years ago

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.

samth commented 8 years ago

Can't you put it in a string, and call read?

bennn commented 8 years ago

I think you're right. Looks like I was missing a "\" when I put it in a string the first time.

bennn commented 8 years ago

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).

rfindler commented 8 years ago

I generally use a regexp-match on the exn-message field of the exception record that gets raised.

bennn commented 8 years ago

That's my problem, I haven't found the equivalent of exn-message in r6rs.

samth commented 8 years ago

I think you want condition-message.

bennn commented 8 years ago

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"
samth commented 8 years ago

That result certainly seems to have enough information to test using @rfindler's suggestion.

rfindler commented 8 years ago

Why not write the test in racket and just have it call into r6rs's read?

rfindler commented 8 years ago

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;")))
bennn commented 8 years ago

@rfindler thank you that's exactly what I needed

bennn commented 8 years ago

(@stamourv ok to merge?)

stamourv commented 8 years ago

Sure, LGTM