Quick
index
main
eev
maths
blogme
dednat6
littlelangs
PURO
(GAC2,
C3TD,
λMDetc)
(Chapa 1)

emacs
lua
(la)tex
fvwm
agda
tcl
forth
icon
debian
irc
contact

Test blocks: eev @ EmacsConf 2021

My talk at the EmacsConf2021 will be about test blocks.
See my old page on test blocks, and my talks at the EmacsConf2020 and EmacsConf2019.

Title: Test blocks
Intended duration: 5 minutes
Abstract:

In this presentation I will show an idea that feels completely obvious once we see it, but that only occured to me after after using Emacs and eev as my main interface to the computer for more than 20 years. Take any interpreted language that supports multi-line comments, and whose interpreter can be run in an Emacs buffer - for example Lua, Haskell, Python, or Julia; let's say just "Lua" from here on for simplicity. So: suppose that we have a Lua script that we wrote, that is called "foo.lua" and that defines lots of functions and defines the classes Bar and Bletch. We can put after the definition of the class Bar a multi-line comment that contains an eepitch block that when executed starts a Lua interpreter, loads the script foo.lua (by running 'dofile "foo.lua"'), and then has several tests for that class and its methods; and we can put another block with tests like that after the class Bletch, and other blocks after some functions. Eepitch allows sending these tests line by line to the Lua interpreter by typing on each line that we want to send, and this lets us create tests that are very easy to understand even without writing comments; this gives us a very quick way to document code by executable tests, that is super-great for experimental code that is still going to change a lot before running the risk of being read by other people.

These multi-line comments with eepitch blocks that run an interpreter and make it load the current file are called "test blocks". The command `M-x eeit' inserts a test block at point, using the major mode to decide the right syntax to use for the multi-line comments and for the "dofile". We can configure the syntax of the test blocks for the current major mode by running `M-x find-eeit-links'; this can also be used to add support for test blocks to more languages (or, more precisely: to more major modes).


An old video (made in 2021jan24; elisp here):
0:00  Hi!
0:16  I just added this section here to the documentation:
0:30  3.2. Test blocks as documentation
0:36    most people think that test blocks are very alien
1:04    The demo is this thing here:
1:25    this part downloads dednat6-minimal.zip with eepitch
1:50    we run this code-c-d so that the hyperlinks below will work
1:56    we run this setenv to set up the init file that Lua uses
2:06    the header of 'edrxlib.lua' explains how that init file works
2:19  let's go to this test block: in 'treetex.lua'...
2:23  test block 1: 'Treenode-tests'
2:24  this thing here is colored as a comment - it is a comment
2:33    if I run f8 here I start a new Lua interpreter
2:44    the line 'require \"treetex.lua\"' loads the current file
2:57    I use it as documentation for certain data structures
3:31  test block 2: 'dedtorect-tests'
3:44    run this start a new Lua interpreter
4:14  again: these things are treated by Lua as comment but...
4:24  to learn more about test blocks go to the eepitch tutorial
4:36  to the section: '3. Test blocks'