Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Have some Elisp code.

    (defun toggle-test-plan ()
      (interactive)
      (let ((new-pos))
        (save-excursion
          (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 ()
        (interactive)
        (let ((new-pos))
          (save-excursion
            (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 would have liked and was not incorporated (I'm disappointed, but agree).

            I'd also like TogglePlan to work with Test::Class and that shouldn't be too hard, but I've not written the code for it yet.

            The ,gt and ,gm functions are tough. They require a bit of discipline on the part of developers in how they want to lay out their code so that one can find the appropriate test and/or implementation in a deterministic fashion. If the user has a non-standard layout, it would require that they set some variables in their .vimrc file to let PerlTests.vim know how to find things. Also, while this is fairly easy for Test::Class, I think special comments would be necessary in modules and tests if just using regular Test::More style scripts. I'm thinking something like this:

            package Foo;

            # :test:t/foo.t:

            And in the test:

            #!/usr/bin/perl -T

            # :module:lib/Foo.pm

            If that worked, you could easily pop back and forth between your test and its implementation with very little work.

            For Test::Class, you would specify test package identifier (typically 'TEST' or 'Test') and whether it's prefix, postfix, or infix. Here are the allowed styles:

            Test::My::Dedicated::Customer; # prefix
            My::Dedicated::Customer::Test; # postfix
            My::Dedicated::Test::Customer; # infix

            In your .vimrc, you would then set:

            set pt_testpath='t/tests/'
            set pt_libpath='lib/'
            set pt_testpackage='TEST'
            set pt_testfix='prefix'

            There's a reason why 'infix' is there, but it's a long story dealing with a company I used to work for. I doubt I'd actually include that.

            • Ooh, and along with the regular documentation, it would be nice to include something like Ian Langworth's testing quick reference card [langworth.com] 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.