0001
0002
0003
0004
0005 import matlab.unittest.TestSuite
0006 import matlab.unittest.TestRunner
0007 import matlab.unittest.selectors.HasTag
0008 import matlab.unittest.plugins.CodeCoveragePlugin
0009 import edu.stanford.covert.test.Coverage
0010
0011
0012 fprintf('Running from dir:%s\n',pwd);
0013 [~,ws] = system('echo $WORKSPACE');
0014 ws = strtrim(ws);
0015 fprintf('Workspace:%s\n',ws);
0016
0017
0018 fprintf('Fixing paths.\n');
0019 rmPathVar('ds');
0020 addpath(genpath(ws));
0021
0022
0023 dsMakeDefaultConfigJenkins;
0024
0025
0026 finalDir = fullfile(dsGetConfig('ds_unitTestData_path'), 'autogen');
0027 if ~exist(finalDir, 'dir')
0028 newDir = fullfile(dsGetConfig('ds_unitTestData_path'), 'autogen_newSave');
0029 movefile(newDir, finalDir);
0030 end
0031
0032
0033 finalDir = fullfile(dsGetConfig('ds_unitTestData_path'), 'autogenDirs');
0034 newDir = fullfile(dsGetConfig('ds_unitTestData_path'), 'autogenDirs_newSave');
0035 if ~exist(finalDir, 'dir') && exist(newDir, 'dir')
0036 movefile(newDir, finalDir);
0037 end
0038
0039
0040 fullSuite = TestSuite.fromPackage('dsUnit');
0041 fullSuite = fullSuite.selectIf(~HasTag('query'));
0042 fullSuite = fullSuite.selectIf(HasTag('autogen'));
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 runner = matlab.unittest.TestRunner.withTextOutput;
0055 try
0056 results = runInParallel(runner,fullSuite);
0057 display(results);
0058
0059
0060 testCoverageDir = fullfile(ws, 'testCoverage');
0061 mkdirSilent(testCoverageDir);
0062 reportPath = fullfile(testCoverageDir, 'dsAllAutogenTestCoverageJenkins.xml');
0063 report = Coverage( fullfile(ws, 'functions'), ws );
0064 report.exportXML(reportPath);
0065
0066
0067 coverPercent = report.stats.lineRate;
0068 if isnan(coverPercent)
0069 coverPercent = 0;
0070 end
0071 coverPercentStr = sprintf('%.f', coverPercent);
0072 fprintf('Test Coverage (%% of code lines): %s\n', coverPercentStr);
0073
0074
0075 filepath = dsGetConfig('ds_jenkins_badge_path');
0076 system(['python ' dsGetConfig('ds_universal_coverage_badge_py_path') ' ' coverPercentStr ' -o ' filePath ' -f True']);
0077 catch e
0078 disp(getReport(e,'extended'))
0079 exit(1);
0080 end
0081
0082 exit(any([results.Failed]));