Skip to content

Commit 58d89d6

Browse files
authored
Merge pull request #179 from catch22/dot_finds_oct_files
Find tests in .oct files
2 parents ee81ea5 + 7b13b8e commit 58d89d6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

inst/doctest.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% Copyright (c) 2010 Thomas Grenfell Smith
22
%% Copyright (c) 2011, 2013-2016 Michael Walter
3-
%% Copyright (c) 2015-2017 Colin B. Macdonald
3+
%% Copyright (c) 2015-2019 Colin B. Macdonald
44
%%
55
%% Redistribution and use in source and binary forms, with or without
66
%% modification, are permitted provided that the following conditions are met:
@@ -41,6 +41,7 @@
4141
%% @item function;
4242
%% @item class;
4343
%% @item Texinfo file;
44+
%% @item .oct/.mex compiled code;
4445
%% @item directory/folder (pass @code{-nonrecursive} to skip subfolders);
4546
%% @item cell array of such items.
4647
%% @end itemize

inst/private/doctest_collect.m

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
%%
1111
% Copyright (c) 2010 Thomas Grenfell Smith
1212
% Copyright (c) 2015 Michael Walter
13-
% Copyright (c) 2015-2017 Colin B. Macdonald
13+
% Copyright (c) 2015-2018 Colin B. Macdonald
1414
% Copyright (c) 2015 Oliver Heimlich
15+
% Copyright (C) 2018 Mike Miller
1516
% This is Free Software, BSD-3-Clause, see doctest.m for details.
1617

1718

@@ -24,6 +25,11 @@
2425
[~, ~, ext] = fileparts(what);
2526
if any(strcmpi(ext, {'.texinfo' '.texi' '.txi' '.tex'}))
2627
type = 'texinfo';
28+
elseif (strcmp (ext, '.oct') && exist (what) == 3) % .oct explicitly
29+
type = 'octfile';
30+
elseif (exist (what) == 3) % .oct/.mex
31+
[~, what, ~] = fileparts (what); % strip extension if present
32+
type = 'function'; % then access like any function
2733
elseif (exist(what, 'file') && ~exist(what, 'dir')) || exist(what, 'builtin');
2834
if (exist(['@' what], 'dir'))
2935
% special case, e.g., @logical is class, logical is builtin
@@ -109,7 +115,8 @@
109115
end
110116
else
111117
[~, ~, ext] = fileparts(f);
112-
if (~ any(strcmpi(ext, {'.m' '.texinfo' '.texi' '.txi' '.tex'})))
118+
if (~ any(strcmpi(ext, ...
119+
{'.m' '.texinfo' '.texi' '.txi' '.tex' '.oct' '.mex'})))
113120
%fprintf(fid, 'Debug: ignoring file "%s"\n', f)
114121
continue
115122
end
@@ -135,6 +142,8 @@
135142
targets = [target];
136143
elseif strcmp(type, 'class')
137144
targets = collect_targets_class(what, depth);
145+
elseif strcmp (type, 'octfile')
146+
targets = collect_targets_octfile (what, depth);
138147
elseif strcmp(type, 'texinfo')
139148
target = struct();
140149
target.name = what;
@@ -283,6 +292,35 @@
283292
end
284293

285294

295+
function targets = collect_targets_octfile (file, depth)
296+
% first target is the name of the octfile (w/o extension)
297+
[~, basename, ext] = fileparts (file);
298+
assert (strcmp (ext, '.oct'))
299+
target = collect_targets_function (basename);
300+
target.name = file;
301+
target.depth = depth;
302+
targets = [target];
303+
304+
% octfile may have many fcns in it: find them using the autoload map
305+
autoloadmap = autoload ();
306+
len = numel (file);
307+
% matches both "/foo/bar.oct" and "/baz/bar.oct"; uncommon in practice
308+
pmatch = @(e) (numel (e.file) >= len) && strcmp (e.file(end-len+1:end), file);
309+
idx = find (arrayfun (pmatch, autoloadmap));
310+
311+
if (~ isempty (idx))
312+
% indicate that octfile has other fcns, and indent those targets
313+
targets(1).name = [targets(1).name ':'];
314+
for i = 1:numel (idx)
315+
f = autoloadmap(idx(i)).function;
316+
target = collect_targets_function (f);
317+
target.depth = depth + 1;
318+
targets = [targets; target];
319+
end
320+
end
321+
end
322+
323+
286324
function [docstring, error] = extract_docstring(name)
287325
if is_octave()
288326
[docstring, format] = get_help_text(name);

0 commit comments

Comments
 (0)