Skip to content

Commit 3c8c6e2

Browse files
Fix callSiteInfo stack matching in MATLAB (dbstack basenames)
1 parent 04b2b2d commit 3c8c6e2

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎plotly/testing/PlotlyTestCase.m‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,26 @@ function verifyLessThan(testCase, value, ceiling, varargin)
172172

173173
methods (Access = private)
174174
function info = callSiteInfo(testCase)
175-
%-the first stack frame outside this class file: the
176-
%-assertion's location in the test file-%
175+
% the first stack frame outside this class file: the
176+
% assertion's location in the test file
177177
info = '';
178178
st = dbstack;
179-
thisFile = [mfilename('fullpath') '.m'];
179+
% MATLAB's dbstack reports file names without their
180+
% directory (Octave reports full paths); compare
181+
% basenames so the same file matches in both engines
182+
[~, base, ext] = fileparts(mfilename('fullpath'));
183+
thisFile = [base ext '.m'];
180184
for i = 2:numel(st)
181-
if ~isempty(st(i).file) && ~strcmp(st(i).file, thisFile)
182-
info = sprintf('\n at %s:%d', st(i).file, st(i).line);
183-
line = PlotlyTestCase.readSourceLine(st(i).file, st(i).line);
184-
if ~isempty(line)
185-
info = sprintf('%s\n %s', info, strtrim(line));
185+
if ~isempty(st(i).file)
186+
[~, fBase, fExt] = fileparts(st(i).file);
187+
if ~strcmp([fBase fExt], thisFile)
188+
info = sprintf('\n at %s:%d', st(i).file, st(i).line);
189+
line = PlotlyTestCase.readSourceLine(st(i).file, st(i).line);
190+
if ~isempty(line)
191+
info = sprintf('%s\n %s', info, strtrim(line));
192+
end
193+
return;
186194
end
187-
return;
188195
end
189196
end
190197
end

0 commit comments

Comments
 (0)