問題描述
使用 Devel‑Cover 獲取覆蓋率報告 (Using Devel‑Cover to get coverage reports)
我是 Perl 新手,我正在嘗試為我擁有的 Perl 腳本生成覆蓋率報告。我按照此處提到的步驟安裝了 Devel‑Cover https://code.activestate.com/ ppm/Devel‑Cover/ 並運行
perl ‑MDevel::Cover script
我得到一些覆蓋率信息和該消息
Pod coverage is unavailable. Please install Pod::Coverage from CPAN.
然後運行命令cover
生成報告我得到 cover: Command not found.
嘗試按輸出所述運行 cpan install Pod::Coverage
但它失敗了。我不確定我在這裡缺少什麼。我也嘗試使用 Devel::Coverage 使用
perl ‑d:Coverage script
但我得到了輸出
Can't locate Devel/Coverage.pm in @INC (you may need to install the Devel::Coverage module) (@INC contains: /spiratech/tools/perllib /home/mmaher/.cache/activestate/02540130/lib/perl5/site_perl/5.32.0/x86_64‑linux /home/mmaher/.cache/activestate/02540130/lib/perl5/site_perl/5.32.0 /home/mmaher/.cache/activestate/02540130/lib/perl5/5.32.0/x86_64‑linux /home/mmaher/.cache/activestate/02540130/lib/perl5/5.32.0).
BEGIN failed‑‑compilation aborted.
%!s(<nil>)
我不能 找不到有關如何安裝它的任何說明。我正在使用 Perl v5.32.0
參考解法
方法 1:
Zeroth, ActiveState's PPM is old stuff. They have a new State Tool to handle all of that. Note that this is for using their Perl packages. If you aren't using ActiveState's perl, don't use their instructions.
First, you only need Pod::Coverage if you want to check that all of your public subroutines are documented. It's an optional feature.
Second, there's no install
command to cpan
. Just list the modules that you want or use the command line options. With no options, the ‑i
(for install) is assumed:
$ cpan Pod::Coverage
$ cpan ‑i Pod::Coverage
Third, the ‑d
switch for debugging assumes that you are loading a module under the Devel
namespace. That's why ‑d:Coverage
looks for Devel::Coverage
, which it then cannot find.
To load any module that you like, you can use the ‑M
switch. This takes the entire module name:
$ perl ‑MPod::Coverage
Lastly, once you install Devel::Cover
, look where you installed cover
and ensure that that directory is in your PATH
.
(by Merolla、brian d foy)