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

조회 수: 15 (최근 30일)
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.

답변 (2개)

Rich006
Rich006 2024년 6월 19일
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
Ernst van der Pols
Ernst van der Pols 2024년 7월 5일
편집: Ernst van der Pols 2024년 7월 5일
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.

댓글을 달려면 로그인하십시오.


Himanshu
Himanshu 2023년 11월 21일
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
Rich006
Rich006 2023년 11월 27일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by