chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Unit testing of non-exported procedures


From: Mario Domenech Goulart
Subject: Re: [Chicken-users] Unit testing of non-exported procedures
Date: Wed, 27 Mar 2013 20:11:06 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Hi Matt,

On Wed, 27 Mar 2013 17:02:39 -0600 Matt Gushee <address@hidden> wrote:

> I am writing a test suite for an egg I am developing, using the 'test'
> egg. So far I've written 17 tests with various supporting data, for a
> total of 274 lines of code ... I estimate that is about 10-20% of what
> I need for thorough test coverage. So before I go much further ...
>
> Much of what I want to test is the functioning of various support
> procedures that in principle are not part of the public API. Given
> that the egg is in alpha status, the module currently exports all
> symbols, and I don't mind saying "If it isn't documented, don't use
> it." And this way I can test everything. But in more mature versions,
> I want to restrict the API, but retain the ability to perform unit
> testing on all the internal procedures. And of course, the test egg
> can only test exported symbols. I think 'testeez' might work, except
> that I need to be able to verify that certain conditions will cause
> errors, and testeez doesn't appear to be able to run that kind of
> test.
>
> So, any recommendations on how best to do this?

I don't know any perfect solution for this case.  Here's a trick that
maybe can be used.  Basically, keep the implementation of your software
in a file (my-module-impl.scm) and the module stuff in other file
(my-module.scm), which includes my-module-impl.scm.

$ tree
.
├── my-module-impl.scm
├── my-module.meta
├── my-module.scm
├── my-module.setup
└── tests
    └── run.scm

1 directory, 5 files


$ cat my-module.scm 
(module my-module (my-procedure) "my-module-impl")


$ cat my-module-impl.scm 
(import chicken scheme)

(define (helper)
  42)

(define (my-procedure)
  (+ 42 (helper)))


$ cat my-module.setup 
;; compiling my-module-impl.scm separately is not necessary if tests can
;; include the source file
(compile -d0 -O3 -s my-module-impl.scm)

(compile -d0 -O3 -J -s my-module.scm)
(compile -d0 -O3 -s my-module.import.scm)

(install-extension
 'my-module
 '("my-module.so" "my-module.import.so")
 '((version "0.0.1")))


$ cat tests/run.scm 
(use test)

;; Here maybe you can (include "../my-module-impl") to avoid compiling
;; my-module-impl.scm twice
(load "../my-module-impl.so")

(test 42 (helper))
(test 84 (my-procedure))


$ chicken-install -test
<chicken-install output omitted>
(helper) ............................................................. [PASS]
(my-procedure) ....................................................... [PASS]

$ csi -R my-module -e '(print (my-procedure))'
84

$ csi -R my-module -e '(print (helper))'

Error: unbound variable: helper


Maybe there are better ways of doing that.

Best wishes.
Mario
-- 
http://parenteses.org/mario



reply via email to

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