changeset 32933:2bc78bbc3fde stable

test: Add BIST tests for classdef help (bug #65220). * test/Makefile.am: include bug-65220/module.mk into build system. * test/bug-65220/module.mk: Makefile rules for new test directory. * bug-65220.tst: BIST tests for classdef help. * cdef_help1.m, cdef_help2.m: Helper files with different classdef definitions for use with bug-65220.tst.
author Rik <rik@octave.org>
date Mon, 05 Feb 2024 14:22:06 -0800
parents ab4b7e516ff3
children b216fd94f5cc 0ad5004f85e3
files test/Makefile.am test/bug-65220/bug-65220.tst test/bug-65220/cdefdir/cdef_help1.m test/bug-65220/cdefdir/cdef_help2.m test/bug-65220/module.mk
diffstat 5 files changed, 304 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/Makefile.am	Sun Feb 04 23:21:11 2024 -0500
+++ b/test/Makefile.am	Mon Feb 05 14:22:06 2024 -0800
@@ -112,6 +112,7 @@
 include bug-61191/module.mk
 include bug-63841/module.mk
 include bug-65037/module.mk
+include bug-65220/module.mk
 include class-concat/module.mk
 include classdef/module.mk
 include classdef-debug/module.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-65220/bug-65220.tst	Mon Feb 05 14:22:06 2024 -0800
@@ -0,0 +1,110 @@
+########################################################################
+##
+## Copyright (C) 2024 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+%!test <*65220>
+%! unwind_protect
+%!   addpath ('cdefdir');
+%! 
+%!   ## Check methods first (bug was disguised if class checked first)
+%!   s = help ('cdef_help1.meth1');
+%!   assert (regexp (s, 'meth1: method help text ABOVE function'));
+%!
+%!   s = help ('cdef_help1.meth2');
+%!   assert (regexp (s, 'meth2: method help text BELOW function'));
+%!
+%!   s = help ('cdef_help1.meth3');
+%!   assert (regexp (s, 'meth3: method help text BELOW function'));
+%!
+%!   s = '';
+%!   try
+%!     s = help ('cdef_help1.meth4');
+%!   catch
+%!     assert (regexp (lasterr (), "'cdef_help1.meth4' is not documented"));
+%!   end_try_catch
+%!   if (! isempty (s))
+%!     error ("Impossible state: Help text found for 'cdef_help1.meth4'");
+%!   endif
+%!
+%!   ## Check documentation for entire class
+%!   s = help ('cdef_help1');
+%!   assert (regexp (s, 'class cdef_help1 : class help text ABOVE classdef'));
+%!   
+%!   ## Check documentation for constructor
+%!   s = help ('cdef_help1.cdef_help1');
+%!   assert (regexp (s, 'cdef_help1: constructor help text BELOW function'));
+%!   
+%!   ## Check documentation for properties
+%!   s = help ('cdef_help1.prop1');
+%!   assert (regexp (s, 'prop1: property help text ABOVE property'));
+%!
+%!   s = help ('cdef_help1.prop2');
+%!   assert (regexp (s, 'prop2: property help text in EOL-comment'));
+%!
+%! unwind_protect_cleanup
+%!   rmpath ('cdefdir');
+%! end_unwind_protect
+
+%!test <*65220>
+%! unwind_protect
+%!   addpath ('cdefdir');
+%! 
+%!   ## Check methods first (bug was disguised if class checked first)
+%!   s = help ('cdef_help2.meth1');
+%!   assert (regexp (s, 'meth1: method help text ABOVE function'));
+%!
+%!   s = help ('cdef_help2.meth2');
+%!   assert (regexp (s, 'meth2: method help text BELOW function'));
+%!
+%!   s = help ('cdef_help2.meth3');
+%!   assert (regexp (s, 'meth3: method help text ABOVE function'));
+%!
+%!   s = '';
+%!   try
+%!     s = help ('cdef_help2.meth4');
+%!   catch
+%!     assert (regexp (lasterr (), "'cdef_help2.meth4' is not documented"));
+%!   end_try_catch
+%!   if (! isempty (s))
+%!     error ("Impossible state: Help text found for 'cdef_help2.meth4'");
+%!   endif
+%!
+%!   ## Check documentation for entire class
+%!   s = help ('cdef_help2');
+%!   assert (regexp (s, 'class cdef_help2 : class help text BELOW classdef'));
+%!   
+%!   ## Check documentation for constructor
+%!   s = help ('cdef_help2.cdef_help2');
+%!   assert (regexp (s, 'cdef_help2: constructor help text ABOVE function'));
+%!   
+%!   ## Check documentation for properties
+%!   s = help ('cdef_help2.prop1');
+%!   assert (regexp (s, 'prop1: property help text ABOVE property'));
+%!
+%!   s = help ('cdef_help2.prop2');
+%!   assert (regexp (s, 'prop2: property help text in EOL-comment'));
+%!
+%! unwind_protect_cleanup
+%!   rmpath ('cdefdir');
+%! end_unwind_protect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-65220/cdefdir/cdef_help1.m	Mon Feb 05 14:22:06 2024 -0800
@@ -0,0 +1,95 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%
+%% Copyright (C) 2024 The Octave Project Developers
+%%
+%% See the file COPYRIGHT.md in the top-level directory of this
+%% distribution or <https://octave.org/copyright/>.
+%%
+%% This file is part of Octave.
+%%
+%% Octave is free software: you can redistribute it and/or modify it
+%% under the terms of the GNU General Public License as published by
+%% the Free Software Foundation, either version 3 of the License, or
+%% (at your option) any later version.
+%%
+%% Octave is distributed in the hope that it will be useful, but
+%% WITHOUT ANY WARRANTY; without even the implied warranty of
+%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%% GNU General Public License for more details.
+%%
+%% You should have received a copy of the GNU General Public License
+%% along with Octave; see the file COPYING.  If not, see
+%% <https://www.gnu.org/licenses/>.
+%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% class cdef_help1 : class help text ABOVE classdef keyword.
+%
+% Type 'help cdef_help1'
+
+classdef cdef_help1
+  % -*- texinfo -*-
+  % class cdef_help1 : class help text BELOW classdef keyword.
+  %
+  % Type 'help cdef_help1'
+
+  properties
+    % prop1: property help text ABOVE property name.
+    % Type "help cdef_help1.prop1"
+    prop1   % prop1: EOL-comment text.  Should not be displayed
+    prop2   % prop2: property help text in EOL-comment for property PROP2.  Type "help cdef_help1.prop2"
+  end
+
+  methods
+
+    % cdef_help1: constructor help text ABOVE function keyword
+    % Type 'help cdef_help1.cdef_help1'.
+    function obj = cdef_help1 (p1, p2)
+      % cdef_help1: constructor help text BELOW function keyword
+      % Type 'help cdef_help1.cdef_help1'.
+      if (nargin ~= 2)
+        obj.prop1 = 'default';
+        obj.prop2 = 42;
+      else
+        obj.prop1 = p1;
+        obj.prop2 = p2;
+      end
+    end
+
+    % meth1: method help text ABOVE function
+    % 
+    % Type 'help cdef_help1.meth1'.
+    function obj2 = meth1 (obj, n)
+      obj2 = n + obj;
+    end
+    
+    function obj2 = meth2 (obj, n)
+
+      % meth2: method help text BELOW function
+      % The blank line between function and comment is intentional.
+      % Type 'help cdef_help1.meth2'.
+      obj2 = n - obj;
+    end
+
+    % meth3: method help text ABOVE function
+    % Type 'help cdef_help1.meth3'.
+    % This should not be shown.
+    function obj3 = meth3 (obj, n)
+      % meth3: method help text BELOW function
+      % Type 'help cdef_help1.meth3'.
+      % This should be displayed.
+      obj3 = obj + n;
+    end
+
+    function obj4 = meth4 (obj, n)
+
+      obj4 = n - obj;
+      if (n)
+        % meth4: pure comment text.  This should *never* be displayed.
+        % Type 'help cdef_help1.meth4'.
+      end
+    end
+
+  end
+
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-65220/cdefdir/cdef_help2.m	Mon Feb 05 14:22:06 2024 -0800
@@ -0,0 +1,92 @@
+########################################################################
+##
+## Copyright (C) 2024 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+classdef cdef_help2
+  # -*- texinfo -*-
+  # class cdef_help2 : class help text BELOW classdef keyword.
+  #
+  # Type 'help cdef_help2'
+
+  properties
+    # prop1: property help text ABOVE property name.
+    # Type "help cdef_help2.prop1"
+    prop1   # prop1: EOL-comment text.  Should not be displayed
+    prop2   # prop2: property help text in EOL-comment for property PROP2.  Type "help cdef_help2.prop2"
+  end
+
+  methods
+
+    # cdef_help2: constructor help text ABOVE function keyword
+    # Type 'help cdef_help2.cdef_help2'.
+    # This should be shown because Octave comment character '#' is used.
+    function obj = cdef_help2 (p1, p2)
+      # cdef_help2: constructor help text BELOW function keyword
+      # Type 'help cdef_help2.cdef_help2'.
+      if (nargin ~= 2)
+        obj.prop1 = 'default';
+        obj.prop2 = 42;
+      else
+        obj.prop1 = p1;
+        obj.prop2 = p2;
+      end
+    end
+
+    # meth1: method help text ABOVE function
+    # 
+    # Type 'help cdef_help2.meth1'.
+    function obj2 = meth1 (obj, n)
+      obj2 = n + obj;
+    end
+    
+    function obj2 = meth2 (obj, n)
+
+      # meth2: method help text BELOW function
+      # The blank line between function and comment is intentional.
+      # Type 'help cdef_help2.meth2'.
+      obj2 = n - obj;
+    end
+
+    # meth3: method help text ABOVE function
+    # Type 'help cdef_help2.meth3'.
+    # This should be shown because Octave comment character '#' is used.
+    function obj3 = meth3 (obj, n)
+      # meth3: method help text BELOW function
+      # Type 'help cdef_help2.meth3'.
+      # This should NOT be displayed.
+      obj3 = obj + n;
+    end
+
+    function obj4 = meth4 (obj, n)
+
+      obj4 = n - obj;
+      if (n)
+        # meth4: pure comment text.  This should *never* be displayed.
+        # Type 'help cdef_help2.meth4'.
+      end
+    end
+
+  end
+
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-65220/module.mk	Mon Feb 05 14:22:06 2024 -0800
@@ -0,0 +1,6 @@
+bug_65220_TEST_FILES = \
+  %reldir%/bug-65220.tst \
+  %reldir%/cdef_help1.m \
+  %reldir%/cdef_help2.m
+
+TEST_FILES += $(bug_65220_TEST_FILES)