summaryrefslogtreecommitdiffstats
path: root/2021/talks/test.md
blob: c3b6125d0a0fa148c65d47e1ea974c6248646197 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[[!meta title="Test blocks"]]
[[!meta copyright="Copyright © 2021 Eduardo Ochs"]]
[[!inline pages="internal(2021/info/test-nav)" raw="yes"]]

<!-- You can manually edit this file to update the abstract, add links, etc. --->


# 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 <f8\> 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).

Eduardo Ochs <http://angg.twu.net>



[[!inline pages="internal(2021/info/test-schedule)" raw="yes"]]

[[!inline pages="internal(2021/info/test-nav)" raw="yes"]]