From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.user Subject: Python-style doctests in Guile (implemented, please comment) Date: Sun, 30 Jul 2017 20:54:14 +0200 Message-ID: <87379d7m66.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1501443365 32330 195.159.176.226 (30 Jul 2017 19:36:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 30 Jul 2017 19:36:05 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jul 30 21:36:00 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbu0L-0007yC-15 for guile-user@m.gmane.org; Sun, 30 Jul 2017 21:35:57 +0200 Original-Received: from localhost ([::1]:56274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbu0Q-0004gB-TX for guile-user@m.gmane.org; Sun, 30 Jul 2017 15:36:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbu04-0004g5-G5 for guile-user@gnu.org; Sun, 30 Jul 2017 15:35:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbu00-0005SH-HI for guile-user@gnu.org; Sun, 30 Jul 2017 15:35:40 -0400 Original-Received: from mout.web.de ([217.72.192.78]:56115) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dbu00-0005Pp-5D for guile-user@gnu.org; Sun, 30 Jul 2017 15:35:36 -0400 Original-Received: from fluss ([85.212.91.45]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MGiUP-1dOvRt0TBJ-00DTuC; Sun, 30 Jul 2017 21:35:32 +0200 X-Provags-ID: V03:K0:F8mpbzll0MOfC+ZzfJ7RsxRCKXps0gn5BMklyGUhb7qL2CaU7H/ YfVgwbYmYL4U0X7X9a7p7fG2W/tiIcDkj49HT5NiMG36wcw7qvZ0hbkWmA81ZmBUm30aVb6 AEe/kAb9g6C8UJ/+jlGxQWufOvvP16rCQv7QnvSt89A3E1GF1riPii12WDcJWREMPhAt1gS P4bLv34jXEZH7FjM6Q0Jw== X-UI-Out-Filterresults: notjunk:1;V01:K0:jBT/eHeSir0=:kKMKE/XPaljuuOCQyEepfj TNIC6HKw4PHerJAcyLHF7TzvxOvwR34MZLhoXhbfNfjhBOW0nollyqI3982zlVtV6tBAT+S4P dooX69njfs8OSVeUkYuZY4CKNI+dCOO+J+liHo3L7VL36FvsE/uhphqtcNbXNa0uEkeLoNB2p e8eFDWiKpoP8z36Hp2woYJSYNBcwdhG+9essJzcVoBDzq2S2tguYTNZ3oIxxy74CdlZqScaUg g+ODNCbv5l6qc+U7XdsvT+OuWZEu2CL/1NDGjrLQQ56wxAmPfYes9r3VmXqBAEBVoT9URrKq1 TGUfyyefzIojRCfENfeZStq7f/GLPlESI/BQXwqPpVLil219WL1pXkSyFPQEU0wMYkGJ/Kk68 mJLAkdnBMttceiHc2cITOow6lfvFxt6AuvLe37r3qoRp2YtOkB+w0XiKVsf7DjCi6JGjfHkiu ofzr3a4g5x7MH9BDzmVvyebFP4WNG7Txcn+0tpxp5j/zYeJdJCB4CuE7+aXLvAtdpQUPlcwm4 tNTZfafdRrEA2OUV+ndLo2iCybrtyrShMZwjbi7v9f/3VqLJ3mrpZuRCRrdocplIiYMw+YJKH tdTP20HZ+TSC7okonWboPgt0juvFwejJj/KpynEM/tbWlKYsuMQbbeMfMHJV/NMaATO1elEfa CN3bLMezSvOhwayIMP5eMNdOtoJZC4bNTitwkgwbcYuHAsXF3pA4WP7ble1Z5XFLJRq0rw30V BKPJ4Sj1Dk5M/f/Q5nkEhB0enH8lwIjZCUU9Z+ShtsHlSXEBI1eJbMbsYIUVr47MUCOGQc9M X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.78 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13998 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I implemented doctests in Guile which allow writing SRFI-64 tests directly in the docstring. Here=E2=80=99s a minimal example: (import (examples doctests)) =20=20=20=20 (define (one) "(test 'foo (test-equal 1 (one)))" 1) =20=20=20=20 (doctests-testmod (current-module)) Writing simple tests directly in the procedure-documentation makes for very natural test-driven-design which gets extended into basic documentation automatically: Start the procedure, write a basic test in the docstring, implement the body till the test passes and finally create api-docs from the docstrings which then also show basic usage examples in the tests. My questions: This method here is the simplest implemenation of this feature. It would be great if you could comment on it. Is this structure good? Would you do it differently? Is "(test-equal 1 (one))" close enough to an example in the REPL, or would it serve for better usage-examples in another structure? The output from running the minimal example is plain SRFI-64 output, though with extended identifiers: $ ./doctests-testone.scm=20 %%%% Starting test ._-guile-user--foo--foo (Writing full log to "._-gu= ile-user--foo--foo.log") # of expected passes 1 =20=20=20=20 $ cat ._-guile-user--foo--foo.log=20 %%%% Starting test ._-guile-user--foo--foo Group begin: ._-guile-user--foo--foo Test begin: source-line: 2 source-form: (test-equal "bar" (foo)) Test end: result-kind: pass actual-value: "bar" expected-value: "bar" Group end: ._-guile-user--foo--foo # of expected passes 1 The syntax for the identifier is: ._----- I mainly know doctests from Python. There they use a special syntax which looks like the interpreter. For Guile I rather chose to start the tests with "(test 'testname" and treat as test everything read by (read). Avoiding (test-begin 'testname) and (test-end 'testname) makes for easier parsing. (they are added automatically using the 'testname) Here=E2=80=99s a somewhat longer example with the test-execution tucked awa= y in the main file so it does not interfere with importing the module: The full code is available in the wisp-repo: (The code is originally written in wisp, but I decided to use parenthizes syntax nontheless, because using s-exps makes for more obvious parsing) Best wishes, Arne =2D-=20 Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE801qEjXQSQPNItXAE++NRSQDw+sFAll+NQIACgkQE++NRSQD w+v+lBAAnrYPEpWjbbkG85qWBBeIDOshOyzGmp7eNXKVZsvRX7DOn4NsWG1PHyjr h017h7cst0N8z5pvdfNPimkLUIo3L+tRjqONGmIxpLpm9Vkam1VivgIsOWW6fFhF C2R9mkyGybYaJSRalaIxGTN3Eh9pSjouU3x4y+y7jg912Zx6CjjF+45CpqFNd6BG dksYuZql9IoMNIf3dAzT10lL+RSZP6GsZxrL3XabR69BSwHlJwlHwEwVRJzQ4ZGv HPt/WXPSGnxE9lZFt6/4NU2bJJW+6u0FEhTnzXWKgc3fqfAXjgtFu+GXdGVbkMHh 2nL99ErLFDl2EGRp6aCYLGtnl833gag8Kn7tYIr97EDHFHE4/gGZz87GwfXdbuwF h5xy4A6PG7BpsyqzcrZOd3P2D+VXh2mQ6YejH0+SEPh0vBqZjcjS0CXudozk1UF+ GnjFtZl/+gKYVfSm/kA/FhT82uO1mj2PwLe20TTHXTqppi3dkhXK2cGx+WlRx54s uVqRZLGEG9Hlf9Vc8KRrhcrVQck9iWzvRImsltBJw8Y+7nhc3VPlRdn1fm7lQiHO pXFF8LsGVdXTOujJKvSjxwUFV+ZHCnUeZB60+iR2P0ygj+5ICyN+k6rpvK4MyPFI 8q4f86LKbILL9ZdCWzYkrlEwOImLGhoXHFzF65zb2vuexEsQrR0= =y6W3 -----END PGP SIGNATURE----- --=-=-=--