Wow, cool. I really need to learn Vim more. :-)
Anything in particular in that post need further explaining? I
tried to comment it more than I do my own throw-away scripts in
the hopes that readers could follow along.
The basic framework of the script was
[function definition]
[line of code to run the tests]
[line to terminate the script at this point in the file]
[bunch of lines of test filenames/dirnames]
I don't know as if I've ever seen anybody else do the finish/:g
pair of commands to include a test suite in a script, but it
sounded like what I wanted to do at the time. The test suite
doesn't have the expected results in it, like I would have
preferred, but you've gotta give somewhere. :) I'll leave that
as an exercise for the reader ;)
The function definition should be fairly straightforward. It
first ensures that there's one and only one trailing slash at the
end of the parameter. It then expands any variables, resolves
them (in case there are symbolic links or .LNK files on win32 in
the path), and tests if the resulting name is a directory. If it
is, we're good to go. If it's not, it tries to make the
directory (escaping at least spaces...other characters might need
to be escaped as well). It then tests again to see if the
directory was successfully created. If so, all's good. If not,
it spontaneously combusts into a thousand messy pieces that
you'll have to scrape off the ceiling with a spatula. Or echoerr. :)
The test-harness line is a bit opaque, but managable. Operating
on the range from the last line containing only the word "finish"
in the file through the end of the file, it does issues commands
on lines that don't match (":v") the pattern "beginning of the
line, followed by whitespace, followed by a double-quote". As
the double-quote is used as the vimscript comment leader, I just
kept it the same. Thus it ignores any commented lines. One
might want to make a smarter test harness that ignored blank
lines too. It then, for each of those non-comment lines, gets
the line's contents and passes it as a parameter to the function.
The "finish" line stops the vimscript in its tracks so that vim
doesn't attempt to parse the remainder of the file as
script...which is good, because the rest of the file isn't
vimscript, but stuff that would make vim choke.
Hope this gives a bit of a breakdown and makes it easier to
follow along. Feel free to incorporate any or all of it into
your own scripting adventures. Just one more vimscript hack.
Enjoy!
-tim