Lisp HUG Maillist Archive

Finding definitions inside a PROGN

In an attempt to upgrade my unit tests from simple top-level assert 
statements (which is so simple that you don't need a framework at all, 
but has 1 big disadvantage: I cannot jump to the source from a 
debugger), I tried the following:

(defpackage :cl-unit
   (:use :common-lisp))

(in-package :cl-unit)

(export '(test))

(defmacro test (name &body body)
   "Define and invoke a unit test with name and body"
   `(progn
      (defun ,name () ,@body)
      (,name)))

And then in some test file I write:

(cl-unit:test my-test
   (assert (string= "" "w")))

This works fine, the offending function/test shows up in the debugger, 
but I still cannot jump to the source because 'the definition cannot be 
found', proably because it is inside a PROGN. The editor has the same 
problem. Is there a way to solve this ? Is that what the DSPEC stuff is 
for (apart from the reference I couldn't find a more guided description 
of how to use this).

TIA,

Sven


Re: Finding definitions inside a PROGN

> From: "Sven Van Caekenberghe" <sven@beta9.be>
> Sent: Thursday, April 01, 2004 1:54 PM
> Subject: Finding definitions inside a PROGN
>
> In an attempt to upgrade my unit tests from simple top-level assert
> statements (which is so simple that you don't need a framework at
> all, but has 1 big disadvantage: I cannot jump to the source from a
> debugger), I tried the following:
>
> (defpackage :cl-unit
>    (:use :common-lisp))
>
> (in-package :cl-unit)
>
> (export '(test))
>
> (defmacro test (name &body body)
>    "Define and invoke a unit test with name and body"
>    `(progn
>       (defun ,name () ,@body)
>       (,name)))
>
> And then in some test file I write:
>
> (cl-unit:test my-test
>    (assert (string= "" "w")))
>
> This works fine, the offending function/test shows up in the
> debugger, but I still cannot jump to the source because 'the
> definition cannot be
> found', proably because it is inside a PROGN. The editor has the
> same problem. Is there a way to solve this ? Is that what the
> DSPEC stuff is for (apart from the reference I couldn't find a
> more guided description of how to use this).
>
> TIA,
>
> Sven


In LW 4.3, I think adding the following will suffice:

(dspec:define-dspec-alias test (name)
  `(defun ,name))

In LW 4.2, I think you'll also need this:

(defmacro test (name &body body)
    "Define and invoke a unit test with name and body"
    `(lw:top-level-form ,name
        (defun ,name () ,@body)
        (,name)))

(Not tested! If it doesn't work, let me know and I'll take a closer
look.)



Re: Finding definitions inside a PROGN

Unable to parse email body. Email id is 2141

Updated at: 2020-12-10 08:57 UTC