From 3fa5777f7166097dc290313884ee5db274d9e0b6 Mon Sep 17 00:00:00 2001 From: "Colin B. Macdonald" Date: Thu, 4 Jan 2018 11:34:49 -0800 Subject: [PATCH] workaround arm-specific regexprep bug This fixes #130. Again. To workaround, we avoid using regexprep and instead get the tokens with regexp and do the substitution ourselves. Leave the regexprep code commented out with a link to the newly-submitted upstream bug. This can be undone once a fix lands upstream. Prep for a new release with a minor version bump. --- DESCRIPTION | 4 +-- NEWS | 7 ++++++ inst/doctest.m | 2 +- inst/private/doctest_collect.m | 45 +++++++++++++++++++++++++--------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cb1b6d7..60ac853 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Name: doctest -Version: 0.6.0 -Date: 2017-12-25 +Version: 0.6.1 +Date: 2018-01-04 Author: various authors Maintainer: Colin B. Macdonald , Michael Walter Title: Documentation tests diff --git a/NEWS b/NEWS index 5e108f0..7b5a587 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +doctest 0.6.1 (2018-01-04) +========================== + + * Workaround regex bug on ARM (again!). + + + doctest 0.6.0 (2017-12-25) ========================== diff --git a/inst/doctest.m b/inst/doctest.m index 116467c..414a0b7 100644 --- a/inst/doctest.m +++ b/inst/doctest.m @@ -273,7 +273,7 @@ [color_ok, color_err, color_warn, reset] = doctest_colors(fid); % print banner -fprintf(fid, 'Doctest v0.6.0: this is Free Software without warranty, see source.\n\n'); +fprintf(fid, 'Doctest v0.6.1: this is Free Software without warranty, see source.\n\n'); summary = struct(); diff --git a/inst/private/doctest_collect.m b/inst/private/doctest_collect.m index 7b029e5..43d8ebb 100644 --- a/inst/private/doctest_collect.m +++ b/inst/private/doctest_collect.m @@ -338,17 +338,40 @@ % Mark the occurrence of “@example” and “@end example” to be able to find % example blocks after conversion from texi to plain text. Also consider % indentation, so we can later correctly unindent the example's content. - % Note: uses “@example” instead of “$2” to avoid ARM-specific bug #130. - str = regexprep (str, ... - '^([ \t]*)(\@example)(.*)$', ... - [ '$1\@example$3\n', ... % retain original line - '$1###### EXAMPLE START ######'], ... - 'lineanchors', 'dotexceptnewline', 'emptymatch'); - str = regexprep (str, ... - '^([ \t]*)(\@end example)(.*)$', ... - [ '$1###### EXAMPLE STOP ######\n', ... - '$1\@end example$3'], ... % retain original line - 'lineanchors', 'dotexceptnewline', 'emptymatch'); + + % These should work, but I keep hitting ARM-specific when $1 is empty: + % https://savannah.gnu.org/bugs/index.php?52810 + %str = regexprep (str, ... + % '^([ \t]*)(\@example)(.*)$', ... + % [ '$1$2$3\n', ... % retain original line + % '$1###### EXAMPLE START ######'], ... + % 'lineanchors', 'dotexceptnewline', 'emptymatch'); + %str = regexprep (str, ... + % '^([ \t]*)(\@end example)(.*)$', ... + % [ '$1###### EXAMPLE STOP ######\n', ... + % '$1$2$3'], ... % retain original line + % 'lineanchors', 'dotexceptnewline', 'emptymatch'); + + % Instead we do it manually + [S, E, TE, M, T, NM, SP] = regexp (str, '^([ \t]*)(\@example)(.*)$', ... + 'lineanchors', 'dotexceptnewline', 'emptymatch'); + str = SP{1}; + for i=1:length (T) + str = [str ... + T{i}{:} sprintf('\n') ... % retain original line + T{i}{1} '###### EXAMPLE START ######' ... + SP{i+1}]; + end + + [S, E, TE, M, T, NM, SP] = regexp (str, '^([ \t]*)(\@end example)(.*)$', ... + 'lineanchors', 'dotexceptnewline', 'emptymatch'); + str = SP{1}; + for i=1:length (T) + str = [str ... + T{i}{1} '###### EXAMPLE STOP ######' sprintf('\n') ... + T{i}{:} ... % retain original line + SP{i+1}]; + end % special comments "@c doctest: cmd" are translated % FIXME the expression would also match @@c doctest: ...