changeset 32411:768df05d04f3

add tests for bug 63841 * new subdir test/bug-63841 * add test/bug-63841 to build system
author A.R. Burgers <arburgers@gmail.com> and Fernando Alvarruiz <feralber@upvnet.upv.es>
date Sat, 15 Apr 2023 09:18:39 +0200
parents 554a932fc6d0
children 2e933fe82ecb
files test/Makefile.am test/bug-63841/@cls2_b63841/cls2_b63841.m test/bug-63841/@cls2_b63841/subsref.m test/bug-63841/bug-63841.tst test/bug-63841/cls_b63841.m test/bug-63841/module.mk
diffstat 6 files changed, 187 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/Makefile.am	Sat Apr 15 10:37:37 2023 +0200
+++ b/test/Makefile.am	Sat Apr 15 09:18:39 2023 +0200
@@ -107,6 +107,7 @@
 include bug-60882/module.mk
 include bug-61105/module.mk
 include bug-61191/module.mk
+include bug-63841/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-63841/@cls2_b63841/cls2_b63841.m	Sat Apr 15 09:18:39 2023 +0200
@@ -0,0 +1,4 @@
+function y = cls2_b63841 ()
+  y.a_property = 1;
+  y = class (y, 'cls2_b63841');
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-63841/@cls2_b63841/subsref.m	Sat Apr 15 09:18:39 2023 +0200
@@ -0,0 +1,3 @@
+function varargout = subsref(obj, s)
+  varargout = {nargout, s(1).type, 'arg3'};
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-63841/bug-63841.tst	Sat Apr 15 09:18:39 2023 +0200
@@ -0,0 +1,162 @@
+########################################################################
+##
+## Copyright (C) 2023-2023 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/>.
+##
+########################################################################
+
+%%
+%% Testing nargout when calling subsref for classdef classes
+%%
+
+%!test <*63841>
+%! cm = containers.Map;
+%! cm('first') = cls_b63841;
+%! a_63841 = 0;
+%! try
+%!   if cm('first').a_property
+%!     a_63841 = 1;
+%!   endif
+%! catch
+%! end_try_catch
+%! assert (a_63841, 1);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! a = 0;
+%! if ti(1:5).a_property
+%!   a = 1;
+%! endif
+%! assert (a, 1);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! a = 0;
+%! for x = ti(1:5).a_property
+%!   a = 1;
+%! endfor
+%! assert (a, 1);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b] = ti.call_a_method;
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b] = ti{1};
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b] = ti(1);
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b] = ti(1).a_property;
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b, c] = ti.call_a_method;
+%! assert (n_arg, 3);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b, c] = ti{1};
+%! assert (n_arg, 3);
+
+%!test <*63841>
+%! ti = cls_b63841;
+%! [n_arg, b, c] = ti(1);
+%! assert (n_arg, 3);
+
+%%
+%% Testing nargout when calling subsref for struct-based classes
+%%
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! a = 0;
+%! if ti(1:5).a_property
+%!   a = 1;
+%! endif
+%! assert (a, 1);
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! a = 0;
+%! for x = ti(1:5).a_property
+%!   a = 1;
+%! endfor
+%! assert (a, 1);
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! [n_arg, b] = ti.call_a_method;
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! [n_arg, b] = ti{1};
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! [n_arg, b] = ti(1);
+%! assert (n_arg, 2);
+
+%!test <*63841>
+%! ti = cls2_b63841;
+%! [n_arg, b] = ti(1).a_property;
+%! assert (n_arg, 2);
+
+%%
+%% Different expressions that should produce errors (classdef and struct-based classes)
+%%
+
+%!shared ti, ti2
+%! ti = cls_b63841;
+%! ti2 = cls2_b63841;
+
+%% binary operator
+%!error <binary operator \'\+\' not implemented for \'scalar\' by \'cs-list\' operations> 1 + ti(1:3).a_property
+%!error <binary operator \'\+\' not implemented for \'cs-list\' by \'scalar\' operations> ti(1:3).a_property + 1
+%!error <binary operator \'\+\' not implemented for \'cs-list\' by \'cs-list\' operations> ti(1:3).a_property + ti(1:3).a_property
+%!error <binary operator \'\+\' not implemented for \'scalar\' by \'cs-list\' operations> 1 + ti2(1:3).a_property
+%!error <binary operator \'\+\' not implemented for \'cs-list\' by \'scalar\' operations> ti2(1:3).a_property + 1
+%!error <binary operator \'\+\' not implemented for \'cs-list\' by \'cs-list\' operations> ti2(1:3).a_property + ti2(1:3).a_property
+
+%% unary postfix operator
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> ti(1:3).a_property'
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> ti2(1:3).a_property'
+
+%% unary prefix operator
+%!error <unary operator \'!\' not implemented for \'cs-list\' operands> ~ti(1:3).a_property
+%!error <unary operator \'!\' not implemented for \'cs-list\' operands> ~ti2(1:3).a_property
+
+%% compound binary operation
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> 3*ti(1:3).a_property'
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> ti(1:3).a_property'*3
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> 3*ti2(1:3).a_property'
+%!error <unary operator \'\'\' not implemented for \'cs-list\' operands> ti2(1:3).a_property'*3
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-63841/cls_b63841.m	Sat Apr 15 09:18:39 2023 +0200
@@ -0,0 +1,10 @@
+classdef cls_b63841
+  properties
+    a_property = 1;
+  end
+  methods
+    function varargout = subsref(obj, s)
+      varargout = {nargout, s(1).type, 'arg3'};
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-63841/module.mk	Sat Apr 15 09:18:39 2023 +0200
@@ -0,0 +1,7 @@
+bug_63841_TEST_FILES = \
+  %reldir%/@cls2_b63841/cls2_b63841.m \
+  %reldir%/@cls2_b63841/subsref.m \
+  %reldir%/bug-63841.tst \
+  %reldir%/cls_b63841.m
+
+TEST_FILES += $(bug_63841_TEST_FILES)