florence / cover

a code coverage tool for racket
MIT License
38 stars 7 forks source link

in format-utils.rkt vector-ref: contract violation, given: -1 #129

Closed SuzanneSoy closed 7 years ago

SuzanneSoy commented 8 years ago

See travis build logs: https://travis-ci.org/jsmaniac/repltest/jobs/153136245#L378

The error happens only when the file test/doc2-no-newline-at-end-of-file.rkt is present, the same file with a newline at the end works fine.

I narrowed down the problem to make-byte->str-offset, which creates an empty mapping when str is the empty string "". The (lambda (offset) …) then tries to access the last element of the mapping, and fails because the vector is empty.

I made a quick fix which returns 0 in this case, see https://github.com/florence/cover/compare/master...jsmaniac:fix-vector-ref-minus-one , but I'm quite unsure if the correct value to return here is 0, or if the problem is not somewhere else.

vector-ref: contract violation
  expected: exact-nonnegative-integer?
  given: -1
  argument position: 2nd
  other arguments...:
   '#()
  context...:
   /home/travis/.racket/6.4/pkgs/cover/cover/private/format-utils.rkt:164:2
   success
   /home/travis/racket/collects/racket/private/map.rkt:48:13: for-each
   /home/travis/racket/collects/racket/private/map.rkt:48:13: for-each
   /home/travis/.racket/6.4/pkgs/cover/cover/private/format-utils.rkt:44:0: coverage-cache-file
   /home/travis/.racket/6.4/pkgs/cover/cover/private/format-utils.rkt:29:0: make-covered?
   /home/travis/racket/collects/racket/private/more-scheme.rkt:373:13: hash-ref!
   /home/travis/.racket/6.4/pkgs/cover/cover/cover.rkt:334:5
   /home/travis/.racket/6.4/pkgs/cover-coveralls/cover/private/coveralls.rkt:155:2: process-coverage
   /home/travis/racket/collects/racket/private/list.rkt:245:7: loop
   /home/travis/racket/collects/racket/private/list.rkt:245:7: loop
   /home/travis/racket/collects/racket/private/list.rkt:245:7: loop
   /home/travis/racket/collects/racket/private/list.rkt:245:7: loop
   /home/travis/racket/collects/racket/private/list.rkt:245:7: loop
   /home/travis/racket/collects/racket/private/list.rkt:242:4: foldr
   /home/travis/.racket/6.4/pkgs/cover-coveralls/cover/private/coveralls.rkt:167:4: for-loop
   ...
florence commented 8 years ago

That looks like the right fix, but I'm not completely sure whats going on. I guess there is a piece of syntax in that file that has a span of zero? I'll try to make a smaller test case this weekend.

florence commented 7 years ago

Merged, thanks!