Loading ...
Sorry, an error occurred while loading the content.

gcov report for vim tests

Expand Messages
  • Nazri Ramliy
    Hi! I m fooling around with gcov[1] at $dayjob and I think vim would benefit from it too. Attached is a patch to produce both gcov (text-only) and lcov (html)
    Message 1 of 1 , Feb 14, 2013
    View Source
    • 0 Attachment
      Hi!

      I'm fooling around with gcov[1] at $dayjob and I think vim would
      benefit from it too. Attached is a patch to produce both gcov
      (text-only) and lcov (html) reports from vim's test suite.

      You may need to install lcov. gcov should come preinstalled with gcc.

      After applying the patch, do the following to get the gcov and lcov reports:

      $ cd src
      $ make gcov

      This will recompile vim with the coverage flags on and runs the test
      suite and generate the two kind of reports:

      1. gcov: This creates a foo.c.gcov for each foo.c source file.

      2. lcov: This creates an html report browsable from
      lcov-report/index.html under the src directory - all pointy-clicky.


      For gcov I've gone one step further and created a silly perl script to
      generate a .vim file that adds an "x" sign for each untested line of
      code in the c file, and an "!" sign for each untested function:

      -- gcovsign.pl 8< ---
      #!/usr/bin/env perl
      use strict;
      use warnings;
      use File::Slurp;

      foreach my $file (@ARGV) {
      my ($source) = $file =~ /(.*)\.gcov/;
      my $sign_file = "$source.sign.vim";
      my @vim = ("sign define notest text=x texthl=notest",
      "sign define notcalled text=! texthl=notcalled",
      "hi SignColumn ctermbg=none",
      "hi notest ctermfg=brown",
      "hi notcalled ctermfg=red",
      );

      my @lines = read_file($file);
      my $add_not_called_sign;
      foreach my $line (@lines) {
      if ($add_not_called_sign) {
      my ($lnum) = $line =~ /^[^:]+: *(\d+):/;
      push(@vim,
      "sign place $lnum line=$lnum name=notcalled file=$source");
      $add_not_called_sign = 0;
      } elsif ($line =~ /^ *#####: *(?'lnum'\d+):/) {
      push (@vim,
      "sign place $+{lnum} line=$+{lnum} name=notest file=$source");
      } elsif ($line =~ /called 0 /) {
      $add_not_called_sign = 1;
      }
      }
      write_file($sign_file, join("\n", @vim));
      }
      -- >8 ---

      Run it like this:

      $ perl gcovsign.pl *.c.gcov

      This should produce the corresponding *.c.sign.vim files usable like so:

      $ vim buffer.c -S buffer.c.sign.vim

      Doing ":set fdm=marker fmr={,}" we can quickly identify which
      functions are not tested at all by the red "!" signs.

      Also:

      $ grep 'function .* called 0' *.gcov

      would give a list of all untested functions.

      Have fun!

      Nazri

      [1] http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
      [2] http://ltp.sourceforge.net/coverage/lcov.php

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    Your message has been successfully submitted and would be delivered to recipients shortly.