skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
328 stars 27 forks source link

Improve test-coverage of the eval/eval.go file. #71

Closed skx closed 5 years ago

skx commented 5 years ago

The core of our interpreter is implemented in eval/eval.go, and currently boasts 85% test-coverage.

Unfortunately the bits that are lacking coverage are tricky to test, and the tests we've got defined cover random things unrelated to the core - specifically they cover the builtins, from before they were moved to their own package (in #58, #59, #60).

I will accept 95% coverage - because I assume handling INPUT will be a pain - but nothing less.

Once this pull-request is complete this will be achieved, and our test-cases (and no doubt improved implementation) will be much cleaner and more tightly focused - we'll close #70 at that time.

skx commented 5 years ago

9 test functions now provide >50% coverage of eval/eval.go, which is a much better situation to be in.

I'll bump the coverage further this evening, hopefully to exceed 90%.

Downside is that our API has changed again, since New can now return an error..

skx commented 5 years ago

Current status:

   frodo ~/go/src/github.com/skx/gobasic $ cover ./...
   ?    github.com/skx/gobasic  [no test files]
   ok   github.com/skx/gobasic/builtin  0.003s  coverage: 100.0% of statements
   ?    github.com/skx/gobasic/embed    [no test files]
   ok   github.com/skx/gobasic/eval 0.011s  coverage: 83.5% of statements
   ?    github.com/skx/gobasic/goserver [no test files]
   ok   github.com/skx/gobasic/object   0.002s  coverage: 100.0% of statements
   ok   github.com/skx/gobasic/token    0.002s  coverage: 100.0% of statements
   ok   github.com/skx/gobasic/tokenizer    0.002s  coverage: 100.0% of statements

So the package I'm dealing with in this pull-request, eval/ has 83.5% coverage.

I don't expect 100%, but I do expect 95+%.

skx commented 5 years ago

So close!

  frodo ~/go/src/github.com/skx/gobasic $ cover ./...
  ?     github.com/skx/gobasic  [no test files]
  ok    github.com/skx/gobasic/builtin  0.016s  coverage: 100.0% of statements
  ?     github.com/skx/gobasic/embed    [no test files]
  ok    github.com/skx/gobasic/eval 0.033s  coverage: 94.6% of statements
  ?     github.com/skx/gobasic/goserver [no test files]
  ok    github.com/skx/gobasic/object   0.002s  coverage: 100.0% of statements
  ok    github.com/skx/gobasic/token    0.002s  coverage: 100.0% of statements
  ok    github.com/skx/gobasic/tokenizer    0.002s  coverage: 100.0% of statements
  frodo ~/go/src/github.com/skx/gobasic $ 

Outstanding tasks:

Then this is ready.

skx commented 5 years ago

I think my work here is done:

   ?    github.com/skx/gobasic  [no test files]
   ok   github.com/skx/gobasic/builtin  0.010s  coverage: 100.0% of statements
   ?    github.com/skx/gobasic/embed    [no test files]
   ok   github.com/skx/gobasic/eval 0.013s  coverage: 96.8% of statements
   ?    github.com/skx/gobasic/goserver [no test files]
   ok   github.com/skx/gobasic/object   0.007s  coverage: 100.0% of statements
   ok   github.com/skx/gobasic/token    0.021s  coverage: 100.0% of statements
   ok   github.com/skx/gobasic/tokenizer    0.002s  coverage: 100.0% of statements