0001
0002
0003
0004 import matlab.unittest.TestSuite
0005 import matlab.unittest.TestRunner
0006 import matlab.unittest.selectors.HasTag
0007 import matlab.unittest.plugins.CodeCoveragePlugin
0008 import edu.stanford.covert.test.Coverage
0009
0010
0011 fprintf('Running from dir:%s\n',pwd);
0012 [~,ws] = system('echo $WORKSPACE');
0013 ws = strtrim(ws);
0014 fprintf('Workspace:%s\n',ws);
0015
0016
0017 fprintf('Fixing paths.\n');
0018 rmPathVar('ds');
0019 addpath(genpath(ws));
0020
0021
0022 dsMakeDefaultConfigJenkins;
0023
0024
0025 fullSuite = TestSuite.fromPackage('dsUnit');
0026 fullSuite = fullSuite.selectIf(~HasTag('query'));
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 runner = matlab.unittest.TestRunner.withTextOutput;
0039 try
0040 results = runInParallel(runner,fullSuite);
0041 display(results);
0042
0043
0044 testCoverageDir = fullfile(ws, 'testCoverage');
0045 mkdirSilent(testCoverageDir)
0046 reportPath = fullfile(testCoverageDir, 'dsAllTestCoverageJenkins.xml');
0047 report = Coverage( fullfile(ws, 'functions'), ws );
0048 report.exportXML(reportPath);
0049
0050
0051 coverPercent = report.stats.lineRate;
0052 if isnan(coverPercent)
0053 coverPercent = 0;
0054 end
0055 coverPercentStr = sprintf('%.f', coverPercent);
0056 fprintf('Test Coverage (%% of code lines): %s\n', coverPercentStr);
0057
0058
0059 filePath = '/home/erik/Dropbox/research/dsJenkinsBadge/coverage.svg';
0060 system(['python /home/erik/Dropbox/Programming/Python/universal_coverage_badge/__main__.py -percent ' coverPercentStr ' -o ' filePath ' -f True']);
0061 catch e
0062 disp(getReport(e,'extended'))
0063 exit(1);
0064 end
0065
0066 exit(any([results.Failed]));