Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Wednesday August 09, 2006
04:52 AM

Toggling test plans with vim

[ #30575 ]

For some reason, folks seem to complain a lot about the test plan in vim because, as you know, it's so much work to switch 'no_plan' to a real plan. Based on a couple of mappings that chromatic wrote, I wrote a plugin that toggles the test plan for you just by typing ',tp' ('t'oggle 'p'lan). Now I expect folks to complain because they still have to update the test count manually.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Could your plugin perhaps count the number of calls to qw/isa_ok is isnt ok is_deeply etc/ and update the test count with that information?

    Sure, compiling that list would be tedious, but each person could maintain their own.

    Of course... I'm forgetting about tests inside cycles, so... hum...

    Well, I just felt like complaining :-)
    • Yeah, the problem is that this involves parsing Perl, a notoriously unreliable thing. Otherwise, I'd be happy to. Fortunately, I work with a vim guru (smylers) and he's been helping me with the tricky bits.

      • I am not complaining...just nudging you to post your plugin(s) to
        • I think I will, but now that I'm looking at it, I have a bunch more work to do on it. I have some automatic pod generation and boilerplate routines that I could use to create a 'PerlDeveloper.vim' script that could incorporate a lot of nifty things to make vim a very easy choice for Perl. However, can't do that at work :)

  • Have some Elisp code.

    (defun toggle-test-plan ()
      (let ((new-pos))
          (goto-char (point-min))
          (cond ((re-search-forward "More[ \t]+tests[ \t]*=>[ \t]*" nil t)
             (replace-match "More 'no_plan'; # tests => " t t))
            ((re-search-forward "More[ \t]+'no_plan';[ \t]*#[ \t]*" nil t)
             (replace-match "More " t t)

    • Argh. Tabs ruined my indentation.

      (defun toggle-test-plan ()
        (let ((new-pos))
            (goto-char (point-min))
            (cond ((re-search-forward "More[ \t]+tests[ \t]*=>[ \t]*" nil t)
                   (replace-match "More 'no_plan'; # tests => " t t))
                  ((re-search-forward "More[ \t]+'no_plan';[ \t]*#[ \t]*" nil t)

      • Hey, that looks awesome (no surprise that someone interested in Prolog would have Lisp skills, I suppose).

        I've been thinking about creating several vim tools specifically dedicated to making tests easier to write and maintain. Would you be interested in converting them to eLisp?

        • Sure, that's fine. What were you going to create? The only thing I really want to do is get *smart* autocompletion of identifiers. Right now all I have Emacs doing is noticing that fun\t might be short for things like function_name, function_fqfname, function_ref, etc. That is, anything \w+-like that it already has open somewhere. That's often good enough especially since I don't ever really write out whole variable names anymore but it'd be even nicer if it knew something about methods.

          So what helpers do y
          • There are a few features I'm thinking about.

            1. ,tp Toggle plan
            2. ,tt Run test (even with Test::Class)
            3. ,tm Run Test::Class test method (requires a planned but unimplemented feature of Test::Class)
            4. ,gt and ,gm, "goto test" and "goto module", respectively.
            5. Other things I think up as I go along (I have vauge ideas)

            Obviously I have 1 and 2 working. Number 3 requires a planned feature for Test::Class that lets you run a single test method. I've submitted a patch, but it wasn't as clean as Adrian

            • Ooh, and along with the regular documentation, it would be nice to include something like Ian Langworth's testing quick reference card [] information. I'm unsure of the syntax, but if someone new to testing wants a quick refresher of how to use Test::More, they could type something like:

              :quickref Test::More

              And get short output like what's on the card. Still, I don't like that syntax.