[[!meta title="Test blocks"]] [[!meta copyright="Copyright © 2021 Eduardo Ochs"]] [[!inline pages="internal(2021/info/test-nav)" raw="yes"]] # Test blocks Eduardo Ochs 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). Cheers =), Eduardo Ochs [[!inline pages="internal(2021/info/test-schedule)" raw="yes"]] [[!inline pages="internal(2021/info/test-nav)" raw="yes"]]