forked from UniprJRC/FSDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunAllMyTestsJenkins.m
136 lines (108 loc) · 4.47 KB
/
runAllMyTestsJenkins.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%% Load necessary elements for performance test
% load OUT
run addFSDA2path
FileName='addFSDA2path';
FullPath=which(FileName);
%Navigate to the main folder of FSDA
FSDAroot=fileparts(FullPath);
cd(FSDAroot)
% Specify subfolders of main folders for which contents file has to be
% created
InclDir={'graphics' 'regression' 'multivariate' 'clustering' 'combinatorial' ...
'examples' 'utilities' 'utilities_stat' 'utilities_help'};
ExclDir={'privateFS' 'datasets'};
% Create list of folders which must have the personalized contents file
list = findDir(FSDAroot,'InclDir',InclDir,'ExclDir',ExclDir);
% Create personalized contents file for main folder of FSDA
% and required subfolders.
force=false;
warning('off')
[FilesIncluded,FilesExcluded]=makecontentsfileFS('dirpath',list,'FilterFileContent','%FScategory:','force',force,'printOutputCell','Contents.m');
[filesWithProblems,OUT]=publishFSallFiles(FilesIncluded, 'evalCode','false',...
'write2file',false,'ErrWrngSeeAlso',false,'msg',false);
selectTests=1:size(FilesIncluded,1);
FilesIncluded=FilesIncluded(selectTests,:);
OUT=OUT(selectTests);
FilesIncludedAll= FilesIncluded;
warning('on')
disp(filesWithProblems)
ij=1;
nfiles=length(OUT);
sz=[5000, 7];
varnames={'FileName' 'Category', 'Identifier' 'MeanTime' 'MedianTime' 'Code' 'TestActivity'};
% TotSummary = table('Size',sz,'VariableTypes',{'cellstr' 'cellstr' 'cellstr' 'double' 'double' 'cellstr' 'cellstr'},...
% 'VariableNames',varnames);
% TotSummary = array2table(zeros(sz),'VariableNames',varnames);
% [tmp]=publishFS('existFS', 'evalCode','false',...
% 'write2file',false,'ErrWrngSeeAlso',false);
% disp(tmp)
%% Performance and Testing part
% make sure to be in the FSDAroot
cd(FSDAroot)
% Use perf = true if for each example you want run runperf.m
% Use perf = true if for each example you want run runtests.m
perf = false;
testpath= 'tests-Jenkins';
mkdir(testpath);
for i=1:nfiles
% disp(['Filename ' FilesIncluded{i,1}])
disp(['File ' FilesIncluded{i,1} ' Number ' num2str(i) ' of ' num2str(nfiles)])
Ex=OUT{i,1}.Ex;
Extra=OUT{i,1}.ExtraEx;
Excomb=[Ex;Extra];
for iEx=1:size(Excomb,1)
disp(['Writing to file example number ' num2str(iEx) ' of ' num2str(size(Excomb,1)) ' contained in file: ' FilesIncluded{i,1}]);
close all
Exi=Excomb{iEx,3};
if ~isempty(Exi) && isempty(strfind(Excomb{iEx,1},'Interactive example'))
Exi=regexprep(Exi,'<','<');
Exi=regexprep(Exi,'>','>');
close all
if iEx==1
%Exif=[Exi,newline,'close all',newline 'save tempfileWS'];
Exif=[Exi,newline,'close all'];
else
%Exif=['load tempfileWS',newline,Exi,newline,'close all',newline, 'save tempfileWS'];
Exif=[Exi,newline,'close all'];
end
% Write Exif to a file which name begins with 'text'
filename2open=[testpath '/test' FilesIncluded{i,1}(1:end-2) '_' num2str(iEx) ...
'of' num2str(size(Excomb,1)) FilesIncluded{i,1}(end-1:end)];
file1ID=fopen(filename2open,'w');
%file1ID=fopen('tempfile.m','w');
fprintf(file1ID,'%s',Exif);
fclose('all');
else
disp('Interactive example')
end
end
% disp(['Error on the following function: (fx .num:)' int2str(i)])
% OUT{i,1}.titl;
end
cat2test='Jenkins';
cd(testpath);
import matlab.unittest.plugins.CodeCoveragePlugin;
% Clear last warning
lastwarn('');
warn1 = lastwarn;
suite = testsuite(pwd);
warn2 = lastwarn;
if ~strcmp(warn1, warn2)
disp(warn2)
error('FSDA:runAllMyTestsFS:WrongExample','A warning occurred during test suite creation!')
end
% Create a TestRunner
runner = matlab.unittest.TestRunner.withTextOutput();
% Add a plugin to produce a JUnit-style test report
runner.addPlugin(matlab.unittest.plugins.XMLPlugin.producingJUnitFormat(['test-' cat2test '-report.xml']));
% Get file paths of source code being tested
filePaths = fullfile(FilesIncluded(:,9), FilesIncluded(:,1));
if ~verLessThanFS('9.2') % >2016b
% Indicate where the Cobertura coverage report should be created
covFile = matlab.unittest.plugins.codecoverage.CoberturaFormat(['coverage-' cat2test '-report.xml']);
% Add the CodeCoveragePlugin
runner.addPlugin(matlab.unittest.plugins.CodeCoveragePlugin.forFile(filePaths, 'Producing', covFile));
end
% Run the test suite
disp('Run the test suite')
runner.run(suite);