FAQ

How to specify argument for my program?

if you run the following command you will have a parsing error: unrecognised option '--arg1'.

OpenCppCoverage.exe --sources C:\Dev\MyProject YourProgram.exe --arg1

The parser need a way to know that --arg1 is a flag of YourProgram.exe and not for OpenCppCoverage.exe. You need to add ‘--‘ before your executable name in the same way as many Unix command does.

OpenCppCoverage.exe --sources C:\Dev\MyProject -- YourProgram.exe --arg1

I cannot see my module in the code coverage report.

When running OpenCppCoverage, it starts by displaying information about why a module is selected or not. For example you can have:

[info] Module: C:\Dev\MyProject\YourProgram.exe is selected because it matches selected pattern: MyProject

Or

[info] Module: C:\Dev\MyProject\YourProgram.exe is not selected because it matches excluded pattern: MyProject

If your module is not selected, check the value of --modules and --excluded_modules.

I cannot see my file in the code coverage report.

You can use --verbose flag as command line to show why a file is selected or not:

[debug] Filename: C:\Dev\MyProject\main.cpp is skipped because it matches no selected patterns

The output is also written in file LastCoverageResults.log. It contains also information about the location of program data files used.

You can also check that your program database files are up-to-date by adding a breakpoint inside the file and try to debug.

Is Windows XP supported?

Windows XP is currently not supported.

Why there is an uncovered line at the end of my class declaration with Visual Studio 2013?

You can have an uncovered line at the end of the class like in following code:

LastLine

You will have this behavior if your class have all the following requirements:

  • At least one default method
  • Is exported with __declspec(dllexport)
  • Has only basic types (int, bool) but no std::string, std::vector or any user class.

Even if you call the methods marked with = default, this line will be remained uncovered.

This is not a bug because there is code generated for the method marked with = default that is never called.

To avoid this problem you can see here or do the following things:

  • Remove = default from the method declaration (in the header)
  • Implement your method with = default in your source file (in .cpp)

For example, for a default copy constructor of the class MyClass, you should define in your source file (.cpp)

MyClass::MyClass(const MyClass&) = default;

Coverage and throw

Consider the following output of OpenCppCoverage:

throw

Each line is executed, but line 14 is marked as uncovered.

As foo has a destructor, the compiler adds a call to the destructor at the end of the scope. Of course, it will never be called because of the exception.

If you have an object with a destructor in the same scope as a throw, you will have this issue. You also have this case, if you declare a local variable of type std::exception before throwing.

You can see here or add a new scope around your variable like in the following code:

thorwWithScope

Network path special considerations

Consider a Visual Studio project shared at \\YOUR-COMPUTER\Shared\ConsoleApplication and Z:\ConsoleApplication (Z: is a network drive that maps \\YOUR-COMPUTER\Shared).

The following methods for running the program are equivalent:

Method 1: OpenCppCoverage --sources ConsoleApplication -- Z:\ConsoleApplication\Debug\ConsoleApplication.exe
Method 2: OpenCppCoverage --sources ConsoleApplication -- \\YOUR-COMPUTER\Shared\ConsoleApplication\Debug\ConsoleApplication.exe

For module filtering (--modules and --excluded_modules), you need to always use the network style that is \\YOUR-COMPUTER\Shared\ConsoleApplication.

For source filtering (--sources and --excluded_sources), thing are little more complex because it depends on how the project was compiled and not how the program is run:

  • If you open Visual Studio solution using Z:\ConsoleApplication\ConsoleApplication.sln and then compile, you should use Z:\ConsoleApplication style for filtering.
  • If you open instead \\YOUR-COMPUTER\Shared\ConsoleApplication\ConsoleApplication.sln and then compile, you should use \\YOUR-COMPUTER\Shared\ConsoleApplication style for filtering.

It is highly recommended to run OpenCppCoverage in verbose mode when settings filters.

How do I customize the HTML report?

The HTML report is generated using HTML template files located in "Template" folder inside OpenCppCoverage installation folder.

During the report generation, OpenCppCoverage replaces tags like {{TITLE}} by the proper value.

There are two kinds of template:

  • MainTemplate.html: template for index.html and for all HTML files located in "Module" folder.
  • SourceTemplate.html: template for all source files.

The syntax highlighting is performed by the library code-pretiffy. The getting started page explains how to configure it.

If you want to change the color of the comment for example, you can update the theme defined in prettify-CppCoverage.css located in Template\third-party\google-code-prettify. prettify-CppCoverage.css is a minified version of the default theme and you can find examples of theme here.

"else" or "}" is not marked as covered

OpenCppCoverage uses PDB content to detect which line need a coverage.

int foo(bool v)
{
	if (v)
		return 0;
	else
		return 1;
}

int main(int argc, char** argv)
{
	foo(true);
	foo(false);
	return 0;
}

In the previous example, the line containing "else" will never be executed and OpenCppCoverage will report it as not covered.
This is because Visual Studio generates an instruction for "else". Indeed, generated code are not the same with and without "else".
You can have a similar issue with “throw” (see here for more detail) and for a closing parenthesis (see here for more detail).

To solve this problem, you can use --excluded_line_regex "\s*else.*" and --excluded_line_regex "\s*{.*" to exclude respectively "else" or "{".
You can also introduce a special comment like // @NOCOVERAGE and use --excluded_line_regex ".*@NOCOVERAGE.*".

Last edited Mar 5 at 5:08 PM by OpenCppCoverage, version 9