简体   繁体   English

我可以重新测试所有已安装的CPAN模块吗?

[英]Can I retest all installed CPAN modules?

If a module A relies on module B and module B is upgraded, A may break due to changes. 如果模块A依赖于模块B并且模块B升级,则A可能由于更改而中断。 My idea is to retest both A and B after upgrading B . 我的想法是在升级B后重新测试AB

I think the easiest way is just to retest everything that can be retested: download every installed module from CPAN and execute its test scripts. 我认为最简单的方法就是重新测试可以重新测试的所有内容:从CPAN下载每个已安装的模块并执行其测试脚本。

Is there a way to download and retest? 有没有办法下载和重新测试?

If there is no way, are there any helpers/API so I can implement such tool? 如果没有办法,是否有任何助手/ API,所以我可以实现这样的工具?

I basically need to 我基本上需要

  • query what is installed (including version numbers) 查询安装的内容(包括版本号)
  • download and unpack exact versions 下载并解压缩确切版本
  • execute tests 执行测试

The cpan tool that ships with core Perl includes a -l option, that directs it to provide a list of installed modules. 随核心Perl一起提供的cpan工具包含-l选项,该选项指示它提供已安装模块的列表。 For example, the last 10 items in the list on my system: 例如,我系统列表中的最后10项:

$ cpan -l 2>/dev/null |tail -10
Test2::Event::Encoding  1.302073
Test2::Event::Bail  1.302073
Test2::Event::Exception 1.302073
Test2::Event::Subtest   1.302073
Test2::Event::Skip  1.302073
Test2::Event::Info  1.302073
Test2::Event::Diag  1.302073
Test2::Event::TAP::Version  1.302073
JSON::PP    2.27400_02
JSON::PP::Boolean   undef

As demonstrated here you get a list of modules and version numbers. 如此处所示,您将获得模块和版本号的列表。 Sometimes the tool doesn't find the version in META, and therefore will return undef for the version numbers. 有时该工具在META中找不到版本,因此将返回版本号的undef CPAN authors should be on the lookout for these sorts of mistakes, as they make it harder for tools that wish to identify the version without compiling the module itself. CPAN作者应该注意这些类型的错误,因为它们使得希望在不编译模块本身的情况下识别版本的工具变得更加困难。

Once you have the modules and version numbers you can use the cpanm tool (provided by App::cpanm) with its --test-only option to pull down a module of a specific version and test it. 获得模块和版本号后,您可以使用cpanm工具(由App :: cpanm提供)及其--test-only选项来下载特定版本的模块并对其进行测试。 You can request a specific version like this: 您可以请求这样的特定版本:

cpanm Some::Module@0.9990

(Pulls down only version 0.9990 of the target module). (仅下拉目标模块的0.9990版本)。

Where things get tricky are the following: Perl ships with a bunch of modules, and some of them also receive updates via CPAN. 事情变得棘手的是:Perl附带了一堆模块,其中一些还通过CPAN接收更新。 The cpan -l tool will list all installed modules, including the ones that ship with Perl. cpan -l工具将列出所有已安装的模块,包括Perl附带的模块。

Also some of the modules listed are simply part of a larger distribution. 此外,列出的一些模块只是更大分布的一部分。

Another tool that can be useful to you, which has been bundled with Perl since 5.8.9, is corelist . 另一种工具,可以对你有用,因为5.8.9已经捆绑使用Perl,是corelist If you run this: 如果你运行这个:

corelist File::Temp

You will get: " File::Temp was first released with perl v5.6.1 " 你会得到:“ File::Temp was first released with perl v5.6.1

If you do this: 如果你这样做:

corelist JSON

You will get: " JSON was not in CORE (or so I think) " 你会得到:“ JSON was not in CORE (or so I think)

So it is pretty simple to determine if a module you're looking at in your list is one that ships with Perl or not. 因此,确定列表中正在查看的模块是否与Perl一起提供的模块非常简单。 Use that information as you see fit. 根据需要使用该信息。

Another thing you'll have to solve for is what to do about shared dependencies. 您需要解决的另一件事是如何处理共享依赖项。 If the first thing you test is a Moose upgrade, you'll pull in half of CPAN (that's an exaggeration), and that will dirty your environment for testing other modules. 如果您测试的第一件事是Moose升级,那么您将获得一半的CPAN(这是夸大其词),这将污染您的环境以测试其他模块。 To mitigate this effect you have a few choices. 为了减轻这种影响,您有几个选择。 One is to leverage App::perlbrew and its lib option to set up throwaway library space. 一个是利用App::perlbrew及其lib选项来设置一次性库空间。 That way you can install a module and its dependencies in a destination designated by perlbrew lib and perlbrew use , and then throw it away when done to move on to the next library for testing. 这样你就可以在perlbrew libperlbrew use指定的目的地中安装一个模块及其依赖项,然后在完成后将其丢弃以转移到下一个库进行测试。

However, there may be a better solution, of which I am not adequately familiar to document here: The toolchain used by CPAN smoke testers. 但是,可能有一个更好的解决方案,我不熟悉这里的文档:CPAN烟雾测试仪使用的工具链。 See CPAN::Testers if you wish to pursue this strategy. 如果您希望采用此策略,请参阅CPAN ::测试人员 The smoke testers have worked out relatively lightweight approaches to pulling down and testing modules with their dependencies in an automated fashion. 烟雾测试人员已经制定了相对轻量级的方法,以自动方式下拉和测试模块及其依赖性。

Finally, another issue you will encounter is that CPAN authors are the ones who decide which versions of their modules live on CPAN and which ones get deleted. 最后,您将遇到的另一个问题是CPAN作者决定哪些版本的模块存在于CPAN上以及哪些版本被删除。 A few years ago CPAN authors were encouraged to keep their CPAN repositories clean by deleting old versions. 几年前,CPAN的作者被鼓励通过删除旧版本来保持他们的CPAN存储库清洁。 I don't know if this practice is still encouraged, but it does mean that you cannot count on a specific version number still existing. 我不知道这种做法是否仍然受到鼓励,但它确实意味着您不能指望仍然存在的特定版本号。 To solve for this problem you should probably maintain your own repository of the tarballs for all versions you have installed at a given moment in time. 要解决此问题,您应该为您在给定时刻安装的所有版本维护自己的tar包存储库。 The CPAN module framework Pinto helps with keeping versions of a module, pinning some to not update, and other useful tricks. CPAN模块框架Pinto有助于保留模块的版本,固定一些不更新,以及其他有用的技巧。

If you download and extract distribution B and cd into that directory, you can use the brewbuild binary from my Test::BrewBuild (NOTE: requires Perlbrew or Berrybrew) with the -R aka --revdep flag to test B as well as all distributions that require B : 如果你下载并提取分发Bcd到该目录,你可以使用我的Test :: BrewBuild中brewbuild二进制文件(注意:需要Perlbrew或Berrybrew)和-R aka --revdep标志来测试B以及所有发行版需要B

~/repos/Mock-Sub $ brewbuild -R

reverse dependencies: Test::Module::CheckDep::Version, App::RPi::EnvUI, RPi::DigiPot::MCP4XXXX, Devel::Examine::Subs, PSGI::Hector, File::Edit::Portable, Devel::Trace::Subs

Test::Module::CheckDep::Version
5.26.1 :: PASS

App::RPi::EnvUI
5.26.1 :: FAIL

RPi::DigiPot::MCP4XXXX
5.26.1 :: FAIL

Devel::Examine::Subs
5.26.1 :: PASS

PSGI::Hector
5.26.1 :: PASS

File::Edit::Portable
5.26.1 :: PASS

Devel::Trace::Subs
5.26.1 :: PASS

I do this every time I update one of my CPAN distributions that have reverse dependencies, so I don't break any consumers of my dists. 我每次更新一个具有反向依赖关系的CPAN发行版时都会这样做,所以我不打破任何我的dists的消费者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM