5

I have been tasked with cleaning up some legacy code which is poorly written, but has an astonishingly large number of tests. Some of these tests run code in files like this:

fcgi/*.fcgi

I would very much like to include those in my coverage reports. In fact, I'd love to ensure that I can include everything (regardless of extension) in lib/, fcgi/, and utils/ and nothing in any other directories.

This is one of my many attempts:

HARNESS_PERL_SWITCHES=-MDevel::Cover=+inc,fcgi,+inc,lib,+inc,util prove -rl t

FAIL!

I've also tried creating simple Build.PL or Makefile.PL scripts and keep getting "No tests defined" when I run things like 'cover -test' or './Build testcover'.

This is Devel::Cover 0.88 and perl version 5.12.2

Community
  • 1
  • 1
Ovid
  • 11,580
  • 9
  • 46
  • 76
  • 1
    Can you create a minimal test case tarball that contains a makefile.pl, some .t files and a normal .pm as well as some other files that are being called but not covered correctly? If i had that i'm sure i could get you the right config. – Mithaldu Jul 06 '12 at 15:25
  • 1
    Mithaldu: I've just created it. PM me your email and I'll send it over. Thanks! – Ovid Jul 06 '12 at 15:34
  • (Not exactly the same, but for others who find this via Google) In a similar situation, I added [Test::UseAllModules](https://metacpan.org/pod/Test::UseAllModules) to pull in all my lib/**/*.pm files. That way `cover -test` knew about all of them, including those not otherwise tested. [This article](https://www.perl.com/article/208/2016/1/5/Save-time-with-compile-tests/) by David Farrell shows how to pull in other files based on globs. – cxw Dec 27 '20 at 14:57

1 Answers1

3

Alright, i took your example, fiddled a bit with it and it seems to work fine for me with a minimal Makefile.PL and cover -test. Please clone this: git://gist.github.com/3061026.git

The README file contains what happens on my system.

Specifically, in one of my test files, I added:

use 5.12.0;
use Test::More;

use lib 'lib';

use Foo;
require 'fcgi/foo.fcgi';   # <====== pull in an fcgi file

is craptastic(), 'This is craptastic',
    'We have run an fcgi/*fcgi test';
cxw
  • 16,685
  • 2
  • 45
  • 81
Mithaldu
  • 2,393
  • 19
  • 39
  • In the real system, I kept getting "no tests run" with the minimal Makefile. However, the right incantation (with `prove`) seems to be: HARNESS_PERL_SWITCHES=-MDevel::Cover=+inc,t,+select,fcgi prove -l t – Ovid Jul 06 '12 at 16:06
  • Very strange. Maybe your EUMM is old? – Mithaldu Jul 06 '12 at 16:12
  • Mithaldu, I'll have to look into again on Monday. The example I posted works for my "minimal test case" but fails for the real code base. – Ovid Jul 06 '12 at 17:27
  • The Gist on GitHub: https://gist.github.com/wchristian/3061026 – Daniel Böhmer Jan 18 '22 at 15:05
  • If you use `-MDevel::Cover=+inc,lib` all kinds of modules are included in the stats because `lib` is in their absolute paths. This doesn’t solve the actual issue of forcing all files from my project – Daniel Böhmer Jan 18 '22 at 15:06