Menu:

Post History:

Animals Matter to Me

Installing PlUnit on Ubuntu

Only a short update to the chain tonight because its getting late.

Before starting on the Prolog code for the prologblog.com site, I wanted to see if anyone in the Prolog community had documented how to do Test Driven Development (TDD) or Behavior Driven Development (BDD) in Prolog. I couldn’t even find some discussion on the subject let alone a how-to or tool set. For now, I will be on my own and figuring it out as I go.

The testing framework included with SWI-Prolog is called PlUnit. The Ubuntu SWI packages caused me to waste some more time today, as they don’t seem to include PlUnit, despite it being a package normally distributed with SWI. To use it, I had to get the current version directly from the SWI git respository. I kept the Ubuntu package-installed version of SWI and was able to manually install PlUnit next to it. Here are the steps for doing that.

Clone the SWI-Prolog git repository

git clone git://prolog.cs.vu.nl/home/pl/git/pl.git

Configure and install PlUnit

cd pl/packages/plunit
autoconf
./configure
sudo make install

Note that there is no actual ‘make’ step. There is nothing to build, the files just need to be copied into the correct location.

Check installation

To check that it was installed properly, one can run the files from the PlUnit examples directory.

cd pl/packages/plunit/examples/ # in the cloned git repo
swipl -g "[simple],run_tests,halt."
 % simple compiled into ex_simple 0.01 sec, 108,664 bytes
 % PL-Unit: lists ........ done
 % All 8 tests passed

5 comments


nicholas a. evans on March 16, 2009 9:50AM

FWIW, you could write higher level acceptance tests in cucumber and webrat... so long as that doesn't feel like cheating to leave the prolog world or too much yakshaving/reinventing-the-wheel to write a mini-cucumber-like-framework and webrat-like-library in prolog. But reinvention of said wheels would make for good blog posts. :) e.g. http://github.com/kesor/p5-cucumber/tree/master

Jeff Dallien on March 16, 2009 2:07PM

I don't think having something cucumber-like done in Prolog would be reinventing the wheel, since all the testing options seem to be either PlUnit or something very close. This is probably because its pretty easy to write one in that style, any bit of Prolog code will report a pass/fail when run because that's just the way Prolog is. I haven't seen anything available with a descriptive, step-by-step component like cucumber, so I think I will attempt to write one at some point.

john on August 16, 2010 3:28AM

Hi, I tried installing plunit along the lines suggested above. The simple test for installation however failed. The first few lines of the error are ERROR: /usr/lib/swi-prolog/library/plunit.pl:147: plunit:set_test_flag/2: Undefined procedure: plunit:create_prolog_flag/3 Warning: /usr/lib/swi-prolog/library/plunit.pl:147: Goal (directive) failed: plunit: (initialization current_test_flag(test_options, _G688)->true;set_test_flag(test_options, [run(make), sto(false)])) % library(plunit) compiled into plunit 0.04 sec, 178,916 bytes Warning: /home/venkatm/Desktop/automarker/pl/packages/plunit/examples/simple.pl:15: Clauses of ex_simple:test/1 are not together in the source-file Please help me on this ... yours seems to be the only source/documentation on this topic .. thanks in advance

DaveE on June 02, 2011 11:16AM

I tried following your instructions to the letter, but the baseline swi-prolog install does not seem to include package/plunit (anymore). so i did a git clone from http://prolog.cs.vu.nl/git/packages/plunit.git instead. Then I tried to resume with your instructions. running autoconf gave errors though. Any thoughts would really be appreciated! dave@deb5:~/prologlibs$ cd plunit dave@deb5:~/prologlibs/plunit$ ls autom4te.cache examples Makefile.mak README test_wizard.pl ChangeLog install-sh plunit.doc swi.pl configure.in Makefile.in plunit.pl test_cover.pl dave@deb5:~/prologlibs/plunit$ autoconf /usr/bin/m4:configure.in:6: cannot open `../ac_swi_noc.m4': No such file or directory autom4te: /usr/bin/m4 failed with exit status: 1 dave@deb5:~/prologlibs/plunit$

DaveE on June 04, 2011 9:18AM

ahh! So the error I noted in my last comment is b/c this file comes with the pl.git repository, not the submodule by itself. So since the article posted in 2009, swi-prolog changed plunit to be its own submodule project instead of being tracked from within pl.git. The trick is to do a clone of pl.git like you have above. then doing: "git submodule update --init packages/plunit"

Adding new comments is currently disabled.