* SRFI 64: How do I create a test-runner stub
@ 2019-03-07 21:02 sirgazil
2019-03-07 23:40 ` Christopher Lam
2019-03-09 19:58 ` sirgazil
0 siblings, 2 replies; 4+ messages in thread
From: sirgazil @ 2019-03-07 21:02 UTC (permalink / raw)
To: Guile User
Hello,
I'm trying to implement a procedure that takes a test-runner object and
returns a string with information about the most recently run test. For
example, calling
(format-test-result (make-runner #:test-name "A is not B."
#:result-kind 'fail))
is expected to return:
✖ FAIL A is not B.
In the example, `make-runner` is a procedure that is supposed to create
a test-runner stub with the given values, so that I can test the
`format-test-result` procedure.
I thought I could define `make-runner` body like this:
(let ((runner-stub (test-runner-null)))
(test-runner-test-name! runner-stub test-name)
(test-result-set! runner-stub 'result-kind result-kind)
stub-runner))
The problem is, the `test-runner-test-name!` setter does not exist. And
test-runner objects don't seem to have a `test-name` slot. They do
provide a `test-runner-test-name` getter, though.
So I don't know how to create a test-runner stub to test my procedure.
What would you do in this case?
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SRFI 64: How do I create a test-runner stub
2019-03-07 21:02 SRFI 64: How do I create a test-runner stub sirgazil
@ 2019-03-07 23:40 ` Christopher Lam
2019-03-08 13:24 ` sirgazil
2019-03-09 19:58 ` sirgazil
1 sibling, 1 reply; 4+ messages in thread
From: Christopher Lam @ 2019-03-07 23:40 UTC (permalink / raw)
To: sirgazil; +Cc: Guile User
Hi
In gnucash I've resorted to writing my own srfi-64 test-runner. See the
entry point at (run-test-proper) at
https://github.com/Gnucash/gnucash/blob/maint/gnucash/report/standard-reports/test/test-transaction.scm
Its definition is at
https://github.com/Gnucash/gnucash/blob/maint/libgnucash/engine/test/srfi64
-extras.scm and takes care of both returning #f if any test fails, and also
doing an IMHO better job at logging tests.
On Thu, 7 Mar 2019 at 21:03, sirgazil <sirgazil@zoho.com> wrote:
> Hello,
>
> I'm trying to implement a procedure that takes a test-runner object and
> returns a string with information about the most recently run test. For
> example, calling
>
> (format-test-result (make-runner #:test-name "A is not B."
> #:result-kind 'fail))
>
> is expected to return:
>
> ✖ FAIL A is not B.
>
> In the example, `make-runner` is a procedure that is supposed to create
> a test-runner stub with the given values, so that I can test the
> `format-test-result` procedure.
>
> I thought I could define `make-runner` body like this:
>
> (let ((runner-stub (test-runner-null)))
> (test-runner-test-name! runner-stub test-name)
> (test-result-set! runner-stub 'result-kind result-kind)
> stub-runner))
>
> The problem is, the `test-runner-test-name!` setter does not exist. And
> test-runner objects don't seem to have a `test-name` slot. They do
> provide a `test-runner-test-name` getter, though.
>
> So I don't know how to create a test-runner stub to test my procedure.
>
> What would you do in this case?
>
>
> --
> Luis Felipe López Acevedo
> http://sirgazil.bitbucket.io/
>
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SRFI 64: How do I create a test-runner stub
2019-03-07 23:40 ` Christopher Lam
@ 2019-03-08 13:24 ` sirgazil
0 siblings, 0 replies; 4+ messages in thread
From: sirgazil @ 2019-03-08 13:24 UTC (permalink / raw)
To: Christopher Lam; +Cc: Guile User
Hi, Christopher,
Thanks for the links, but I'm no actually looking for a custom
rest-runner. I'm writing my own as an exercise, and it looks similar to
your `gnc:test-runner`. My runner already prints to standard output and
logs results in a manner I like better than Guile's default test-runner.
The thing is, I'm writing tests to test the functions that compose my
test-runner. One of this functions is `format-test-result` which
receives a test-runner object as an argument. That's why I need to know
how to create a fake test-runner that has the same interface of a real
test-runner object.
Extending a fake runner from `(test-runner-null)`, for example, didn't
quite work for me because I couldn't find a way to set a `test-name`
slot in the object, so that the `test-runner-test-name` getter can be
called on fake runners and return whatever name I set in them.
El 7/03/19 a las 6:40 p. m., Christopher Lam escribió:
> Hi
>
> In gnucash I've resorted to writing my own srfi-64 test-runner. See the
> entry point at (run-test-proper) at
> https://github.com/Gnucash/gnucash/blob/maint/gnucash/report/standard-reports/test/test-transaction.scm
>
> Its definition is at
> https://github.com/Gnucash/gnucash/blob/maint/libgnucash/engine/test/srfi64-extras.scm
> <https://github.com/Gnucash/gnucash/blob/maint/libgnucash/engine/test/srfi64-extras.scm>
> and takes care of both returning #f if any test fails, and also doing an
> IMHO better job at logging tests.
>
>
> On Thu, 7 Mar 2019 at 21:03, sirgazil <sirgazil@zoho.com
> <mailto:sirgazil@zoho.com>> wrote:
>
> Hello,
>
> I'm trying to implement a procedure that takes a test-runner object and
> returns a string with information about the most recently run test. For
> example, calling
>
> (format-test-result (make-runner #:test-name "A is not B."
> #:result-kind 'fail))
>
> is expected to return:
>
> ✖ FAIL A is not B.
>
> In the example, `make-runner` is a procedure that is supposed to create
> a test-runner stub with the given values, so that I can test the
> `format-test-result` procedure.
>
> I thought I could define `make-runner` body like this:
>
> (let ((runner-stub (test-runner-null)))
> (test-runner-test-name! runner-stub test-name)
> (test-result-set! runner-stub 'result-kind result-kind)
> stub-runner))
>
> The problem is, the `test-runner-test-name!` setter does not exist. And
> test-runner objects don't seem to have a `test-name` slot. They do
> provide a `test-runner-test-name` getter, though.
>
> So I don't know how to create a test-runner stub to test my procedure.
>
> What would you do in this case?
>
>
> --
> Luis Felipe López Acevedo
> http://sirgazil.bitbucket.io/
>
>
>
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: SRFI 64: How do I create a test-runner stub
2019-03-07 21:02 SRFI 64: How do I create a test-runner stub sirgazil
2019-03-07 23:40 ` Christopher Lam
@ 2019-03-09 19:58 ` sirgazil
1 sibling, 0 replies; 4+ messages in thread
From: sirgazil @ 2019-03-09 19:58 UTC (permalink / raw)
To: guile-user
El 7/03/19 a las 4:02 p. m., sirgazil escribió:
> Hello,
>
> I'm trying to implement a procedure that takes a test-runner object and
> returns a string with information about the most recently run test. For
> example, calling
>
> (format-test-result (make-runner #:test-name "A is not B."
> #:result-kind 'fail))
>
> is expected to return:
>
> ✖ FAIL A is not B.
>
> In the example, `make-runner` is a procedure that is supposed to create
> a test-runner stub with the given values, so that I can test the
> `format-test-result` procedure.
>
> I thought I could define `make-runner` body like this:
>
> (let ((runner-stub (test-runner-null)))
> (test-runner-test-name! runner-stub test-name)
> (test-result-set! runner-stub 'result-kind result-kind)
> stub-runner))
>
> The problem is, the `test-runner-test-name!` setter does not exist. And
> test-runner objects don't seem to have a `test-name` slot. They do
> provide a `test-runner-test-name` getter, though.
>
> So I don't know how to create a test-runner stub to test my procedure.
>
> What would you do in this case?
Never mind, I found that `test-name` is defined in the test result
association list hold by the test runner (this is not documented though).
So, using the same example above, you would do instead:
(let ((runner-stub (test-runner-null)))
(test-result-set! runner-stub 'test-name test-name)
(test-result-set! runner-stub 'result-kind result-kind)
stub-runner))
--
Luis Felipe López Acevedo
http://sirgazil.bitbucket.io/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-09 19:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 21:02 SRFI 64: How do I create a test-runner stub sirgazil
2019-03-07 23:40 ` Christopher Lam
2019-03-08 13:24 ` sirgazil
2019-03-09 19:58 ` sirgazil
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).