This post updates the Gigantic Win post 
<https://groups.google.com/d/msg/leo-editor/_4TNCZt6-cA/I76d0d4QCwAJ>.* 
tl;dr*: TDD is available for Leo *right now*.

*Executive summary (updated)*

1. A *preamble *in each @test node makes it easy to run unit tests locally, 
without reloading Leo!

2. *A local @button node* (given below) creates new @test nodes, with 
*customized 
*preambles.

For the first time *ever*, easy test-driven development is available, *right 
now*.

*@button make-test*

The following (tested) @button node works spectacularly well. Just change 
the name constant when switching *kinds* of tests.

'''Make an @test node for the importer whose name is given.'''
name = 'otl'
d = g.app.permanentScriptDict
tag = 'make_test_%s_n' % name
n = d.get(tag, 0) + 1
d [tag] = n
d = {'n': n, 'name': name}
<< define preamble >>
p = c.lastTopLevel().insertAfter()
p.b = preamble
p.h = '@test %(name)s importer-%(n)s' % d
c.redraw()
c.selectPosition(p)
c.bodyWantsFocusNow()
c.frame.body.wrapper.setInsertPoint(len(p.b))

The @button make-test script does the following (with name = 'otl' as 
shown):

1. Creates a node called "@test otl importer-N" where N increases every 
time you run the script.

For example, make-test, Ctrl-P, Ctrl-P creates:

@test otl importer-1
@test otl importer-2
@test otl importer-3

If you change name to 'javascript', hitting Ctrl-P three times will create 
the more nodes:

@test javascript importer-1
@test javascript importer-2
@test javascript importer-3

Every time you run the script, the scripts selects new @test node and 
places cursor at the end of the node's body text, ready for you to start 
the real test!

Here is my present << define preamble >> section:

preamble = '''\
if 1:
    # The preamble...
    g.cls()
    if c.isChanged(): c.save()
    import imp
    import leo.plugins.importers.linescanner as linescanner
    import leo.plugins.importers.%(name)s as %(name)s
    imp.reload(linescanner)
    imp.reload(%(name)s)
# insert test for %(name)s here.
''' % d

As you can see, the preamble inserts the 'name' constant automatically.  No 
need to change this by hand, unless you want a different preamble 
altogether.

*Summary*

@button make-test makes TDD *effortless.* It will soon appear in scripts.leo

Today's work proves that we have only begun to see what is possible with 
Leo.

On this Thanksgiving day, I am truly grateful to have been given the 
opportunity to make this discovery.  And thanks to all of you for your 
ongoing support and encouragement.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to