public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Using the Unit Test Srfi from inside a library definition
@ 2015-03-30  2:39 Jeff Gonis
  2015-03-30  7:06 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Gonis @ 2015-03-30  2:39 UTC (permalink / raw)
  To: kawa

Hi Folks,

So I am working with Kawa 2.0 and I wanted to separate the 
implementation of my tests from the functions that they are testing. I 
am working from a repl in emacs 24.4 on Ubuntu Gnome 14.10.

If I import srfi-64 and create a test in the top-level of a file, 
outside of any library definitions everything works just great.  The 
following code is a minimal example that I have pared down to illustrate
 the difference:

(define (test)
  (test-begin "temp")
  (test-end "temp"))

This will result in the test runner "running" the tests and outputting
to a log file. Great.

However if I try to define my test inside a define-library form I get
the following error message: 
/dev/stdin:79:7: improper list (circular or dotted) is not allowed here

The minimal library example is as follows:
(define-library (testlib)
  (export test-suite)
  (import (scheme base)
             (srfi 64))
  (begin
    (define (test-suite)
      (test-begin "temp")
      (test-end "temp"))))

As far as I can tell, there shouldn't be any difference here, 
except that the test-begin and end are define inside a library. I may 
have missed something incredibly simple though and if so my apologies 
for taking up your time.

Thank you for your time,
Jeff G.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Using the Unit Test Srfi from inside a library definition
  2015-03-30  2:39 Using the Unit Test Srfi from inside a library definition Jeff Gonis
@ 2015-03-30  7:06 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2015-03-30  7:06 UTC (permalink / raw)
  To: Jeff Gonis, kawa


On 03/29/2015 07:39 PM, Jeff Gonis wrote:
> However if I try to define my test inside a define-library form I get
> the following error message:
> /dev/stdin:79:7: improper list (circular or dotted) is not allowed here
>
> The minimal library example is as follows:
> (define-library (testlib)
>    (export test-suite)
>    (import (scheme base)
>               (srfi 64))
>    (begin
>      (define (test-suite)
>        (test-begin "temp")
>        (test-end "temp"))))
>
> As far as I can tell, there shouldn't be any difference here,
> except that the test-begin and end are define inside a library.

I checked in a fix for this - it should work now.

The issue is that the default Kawa top-level environment has a number of
predefined bindings, while the body of a define-library only has the
bindings you explicitly import.  The problem is when testing.scm (i.e.
he implementation of srfi 64) is compiled.  Any bindings that are not
explicitly imported are resolved in the default Kawa top-level, which
normally works fine.  Consider a macro that expands to a form that references
various standard Scheme forms.  If the bindings haven't been hygienically
imported when compiling testing.scm, then the Kawa compiler will normally
look for bindings in the default top-level environment dynamic environment
- which is disabled when processing the body of a define-library.

The particular error message you saw is because the binding for quote
is missing, so Kawa processes quote as if it were a call to an unknown
function.

The fix is (basically) to (import (scheme base)) when compiling testing.scm.
This provides hygienic bindings for names used in expanded macros.
(It was a little more complicated than that, mainly because test-begin
is magic in the default top-level, causing an auto-import.)

>  I may have missed something incredibly simple though and if so my apologies
> for taking up your time.

Nope, it was a Kawa bug that needed to be fixed.  Thanks for the
simple test-case.

A lot of these errors were fixed last year (largely thanks to testing by
Seth Alves), but there are probably more remaining.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-30  7:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-30  2:39 Using the Unit Test Srfi from inside a library definition Jeff Gonis
2015-03-30  7:06 ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).