summaryrefslogtreecommitdiffstats
path: root/2021/talks/test.md
blob: b858bd4e9a0271b3c1f53cc921dd9262da75d3b9 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[[!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

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

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/emacsconf2021.html>

# Discussion

IRC nick: edrx

- I love the slide annotations!  They are really nice. :-)
- Love the Racket's (module+ ...)  but this test blocks are interesting too...
- looks like eev should be using eieio to me :)
- am I the only person who never heard of eev before this talk and now has a million uses for it? I've wanted this thing for ages
  - You're in luck! You can check EmacsConf 2019 and 2020 for more eev goodness.
  - that happens every time edrx does a talk on eev!
  - <https://emacsconf.org/2019/talks/27/>
- does language support take a lot of work, or did I miss you relying on a different package that handles that?
- Cool!  So this is kind of like a generic version of Python's doctests? (https://docs.python.org/3/library/doctest.html) 
  - edrx: I don't think so... is it possible to run python's doctests line by line? Also, see this: https://www.youtube.com/watch?v=QUMo7vgkHJI#t=6m36s - we can change the tests on the fly...

[[!inline pages="internal(2021/captions/test)" raw="yes"]]

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