Skip to content

Commit 6c9a626

Browse files
committed
Formating
1 parent e9a3bbe commit 6c9a626

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

verifyFunctionWarning.m

+37-29
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
% warningMessage: The specific warning message that need to be tested
1111
%
1212
% OUPUTS:
13-
% success: Verify if the function throws the provided warning message and catch it in tline
13+
% success: Boolean indicating whether the warning message is thrown
1414
%
1515
% EXAMPLE:
1616
% % Test whether PaCER function throws the provided warning message:
17-
% assert(verifyFunctionWarning('PaCER', warningMessage, 'inputs', {niiCT}));
17+
% verifyFunctionWarning('PaCER', warningMessage, 'inputs', {niiCT});
1818
%
1919
% AUTORS:
2020
% Laurent Heirendt, April 2019
@@ -25,51 +25,59 @@
2525
% https://github.com/opencobra/cobratoolbox/blob/master/test/verifyCobraFunctionError.m
2626
% [5aa9ccd]
2727

28-
parser = inputParser();
29-
parser.addRequired('functionCall', @ischar)
30-
parser.addRequired('warningMessage', @ischar)
31-
parser.addParamValue('inputs', {}, @iscell)
32-
parser.addParamValue('outputArgCount', 0, @(x) isnumeric(x) && mod(x,1) == 0);
33-
parser.parse(functionCall, warningMessage, varargin{:});
34-
outputArgcount = parser.Results.outputArgCount;
35-
inputs = parser.Results.inputs;
36-
functionCall = str2func(functionCall);
37-
% initialize the test
38-
success = false;
39-
% create an hidden file
40-
logFile = '.testCatch.log';
41-
% run the function in diary mode
42-
diary(logFile);
43-
try
44-
if outputArgcount > 0
45-
outArgs = cell(outputArgcount, 1);
46-
[outArgs{:}] = functionCall(inputs{:});
47-
else
48-
functionCall(inputs{:});
28+
parser = inputParser();
29+
parser.addRequired('functionCall', @ischar)
30+
parser.addRequired('warningMessage', @ischar)
31+
parser.addParamValue('inputs', {}, @iscell)
32+
parser.addParamValue('outputArgCount', 0, @(x) isnumeric(x) && mod(x,1) == 0);
33+
parser.parse(functionCall, warningMessage, varargin{:});
34+
outputArgcount = parser.Results.outputArgCount;
35+
36+
inputs = parser.Results.inputs;
37+
functionCall = str2func(functionCall);
38+
39+
% initialize the test
40+
success = false;
41+
42+
% create an hidden file
43+
logFile = '.testCatch.log';
44+
45+
% run the function in diary mode
46+
diary(logFile);
47+
try
48+
if outputArgcount > 0
49+
outArgs = cell(outputArgcount, 1);
50+
[outArgs{:}] = functionCall(inputs{:});
51+
else
52+
functionCall(inputs{:});
53+
end
4954
end
50-
end
5155
diary off
52-
% loop through the temporary diary file
56+
57+
% loop through the temporary diary file
5358
fid = fopen(logFile);
5459
tline = fgetl(fid);
5560
counter = 0;
56-
% Read the code until it reaches the end of the script
61+
62+
% read the code until it reaches the end of the script
5763
while ~feof(fid)
58-
% Setup the function to read the script three lines by three lines. If a
59-
% warning message is found in these three lines, this message will be
60-
% concatenated in tline. If not, tline will be empty.
64+
% setup the function to read the script three lines by three lines.
6165
tline = [tline ' ' fgetl(fid)];
6266
if ~isempty(tline) && contains(tline, warningMessage)
6367
success = true;
6468
break;
6569
end
70+
71+
% if a warning message is found in consecutive three lines, this message will be
72+
% concatenated in tline. If not, tline will be reset.
6673
if counter > 3
6774
tline = '';
6875
counter = 0;
6976
end
7077
counter = counter + 1;
7178
end
7279
fclose(fid);
80+
7381
% remove the temporary diary file
7482
delete(logFile);
7583
end

0 commit comments

Comments
 (0)