I have the following Racket code.
#lang racket
(require rackunit racket/exn)
(define (string-last s)
(let ((lng (string-length s)))
(substring s (- lng 1) lng)))
(string-last "")
(check-equal? (string-last "1") "1")
(check-equal? (string-last "testing") "g")
The call of string last with an empty string fails as expected with:
--------------------
. ERROR
name: check-exn
location: 014.rkt:12:0
substring: contract violation
expected: exact-nonnegative-integer?
given: -1
argument position: 2nd
other arguments...:
""
0
--------------------
How to check for the error by using RackUnit library?
I tried
(check-exn exn:fail? (string-last ""))
and several other variants in place of exn:fail?
but I didn't manage to find the right one.