http://www.perlmonks.org?node_id=11133020

ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I'm using Devel::Cover. I run my script on two different hosts (to test different envs). Let's call the first and the second one host X and host Y, respectively for convince.
The code that I test is the same on both sites (it's being copied first to those sites, before running the script).
I want to create one merged HTML report of those results (from both hosts). The way I run Devel::Cover:
perl -MDevel::Cover=-silent,1,-db,${cover_db_path}" ${perl_script}
It creates the coverage db and then I can use the "cover" script to create the HTML report.

As I mentioned, I want to create one merged report of those dbs (from the two hosts). The problem is that the ${perl_script} is located in two different places. In host X I have /a/b/repo/run.py and in host Y I have /x/y/repo/run.py (please note that all of the perl scripts that I'm interested in are located under "repo" directory).
So I can sum up three problems that dependent on each other:
1. I can copy the cover_db from those sites but running the cover script will not work since it will not find those paths locally. It will create the report but it will have N/A for those paths, which of course makes sense, since it needs the source code.
2. I can run the cover script remotely on each site and create the reports but then how do I merge those HTML reports?
3. If it was possible to merge the HTML reports, how can I make them understand that /a/b/repo/* is the same as /x/y/repo/*?


I don't want it to become an X-Y problem so I would ask this - How would you merge two cover dbs that are located on two different hosts?

Replies are listed 'Best First'.
Re: How to merge two different coverage reports remotely
by choroba (Cardinal) on May 25, 2021 at 22:24 UTC
    Isn't it possible to create a directory /a/b with a symlink to /x/y/repo so that the paths are actually the same? Then, you should be able to merge the databases, too.

    I was able to make it work, but only for a very simple script. Make sure to backup or commit the coverage reports so you don't have to rerun the scripts every time you discover a problem.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Then, you should be able to merge the databases, too. I was able to make it work, but only for a very simple script.

      From a high level, how did you go about doing it? Is it just concatenating some or all of the text files in the cover_db directory? Or do you have to do a manual interleave of data within each file? Or worse, a manual interleave-and-add for counts for certain lines of code? Is it just a subset of files that you have to merge?

      Sorry, since I've never looked into merging them before, or really even at the raw data -- I always just look at the HTML report at the end -- I wouldn't know where to start for the merge. Given the original question, it wouldn't surprise me if the OP was in the same boat as I am. So hints as to how to get started with the merge would be nice. (I am bookmarking this thread, since I think some of my repos might get better coverage numbers if I am able to eventually merge the linux and windows results; I'm reasonably confident that between the CI systems, I have full coverage, but being able to prove it would feel nice.)

        No, I just copied the cover_db from one remote to a directory and ran
        cover cover_db downloaded/cover_db

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: How to merge two different coverage reports remotely
by 1nickt (Canon) on May 25, 2021 at 20:57 UTC

    Hi,

    "The code that I test is the same on both sites"

    So why do you need to run the coverage report on both hosts?


    The way forward always starts with a minimal test.
      Hi!
      Thank you for your comment. I test the code on different hosts, since it's depends on the environment. I copied the code to those hosts to be able to run it there and then get the results. It works but now I want to find the coverage. I want able to get the coverage for each one of them but I want to merge it into one report. The question is how?

        Hi again,

        "I test the code on different hosts, since it's depends on the environment."

        That's one thing, and should be done for sure. But generating a test coverage report depends on the codebase, not the environment, unless you're using it in some way I've not encountered.


        The way forward always starts with a minimal test.