-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_all_tests.m
131 lines (106 loc) · 3.75 KB
/
run_all_tests.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
%% Generate report on all tests for the metas unclib matlab wrapper
%
% This scripts runs all tests that match the pattern "tests/test_*" and
% generates an excel file results in the folder reports detailing the test
% results.
%
% 2021-08-06 [email protected]
% Created Script
%% Config
clear;
clc;
% Test results to also print in the comand line
commandline_output = {...
'failed', ...
'warning', ...
% 'accepted', ...
% 'passed' ...
};
testFolder = 'tests';
testPrefix = 'test_';
%% Setting Up Variables
result_types = {'failed', 'warning', 'accepted', 'passed'};
[currentPath,currentScript,~] = fileparts(mfilename('fullpath'));
cd(currentPath);
files = dir(testFolder);
addpath('.');
cd(testFolder);
uncTypes = {@LinProp, @DistProp, @MCProp};
global automatedUnc;
global testReport;
global automatedTestScript;
global automatedOutput;
global warningOnDifferentErrorMessages;
warningOnDifferentErrorMessages = false;
% automatedTestScript is used to detect in the testing functions, if they
% are executed as part of an automated test. Simply setting a global
% true/false flag might procued unexcepted results if the script crashes.
automatedTestScript = currentScript;
automatedOutput = commandline_output;
testReport = struct();
for ii = 1:length(result_types)
testReport.(result_types{ii}) = table([], [], [], [], [], [], 'VariableNames', {'Script', 'Line', 'Test', 'UncType', 'Result', 'Message'});
end
%% Running the tests
for tt = 1:numel(uncTypes)
automatedUnc = uncTypes{tt};
fprintf('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nTesting %s\n', char(uncTypes{tt}));
for ii = 1:numel(files)
if ~startsWith(files(ii).name, testPrefix) || ~endsWith(files(ii).name, '.m')
continue;
end
fprintf('File %s\n', files(ii).name);
eval(files(ii).name(1:end-2));
end
end
%% Cleanup
cd('..');
v=ver('matlab');
filename = sprintf('reports/%s-test-report-MATLAB-%s.xlsx', datestr(now,'yyyy-mm-dd'), v.Release(2:end-1));
%% Prepare Report
if verLessThan('matlab', '9.8')
summary = readtable('report_template.xlsx', 'ReadVariableNames',false);
else
summary = readtable('report_template.xlsx', 'ReadVariableNames',false,'Format','auto');
end
summary.Var2 = string(summary.Var2);
summary{1, 2} = string(v.Release(2:end-1));
summary{2, 2} = string(datestr(now,'yyyy-mm-dd'));
summary{3, 2} = string(datestr(now,'hh:MM'));
summary{5, 2} = height(testReport.failed);
summary{6, 2} = height(testReport.warning);
summary{7, 2} = height(testReport.accepted);
summary{8, 2} = height(testReport.passed);
% for ii = 1:length(result_types)
% testReport.(result_types{ii}) = sortrows(testReport.(result_types{ii}), [1 2]);
% end
%% Write Report
tryWrite = true;
writeSuccess = false;
while tryWrite
try
copyfile('report_template.xlsx', filename);
warning('off','MATLAB:xlswrite:AddSheet'); %optional
writetable(summary,filename,'Sheet','Summary', 'WriteVariableNames', false);
writetable(testReport.failed,filename,'Sheet','Failed Tests');
writetable(testReport.warning,filename,'Sheet','Warnings');
writetable(testReport.accepted,filename,'Sheet','Accepted Differences');
writetable(testReport.passed,filename,'Sheet','Passed Tests');
tryWrite = false;
writeSuccess = true;
catch
opts.Interpreter = 'none';
opts.Default = 'Retry';
quest = 'Could not write error report.';
answer = questdlg(quest,'File access error',...
'Retry','Cancel',opts);
if ~strcmp(answer, 'Retry')
tryWrite = false;
end
end
end
if writeSuccess
try %#ok<TRYNC> % Will throw an error, if the excel is not installed.
winopen(filename);
end
end