Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 78249 invoked from network); 15 Feb 2009 01:17:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Feb 2009 01:17:00 -0000 Received: (qmail 5676 invoked by uid 500); 15 Feb 2009 01:16:59 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 5632 invoked by uid 500); 15 Feb 2009 01:16:59 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 5621 invoked by uid 99); 15 Feb 2009 01:16:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Feb 2009 17:16:59 -0800 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Feb 2009 01:16:49 +0000 Received: from [10.0.1.6] (e178194185.adsl.alicedsl.de [::ffff:85.178.194.185]) (AUTH: LOGIN jan, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Sun, 15 Feb 2009 01:16:28 +0000 Message-Id: <52FC71A1-9758-47CE-B8BE-79F5D704B867@apache.org> From: Jan Lehnardt To: dev@couchdb.apache.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: [PATCH] Eunit Tests Date: Sun, 15 Feb 2009 02:15:57 +0100 X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org Hi, I prepared a patch that adds EUnit-style tests to CouchDB: http://friendpaste.com/2DAOEki94jg8SGfxheh769 The patch currently simply disables all tests that were available in the ./test/ directory. The `couch_config_*` tests have been migrated to the new EUnit style. The command-line based JS test suite has yet to be enabled again. This is trivial. The patch touches Makefiles'nstuff. Here's how to use it: make local-clean ./bootstrap ./configure cd test make test You should see (after a while): ... /usr/local/bin/erlc -o ../src/couchdb/tests/ ../src/couchdb/tests/*.erl erl -noshell -pa ../src/couchdb/ -pa ../src/couchdb/tests/ \ -eval "eunit:test([couch_config, couch_config_writer])" \ -s init stop All 8 tests successful. The output can be beautified. I kept it raw to show all that happens. You see that this is still contained to the ./test/ directory. We'd still need to hook it up to the top level `make test`. I hope to get some help with this. Also, the conditional compilation with `erlc -DTEST` is not ideal yet. I chose to use this to keep all test code out of code that will be deployed, but currently, all compiled `.beam` files get `rm`'d and recompiled with `erlc -DTEST` on every test-suite run. Also, if you happen to run `make install` from the top level directory, you'd install the test-enabled beam files. My lack of Autotools-fu prevented me from doing this more elegantly and again, I hope to get some help from the community. -- Writing Tests Hey, nice, you stuck around and like to know how to write tests now? Easy: 1) Create a file `my_module_tests.erl` in src/couchdb/tests/ e.g. `couch_config_tests.erl`. 2) Insert boilerplate header: -module(my_module_tests). -include_lib("eunit/include/eunit.hrl"). 3) Start writing tests. See http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html for details. You can take the couch_config*_tests.erl files as guide, but they are of poor quality and not yet good EUnit style. I tried to change as little as possible with this patch. 4)* Add my_module in line 28 of test/Makefile.am 5) cd test && make test 6) Go to step 3). * This should be made more elegant as well as more test suites are written. -- What do you think? Cheers Jan --