Visual Studio 2015 代码覆盖错误文件
Visual Studio 2015 Code Coverage Wrong File
我正在使用 VS 2015 Enterprise,并且我 运行 一个通用单元测试来分析代码覆盖率。我正在查看每个函数的覆盖块列表,它们通常看起来是正确的。但是,当我右键单击一个方法 -> "Go to source code" 时,在某些函数上它会转到源代码中的正确位置(相关的 .cpp 文件),但在其他函数上它会尝试打开头文件(源行号是正确的,但代码在 .cpp 文件中——而不是 .h 文件中)。这会影响源代码突出显示——VS 认为在 .h 中的函数不会在 .cpp 中突出显示。我无法确定函数中的任何差异(相同的可见性、相同的头文件和源文件),除了可能调用它们的线程。知道为什么 VS 认为某些代码在 .h 而不是 .cpp 中吗?
显然,尽管 VS 2015 支持 C++11 功能 non-static data member initializers (it does compile correctly), the coverage tool chokes on this feature. Here's the MCVE. I'm using VS 14.0.24720.00 Update 1. To reproduce, compile this program then get code coverage by running it using a Generic Test。如果 x
已初始化,覆盖工具会在 .h 文件中查找构造函数的代码。如果您取出 = 0
,它会正确识别 .cpp 中的构造函数定义。在我的产品代码中,它不是构造函数,而是覆盖工具认为在 .h 文件中定义的看似随机的函数。在我的例子中,修复只是将数据成员初始化移动到构造函数初始化列表。
//.h
class Test
{
public:
Test();
~Test();
void Func1();
void Func2();
void Func3();
int x = 0;
};
.
// .cpp
#include "Test.h"
#include <iostream>
Test::Test()
{
std::cout << "in Test()" << std::endl;
}
Test::~Test()
{
}
void Test::Func1()
{
std::cout << "in Func1" << std::endl;
Func2();
Func3();
}
void Test::Func2()
{
std::cout << "in Func2" << std::endl;
}
void Test::Func3()
{
std::cout << "in Func3" << std::endl;
}
我正在使用 VS 2015 Enterprise,并且我 运行 一个通用单元测试来分析代码覆盖率。我正在查看每个函数的覆盖块列表,它们通常看起来是正确的。但是,当我右键单击一个方法 -> "Go to source code" 时,在某些函数上它会转到源代码中的正确位置(相关的 .cpp 文件),但在其他函数上它会尝试打开头文件(源行号是正确的,但代码在 .cpp 文件中——而不是 .h 文件中)。这会影响源代码突出显示——VS 认为在 .h 中的函数不会在 .cpp 中突出显示。我无法确定函数中的任何差异(相同的可见性、相同的头文件和源文件),除了可能调用它们的线程。知道为什么 VS 认为某些代码在 .h 而不是 .cpp 中吗?
显然,尽管 VS 2015 支持 C++11 功能 non-static data member initializers (it does compile correctly), the coverage tool chokes on this feature. Here's the MCVE. I'm using VS 14.0.24720.00 Update 1. To reproduce, compile this program then get code coverage by running it using a Generic Test。如果 x
已初始化,覆盖工具会在 .h 文件中查找构造函数的代码。如果您取出 = 0
,它会正确识别 .cpp 中的构造函数定义。在我的产品代码中,它不是构造函数,而是覆盖工具认为在 .h 文件中定义的看似随机的函数。在我的例子中,修复只是将数据成员初始化移动到构造函数初始化列表。
//.h
class Test
{
public:
Test();
~Test();
void Func1();
void Func2();
void Func3();
int x = 0;
};
.
// .cpp
#include "Test.h"
#include <iostream>
Test::Test()
{
std::cout << "in Test()" << std::endl;
}
Test::~Test()
{
}
void Test::Func1()
{
std::cout << "in Func1" << std::endl;
Func2();
Func3();
}
void Test::Func2()
{
std::cout << "in Func2" << std::endl;
}
void Test::Func3()
{
std::cout << "in Func3" << std::endl;
}