I got into the habit of doing about 30 minutes of every morning. I practice these Kata following the test-driven development (TDD) approach. Code Kata Guile distribution includes the SRFI-64 module: a unit testing framework. In this article, I explain how to use it and how to configure it in order to practice code kata. Basic usage The SRFI-64 module has a default configuration. Let me show you what it looks like here. Below is a Guile program that creates a test suite with only one test (doomed to fail) : ( ( srfi-64)) ( ) ( ) ( ) use-modules srfi test-begin "demo" test "Hookup" #f #t test-end "demo" Explanation of the program : load the module named (srfi srfi-64). line 1 : indicate the beginning of the test group demo. line 2 : define a test, named “Hookup”, with the procedure test-equal whose first parameter is the result expected by the test (here, #t ) and the second parameter is the tested expression (here, #t). line 3: indicate the end of the `demo' test group. line 4: It is relatively simple, there are few frills. This is the result of the execution of this suite if you save it in a file and execute the : /tmp/tests.scm $ guile --no-auto-compile test.scm %%%% Starting demo (Writing full to ) /tmp/test.scm:3: FAIL Hookup test log "demo.log" # of unexpected failures 1 The console displays only a summary of the result: line 3 shows an unexpected failure from the “Hookup” test. It's very brief but it gives a quick idea of the state of the program. The complete detail is in the /tmp/demo.log file: cat demo.log %%%% Starting test demo Group : demo : - : - : . -line: - : ( -equal : -kind: fail actual- : expected- : : demo begin Test begin test name "Hookup" source file "/tmp/test.scm" source 3 source form test "Hookup" #f #t) Test end result value #t value #f Group end # of unexpected failures 1 This report gives me two pieces of information that I use a lot : and . actual-value expected-value This default configuration, although ready to use, has the disadvantage of providing information in two places: in the console (list of tests and their states) and in a file (test results). Not very practical... Fortunately, the test framework is easily configurable. In the following article, I present you with my configuration dedicated to code kata. Configuration for Code Kata The idea here is to configure the SRFI-64 module to display all the information I need directly in the console (and I don't need to report in a file). I want to see at a glance : the list of executed tests ; the status of each of these tests; for failed tests, display the expected value and the value obtained. According to the reference, the objects that maintain the statistics on the test suite (total number of tests, number of successful, failed, passed, ...) are the test-runners. SRFI-64 Thanks to the section and some examples gleaned from the web, you should be able to create the test-runner that suits you! Writing a new test-runner Here is the one I made for myself (based on the work of Mathieu Lirzin and Alex Sassmannshausen) : ( script-version ) ( ( ) #:export ( )) ( ( srfi-64) ( pretty-print) ( srfi-26)) ( ( field value #:optional ( ( )) #:key pretty?) ( pretty? ( ( port field) ( value port #:per-line-prefix )) ( port field value))) ( ( symbol) ( (( ( ( symbol)))) ( ( symbol (( ) ) (( ) ) (( ) ) (( xpass) ) (( ) )) result ))) ( ( ) ( ( runner) ( (( ( runner)) ( ( assq <> results)) ( ( assq-ref results <>))) ( ( ( )) ( ( ) ( ( ( )) ( )) ( ( ) ( ( ))) ( ( ) ( ( ) #:pretty? )) ( ( ) ( ( ))) ( )) ( ( ( ( )) ( )))))) ( (( ( ))) ( runner test-on-test-end-kata) runner)) ;;;; kata-driver.scm - Guile test driver for code kata practice define "2020-10-04" ;UTC ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org> ;;; Copyright © 2019 Alex Sassmannshausen <alex@pompo.co> ;;; Copyright © 2019 Jérémy Korwin-Zmijowski <jeremy@korwin-zmijowski.fr> ;;; ;;; This program is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;;; Commentary: ;;; ;;; This script provides a Guile test driver using the SRFI-64 Scheme API for ;;; test suites. SRFI-64 is distributed with Guile since version 2.0.9. ;;; ;;; This script is a very cleaned up version of the Alex Sassmannshausen 's ;;; version. The changes make it suitable for use in a code kata practice. ;;; ;;;; Code: define-module runner-kata test-runner-kata use-modules srfi ice-9 srfi define* test-display port current-output-port "Display 'FIELD: VALUE\n' on PORT." if begin format "~A:~%" pretty-print "+ " format "~A: ~S~%" define* result->string "Return SYMBOL as an upper case string. Use colors when COLORIZE is #t." let result string-upcase symbol->string string-append case pass "" ;green xfail "" ;light green skip "" ;blue fail "" ;red error "" ;magenta "" define* test-runner-kata define test-on-test-end-kata let* results test-result-alist result? cut result cut if equal? 'fail result 'result-kind begin newline format #t "~a ~A~%" result->string result 'result-kind result 'test-name when result? 'expected-value test-display "expected-value" result 'expected-value when result? 'expected-error test-display "expected-error" result 'expected-error #t when result? 'actual-value test-display "actual-value" result 'actual-value newline begin format #t "~a ~A~%" result->string result 'result-kind result 'test-name let runner test-runner-null test-runner-on-test-end! I created which contains a project template for a code kata. When you run the `watch.sh' script, the terminal will reload your tests at every changes. So you are ready to code and see the feedback instantaneously. Handy, right? a git repository No more need to look at the content of the report (which is no longer generated) to find out what the problem is. So I can execute this script in a dedicated emacs buffer, every time I save, and act according to the test results. Now it's up to you! Choose a code kata exercise, work on it for about 30 minutes, share the link to your code and your tests in comments below! Then, I give you my 2 cents for your next session! Thank you so much for reading this article! Don't hesitate to give me your opinion or ask a question! To do so, please leave a comment below or contact me . And most importantly, share the blog and tell your friends it's the best blog in the history of Free Software! No shit! Previously published at https://rednosehacker.com/code-kata-with-srfi-64