diff --git a/inst/private/doctest_collect.m b/inst/private/doctest_collect.m index 368230d..0716786 100644 --- a/inst/private/doctest_collect.m +++ b/inst/private/doctest_collect.m @@ -134,7 +134,8 @@ target.name = what; target.link = ''; target.depth = depth; - [target.docstring, target.error] = parse_texinfo(fileread(what)); + [target.docstring, target.error, target.isdiary] = parse_texinfo(fileread(what)); + target.istexinfo = true; targets = [target]; else target = struct(); @@ -169,6 +170,9 @@ continue; end + % non-configurable pseudo-directives: set based on the target + directives = doctest_default_directives(directives, 'IS_TEXINFO', target.istexinfo); + directives = doctest_default_directives(directives, 'IS_DIARY', target.isdiary); % run doctest results = doctest_run(target.docstring, directives); @@ -224,7 +228,8 @@ else target.link = sprintf('%s', which(what), what); end - [target.docstring, target.error] = extract_docstring(target.name); + [target.docstring, target.error, target.istexinfo, target.isdiary] = ... + extract_docstring(target.name); end @@ -243,7 +248,8 @@ target.link = sprintf('%s', which(what), what); end target.depth = depth; - [target.docstring, target.error] = extract_docstring(target.name); + [target.docstring, target.error, target.istexinfo, target.isdiary] = ... + extract_docstring(target.name); targets = target; % Next, add targets for all class methods @@ -258,17 +264,21 @@ target.link = sprintf('%s', which(what), meths{i}, target.name); end target.depth = depth; - [target.docstring, target.error] = extract_docstring(target.name); + [target.docstring, target.error, target.istexinfo, target.isdiary] = ... + extract_docstring(target.name); targets = [targets; target]; end end -function [docstring, error] = extract_docstring(name) +function [docstring, error, istexinfo, isdiary] = extract_docstring(name) + istexinfo = false; + isdiary = true; if is_octave() [docstring, format] = get_help_text(name); if strcmp(format, 'texinfo') - [docstring, error] = parse_texinfo(docstring); + [docstring, error, isdiary] = parse_texinfo(docstring); + istexinfo = true; elseif strcmp(format, 'plain text') error = ''; elseif strcmp(format, 'Not documented') @@ -295,9 +305,11 @@ end -function [docstring, error] = parse_texinfo(str) +function [docstring, error, isdiary] = parse_texinfo(str) docstring = ''; error = ''; + % texinfo could have diary-style, and that might be useful to know + isdiary = false; % no example blocks? not an error, but nothing to do if (isempty(strfind(str, '@example'))) @@ -390,6 +402,7 @@ L = strsplit (T{i}, '\n'); L = regexprep (L, '^(\s*)(?:⇒|=>|⊣|-\|)', '$1', 'once', 'lineanchors'); T{i} = strjoin (L, '\n'); + isdiary = true; continue end diff --git a/inst/private/doctest_default_directives.m b/inst/private/doctest_default_directives.m index 5891b9a..09f50a7 100644 --- a/inst/private/doctest_default_directives.m +++ b/inst/private/doctest_default_directives.m @@ -8,6 +8,10 @@ defaults.normalize_whitespace = true; defaults.ellipsis = true; + % pseudo-directives: will be detected per target + defaults.is_texinfo = []; + defaults.is_diary = []; + if (nargin == 0) d = defaults; @@ -29,6 +33,10 @@ d.ellipsis = enable; case 'NORMALIZE_WHITESPACE' d.normalize_whitespace = enable; + case 'IS_TEXINFO' + d.is_texinfo = enable; + case 'IS_DIARY' + d.is_diary = enable; otherwise error('invalid directive "%s"', directive) end diff --git a/inst/private/doctest_run.m b/inst/private/doctest_run.m index a8201e8..ce5982d 100644 --- a/inst/private/doctest_run.m +++ b/inst/private/doctest_run.m @@ -44,6 +44,8 @@ % set default options tests(i).normalize_whitespace = defaults.normalize_whitespace; tests(i).ellipsis = defaults.ellipsis; + tests(i).is_texinfo = defaults.is_texinfo; + tests(i).is_diary = defaults.is_diary; tests(i).skip = {}; tests(i).xfail = {};