PATCH: added new Test::Unit compiler plugin

Sam Roberts sroberts at uniserve.com
Fri Apr 30 23:16:45 EDT 2004


Quoteing djkea2 at mugca.its.monash.edu.au, on Thu, Apr 22, 2004 at 09:58:57AM +1000:
> On Wed, Apr 21, 2004 at 07:42:36PM -0400, Sam Roberts wrote:
> > I put it in ~/.vim/compiler
> > 
> > It's not working for me, I get taken to a seemingly random line.
> > 
> > I did this:
> > 
> > > :compiler rubyunit
> > > :make mytests.rb
> > 
> > 
> > I also do:
> > 
> > > :make % | :cwin
> > 
> > and
> > 
> > > :cwin
> > 
> > Neither of them show me a quickfix window with any errors.
> > 
> > Any suggestions on what I'm doing wrong, what anything I can do to give
> > you an idea what's happening?
> 
> If it's not too large, send me a copy of your tests and applicable code
> and I'll take a look.

Ok, I can't reproduce the jump to random lines (in a small example), but
I found one thing, if the test fails because an exception was thrown
from the code being tested, then you don't get to that line.

Here's the code:

-- vim.rb --
module Vim
  def Vim.ok(x)
    x
  end

  def Vim.fail(x)
    x + "hi"  # note that this code will fail when x is a number
  end
end
------------

Here's the test

--- test_vim.rb --
#!/usr/bin/ruby -w

require 'test/unit'
require 'vim'

class TestVim < Test::Unit::TestCase
  def test_external
    assert_equal(0,    Vim::ok(1))
  end

  def test_internal
    assert_equal(0,    Vim::fail(0))
  end
end
-----------------

I do:

:compiler rubyunit
:make test_vim.rb

And I can see the output in the err window, but I can't get to any of
the lines in the test_internal(), just the assert_equal for
test_external().


I hope I don't sound like I'm whining to you about your unit-test code,
I'm just struggling to get vim working for me!

Vim, and running my test suites from inside it, is central to my C
development/day job, I'm in vim (of the command line) all day, and I
work very quickly and effectively, but despite that I'm using it all
day, I know very little about it's config language, I've tweaked the
things I need (indenting, TABS->SPCS, etc.), incremental search, and
that's about it.

I use a similar model with ruby, now:

- I have a top-level makefile in my ruby project
- the makefile runs the test suite as its default target, but also
  has targets for packaging, building the docs, etc.
- I run ":mak" after changing code, or adding tests, to make sure its
  all OK

I would love for ":cn" to take me through the error lines in my ":cwin",
in the case above, thats:

|| 2) Error!!!
|| test_internal(TestVim):
|| TypeError: String can't be coerced into Fixnum
|| ./vim.rb:8:in `+'
|| ./vim.rb:8:in `fail'
|| test_vim.rb:12:in `test_internal'
|| test_vim.rb:11


So, if I could either select and press enter on each line that has a
file:lineno in the cwin, I would be happy, or if I could do :cn and :cp
and move forward and backwards through the places in the stack I would
be happy, too.

Also, how could I modify the test/unit so that I can run my tests with
make?

Can you, or anybody, either give me some advice on how to make this
work, or else suggest an alternate way of developing ruby code from
inside vim? Maybe there's an easier way, and I'm missing it?

Sam



More information about the vim-ruby-devel mailing list