编写一个工具来支持代码覆盖率测试

发布于 2024-07-13 05:19:21 字数 334 浏览 6 评论 0原文

我正在尝试编写一个小型工具来支持我们在公司运行的一些代码覆盖率测试。

这是我对该工具的要求 -

输入 - 已修改的文件(.cpp 和 .h)列表(作为签入更改列表的一部分)

输出 - 在源中添加或修改的所有功能(作为签入更改的结果)。

知道我该怎么做吗? 基本上,它可以归结为更改了哪些行以及与更改后的行相关的功能是什么......

更多信息 - 源代码控制:Perforce 平台:Windows

I am trying to write a small tool to support some of code coverage tests we are running in my company.

Here's my requirement for the tool -

Input -
List of files (.cpp and .h) which have been modified (as a part of a checked-in changelist)

Output -
All the functions which were added or modified in the source (as a result of checking-in the change).

Any idea how I can go about doing this? Basically, it boils down to what lines changed and what is the function associated with the changed lines...

More info -
Source Control: Perforce
Platform: Windows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉目亦如画i 2024-07-20 05:19:21

这听起来很棘手。 我不确定您会如何处理源代码中有关已更改功能的信息。 您不想将代码覆盖范围限制为这些函数:更改的函数可能会影响未更改的函数的覆盖范围。

也许最好的办法就是在每次签入时运行所有测试,或者如果有任何变化,则每小时运行一次。 然后您就可以跳过复杂的工具创建,并获得更好的结果。

This sounds tricky. And I'm not sure what you'd do with the info about the changed functions in the source. You don't want to limit your code coverage to those functions: it could be that a changed function affected the coverage of an unchanged function.

Perhaps the best thing to do is simply run all your tests on each check-in, or once an hour if anything has changed. Then you could skip the complex tool creation, and have better results anyway.

潦草背影 2024-07-20 05:19:21

由于所有文件都已签入 Perforce,因此您可以对更改后的文件与先前版本进行批量比较 (p4 diff2)。 p4 diff2 还采用分支规范,这可能是更方便的方法。

当发现差异时,您将需要编写一个脚本来提取更改行的方法名称。 该算法可能是“在文件中向后搜索,直到找到适合您的语法的方法签名”。

为了更聪明,请根据文件名或另一个脚本生成的类列表来确定类名。 这个类名列表有助于确定方法签名。 如您所知,类名后面跟着 :: 和方法名。

我认为这个算法对于任意输入来说很容易达到 95% 以上的准确率,但很难达到 100% 的准确率。

此脚本应排除重复项以生成唯一列表。

生成的列表是您在问题中请求的列表。

Since all the files are checked into Perforce, you could do a batch diff (p4 diff2) of the changed files with the previous revision. p4 diff2 also takes a branch spec which might be a more convenient method.

When a diff is found, you will need to write a script to extract the method name of the changed line. The algorithm might be "Search backwards in the file until you find a method signature for your syntax".

To be clever, determine the class name based on the file name or a list of your classes generated by another script. This list of class names can be helpful in determining the method signature. As you know, the class name is follow by :: and the method name.

I judge this algorithm to be easy to make 95+% accurate and hard to make 100% accurate for arbitrary input.

This script should exclude duplicates to generate a unique list.

The resulting list is the list you request in your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文