If you develop code using Leo, please read at least the executive summary. It might change your life. It certainly has changed mine.
Executive Summary
1. A
preamble in each @test node makes it easy to run unit tests locally, without reloading Leo!
2. A local test;; abbreviation could create new @test nodes, with
customized preambles.
3. A new reload-abbreviation command (
#340) will allow you to change the preamble without reloading Leo.
This is huge: for the first time
ever, test-driven development will be easy and natural in
Leo.
DetailsI developed these ideas while working on the new importers. Experience shows that I almost
never get regex's right at first. Creating a unit test for each regex saved time almost instantly,
despite some initial setup costs.
The setup cost is that local unit tests must start with a
custom preamble:
g.cls()
if c.isChanged(): c.save()
import imp
import leo.plugins.importers.otl as otl
imp.reload(otl)
x = otl.Otl_Importer(c.importCommands, atAuto=False)
With this preamble, I can run the tests after changing the otl plugin without reloading leoPlugins.leo. This was the beginning of the avalanche...
Here is typical code that follows the preamble:
pattern = x.otl_pattern
print(pattern)
table = (
'body line',
'\tline 1',
' \tlevel 2',
)
for line in table:
m = pattern.match(line)
print('%20r ==> (%r)(%r)' % (
line, m and m.group(1), m and m.group(2)))
Using this @test node, I can modify the regex and see the results
instantly. This saved about 20+ seconds
per coding iteration, a
gigantic win.
I
t is impossible to overstate the importance of this new work flow!It has changed my life. It also got me thinking about a further improvement, namely creating custom preambles for new tests more easily.
Issue
#340 proposes a new reload-abbreviations command. This will allow devs to change the preamble without reloading Leo. The ultimate work flow will be:
- Modify the
local test;; abbreviation so that it supports the code under test.
- Run reload-abbreviations.
- Create new tests with test;;
This will make true test-driven development feasible, for the first time ever in Leo.
Edward