Why do I get a warning that the code coverage result is empty because the file is invalid?

15 views (last 30 days)
I'm trying to add code coverage to my unit test suite. There is one .mlapp file that gives this warning:
Warning: Coverage result is empty for /MyPath/myApp.mlapp because the file is invalid.
How can I find out what is wrong with the file? The app works, so I don't know why it would be "invalid." Note: a blank .mlapp file does not give the same warning.

Answers (2)

Rich006
Rich006 on 19 Jun 2024
After much troubleshooting, I was able to avoid this warning by making sure all files in my directory were free of syntax errors.
It seems that this warning is to tell you that the file couldn't be checked for code coverage because it contains syntax errors. In my case the wrong file name was reported due to an apparent bug in Matlab.
By clicking the link in the warning output, and inserting a breakpoint in createFromCodeCoverageCollectorData, I found that the file name that is reported in the warning is not actually the file name that is invalid. The actual invalid file has a syntax error, so that its code can't be checked. But the warning refers to a different file name. I'm not sure why the invalid file was even being checked, because it's not called by the test runner or any classes/functions being tested. But it is in the same directory with files that are being tested.
In my case, the invalid file was element 8 in codeCovDataObjImpls, but was item 7 in staticData. Further investigation revealed that I would not have this problem if I didn't have a .mlapp file in the directory. The .mlapp file appears in codeCovDataObjImpls but not in staticData. All files after this one have mismatched indices, which is why the wrong file name appears in the warning message.
The bottom line is this: if you have an invalid file in the directory with files being checked for code coverage, you'll get this warning. If you also have a .mlapp file in the same folder, then the wrong file name may appear in the warning statement.
  1 Comment
Ernst van der Pols
Ernst van der Pols on 5 Jul 2024
Edited: Ernst van der Pols on 5 Jul 2024
I encountered the same problem: a warning with the wrong filename in case of an invalid m-file in the folder that is part of the CodeCoverage.
BUG:
In createFromCodeCoverageCollectorData.m (R2023b) line 21 the filename argument of the warning message for the FAILED files(1) is now staticData{ii}.fileName while it should be files(1).path. (disclamer: seems the logic fix based on my situation).
WORKAROUND:
Put a breakpoint on line 20 in createFromCodeCoverageCollectorData.m and inspect files(1).path of files(1).shortPath to identify the failed file.

Sign in to comment.


Himanshu
Himanshu on 21 Nov 2023
Hey,
I understand that you are trying to add code coverage to a unit test suite.
Please note that producing code coverage reports is not supported with MATLAB Compiler. Since App Designer uses the MATLAB Compiler, producing code coverage reports gives you a warning.
Hope this helps!
  1 Comment
Rich006
Rich006 on 27 Nov 2023
I don't see how that can be the case. The file validation function in CodeCoveragePlugin.m requires the filename to end with .m, .mlx, or .mlapp. Starting with line 401:
function validateFile(files)
import matlab.unittest.internal.mustBeTextScalarOrTextArray;
import matlab.unittest.internal.fileResolver;
mustBeTextScalarOrTextArray(files,'file');
mustBeNonempty(files);
for file = reshape(string(files),1,[])
if ~endsWith(fileResolver(file),[".m",".mlx",".mlapp"])
error(message('MATLAB:unittest:CodeCoveragePlugin:InvalidFileType',file));
end
end
end
Also, as I stated in my question, a blank .mlapp file does not give the same warning.

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!