chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tidy way to test and set when using test egg?


From: Matt Welland
Subject: Re: Tidy way to test and set when using test egg?
Date: Fri, 10 Jan 2020 08:51:53 -0700

Hi Kristian,

The test egg does a great job of making it easy to hone in on the root cause of a problem but I thought to get that benefit the call must be done in the context of the test macro. Maybe I'd get the feedback I want from using test-group. I've not used test-group much.
 
csi> (test-group "foo" (define res (- #f 2))(test 1 res))

Warning: error in group outside of tests

Error: (-) bad argument type: #f
1 test completed in 0.0 seconds.
1 error (100%).
0 out of 1 (0%) tests passed.
-- done testing foo ----------------------------------------------------------

Maybe that addresses the problem I was trying to solve. I'll try it.

On Fri, Jan 10, 2020 at 8:41 AM Kristian Lein-Mathisen <address@hidden> wrote:

Hi Matt,

So you want to keep the result for more upcoming test? Why? Just curious.

I've for the most part been content with:

(test-group
 "-"
  (define res (- 2 1))
  (test 1 res)
 (print "res: " res) )
;; res out of scope here (good thing, no?)

K.



On Fri, Jan 10, 2020, 16:22 John Cowan <address@hidden> wrote:
Mixing definitions and expressions in a block isn't actually legal Scheme, though it does work in Chicken.  All defines are supposed to come first and all expressions afterwards.  Since the test library is shared with Chibi, and since Chibi doesn't allow this extension, I can't see adding this to the library.

On Fri, Jan 10, 2020 at 10:18 AM Matt Welland <address@hidden> wrote:
I find myself doing stuff like this very often when writing tests using the test egg:

;; A trivial example where  the function under test is "-"
(define data #f)
(test #f 1 (let ((res (- 2 1)))(set! data res) res))

I'd really prefer to do something like:

(test-and-define data #f 1 (- 2 1))

But the closest I could get was:

(define-syntax test-and-set
  (syntax-rules ()
    ((_ name arg1 arg2 body ...)
     (test arg1 arg2
  (let ((res (begin body ...)))
    (set! name res)
    res
    )))))

So I can do:

(define data #f)
(test-and-set data #f 1 (- 2 1))

Questions:

1. Is there a generally better way to test and gather the result for use in downstream tests?

2. Is there a way to write a macro that can create the toplevel binding?


--
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.


--
--
Complexity is your enemy. Any fool can make something complicated.
It is hard to keep things simple. - Richard Branson.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]