# Does PLDoc have a way to incorporate unit tests akin to Python's doctest?

**URL:** <https://swi-prolog.discourse.group/t/does-pldoc-have-a-way-to-incorporate-unit-tests-akin-to-pythons-doctest/999>\
**Category:** Help!\
**Created:** [July 27, 2019, 8:25am UTC](https://swi-prolog.discourse.group/t/does-pldoc-have-a-way-to-incorporate-unit-tests-akin-to-pythons-doctest/999 "2019-07-27T08:25:46Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 31, 2019, 12:46pm UTC](https://swi-prolog.discourse.group/t/does-pldoc-have-a-way-to-incorporate-unit-tests-akin-to-pythons-doctest/999/23 "2019-07-31T12:46:21Z")

</div>

In looking at the LPN proxy code and thinking about one of the goals of the original question,

> [@joeblog](#):
>
> it leaves helpful examples of how to use it in its wake.

it is just a small intuitive leap to realize that the same concept of extracting source code of LPN to generate working SWISH consoles could be applied to the SWI-Prolog documentation. So instead of just adding example source code to the SWI-Prolog documentation which would be read as static code, instead it could have the gear icon added and then a user could click on the gear to launch a SWISH console and play with the predicate. That would be nice.

* * *

Details for those not up on this concept.

Originally there was a [paper](http://www.dbnet.ece.ntua.gr/~adamo/csbooksonline/prolog-notes.pdf) for learning Prolog called `Learn Prolog Now`.

That evolved into a poplar web site: [LPN](http://www.learnprolognow.org/)

Then an enhanced [version](https://lpn.swi-prolog.org/lpnpage.php?pageid=online) was created ([Notice](https://www.swi-prolog.org/news/9a17c93e-6050-11e4-b1ed-00144fee017c)) that scans the LPN HTML pages for Prolog source code and converts the Prolog source code into an active component with a link, shown as a gear

![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/d3f1856f39cc2c9d90653a8c5712c30fa954dc5c.png)

that converts the source code into a SWISH console.

The code that scans the HTML is in [lpn-swish-proxy](https://github.com/LearnPrologNow/lpn-swish-proxy)

* * *

Example from enhanced LPN, [5.3 Arithmetic and Lists](http://lpn.swi-prolog.org./lpnpage.php?pagetype=html&pageid=lpn-htmlse20)

So this Prolog code in the original LPN site

```prolog
len([],0).
len([_|T],N) :- len(T,X), N is X+1.

```

becomes this in the enhanced web site

![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/936998f815d1671a46eac9abddfeb2150889aaa4.png)

and when the gear is clicked

 ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/0227a448683aab748f289ea4d563eb5b5018e160.png)

the Prolog source code is loaded into a SWISH console ready to be run.

 ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/7526f943b27a1249e16dd275fbccef0ab7fa1d5c.png)

---

_[View the full topic](https://swi-prolog.discourse.group/t/does-pldoc-have-a-way-to-incorporate-unit-tests-akin-to-pythons-doctest/999)._
