Mercurial > octave
changeset 26960:6731d89ef576
new tests for functions in package directories (bug #51709, bug #55975)
* test/fcn-handle/+pkga/+pkgb/bug51709_a.m,
test/fcn-handle/+pkga/+pkgb/bug51709_b.m,
test/fcn-handle/+pkga/+pkgb/f1.m, test/fcn-handle/+pkga/+pkgb/f2.m,
test/fcn-handle/bug51709_a.m, test/fcn-handle/f1.m,
test/fcn-handle/package-function.tst,
test/fcn-handle/static-method.tst: New files.
* test/fcn-handle: Rename from test/fcn-handle-derived-resolution.
* test/fcn-handle/module.mk, test/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Mar 2019 19:06:09 +0000 |
parents | 3ed8955dcdf9 |
children | 1a79f289ca33 |
files | test/fcn-handle-derived-resolution/@fhdr_derived/fhdr_derived.m test/fcn-handle-derived-resolution/@fhdr_other/fhdr_other.m test/fcn-handle-derived-resolution/@fhdr_other/getsize_arrayfun.m test/fcn-handle-derived-resolution/@fhdr_other/getsize_cellfun.m test/fcn-handle-derived-resolution/@fhdr_other/getsize_loop.m test/fcn-handle-derived-resolution/@fhdr_parent/fhdr_parent.m test/fcn-handle-derived-resolution/@fhdr_parent/numel.m test/fcn-handle-derived-resolution/fcn-handle-derived-resolution.tst test/fcn-handle-derived-resolution/module.mk test/fcn-handle/+pkga/+pkgb/bug51709_a.m test/fcn-handle/+pkga/+pkgb/bug51709_b.m test/fcn-handle/+pkga/+pkgb/f1.m test/fcn-handle/+pkga/+pkgb/f2.m test/fcn-handle/@fhdr_derived/fhdr_derived.m test/fcn-handle/@fhdr_other/fhdr_other.m test/fcn-handle/@fhdr_other/getsize_arrayfun.m test/fcn-handle/@fhdr_other/getsize_cellfun.m test/fcn-handle/@fhdr_other/getsize_loop.m test/fcn-handle/@fhdr_parent/fhdr_parent.m test/fcn-handle/@fhdr_parent/numel.m test/fcn-handle/bug51709_a.m test/fcn-handle/derived-resolution.tst test/fcn-handle/f1.m test/fcn-handle/module.mk test/fcn-handle/package-function.tst test/fcn-handle/static-method.tst test/module.mk |
diffstat | 27 files changed, 204 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/test/fcn-handle-derived-resolution/@fhdr_derived/fhdr_derived.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function r = fhdr_derived (n) - s.a = n; - p = fhdr_parent (n); - r = class (s, 'fhdr_derived', p); -end
--- a/test/fcn-handle-derived-resolution/@fhdr_other/fhdr_other.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function r = fhdr_other (n) - s.d = fhdr_derived (n); - r = class (s, 'fhdr_other'); -end
--- a/test/fcn-handle-derived-resolution/@fhdr_other/getsize_arrayfun.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function r = getsize_arrayfun (x) - r = arrayfun (@(i) numel (x(i).d), 1:numel (x), 'uniformoutput', true); -end
--- a/test/fcn-handle-derived-resolution/@fhdr_other/getsize_cellfun.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function r = getsize_cellfun (x) - r = cellfun (@numel, {x.d}); -end
--- a/test/fcn-handle-derived-resolution/@fhdr_other/getsize_loop.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -function r = getsize_loop (x) - n = numel (x); - r = zeros (1, n); - for i = 1:n - r(i) = numel (x(i).d); - end -end
--- a/test/fcn-handle-derived-resolution/@fhdr_parent/fhdr_parent.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function r = fhdr_parent (n) - s.a = rand (n, 1); - r = class (s, 'fhdr_parent'); -end
--- a/test/fcn-handle-derived-resolution/@fhdr_parent/numel.m Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function r = numel (x, varargin) - r = numel (x.a, varargin{:}); -end
--- a/test/fcn-handle-derived-resolution/fcn-handle-derived-resolution.tst Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -## Copyright (C) 2012-2019 John W. Eaton -## -## 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 script for legacy OOP. -%% Requires the path to contain the directory ctor-vs-method. -%% -%% Note: This script and all classes are also intended to run -%% in Matlab to test compatibility. Don't break that! - -%% FIXME: Can't use 'clear -classes' because it also clears all functions in the -%% namespace of test.m (bug #35881). This is a problem only if Octave would -%% re-use a class definition that was defined somewhere else. Unfortunately, -%% that is exactly the case when running 'make check' since the ctor-vs-method -%% test also uses an @parent, @derived, and @other class. -%% Until the bug is fixed, it suffices to make the class names unique so that -%% there is no re-use. Using the prefix fhdr (fcn-handle-derived-resolution) -%% for this directory. -%%!shared -%%! #clear -classes - -%!test -%! p = fhdr_parent (7); -%! assert (numel (p), 7); - -%!test -%! d = fhdr_derived (13); -%! assert (numel (d), 13); - -%!test -%! p = fhdr_parent (11); -%! f = @numel; -%! assert (f (p), 11); - -%!test -%! d = fhdr_parent (21); -%! f = @numel; -%! assert (f (d), 21); - -%!test -%! o(1) = fhdr_other (13); -%! o(2) = fhdr_other (42); -%! assert (getsize_loop (o), [13, 42]); - -%!test -%! o(1) = fhdr_other (13); -%! o(2) = fhdr_other (42); -%! assert (getsize_cellfun (o), [13, 42]); - -%!test -%! o(1) = fhdr_other (13); -%! o(2) = fhdr_other (42); -%! assert (getsize_arrayfun (o), [13, 42]);
--- a/test/fcn-handle-derived-resolution/module.mk Fri Mar 22 08:05:04 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -fcn_handle_derived_resolution_TEST_FILES = \ - %reldir%/@fhdr_derived/fhdr_derived.m \ - %reldir%/@fhdr_other/fhdr_other.m \ - %reldir%/@fhdr_other/getsize_arrayfun.m \ - %reldir%/@fhdr_other/getsize_cellfun.m \ - %reldir%/@fhdr_other/getsize_loop.m \ - %reldir%/@fhdr_parent/fhdr_parent.m \ - %reldir%/@fhdr_parent/numel.m \ - %reldir%/fcn-handle-derived-resolution.tst - -TEST_FILES += $(fcn_handle_derived_resolution_TEST_FILES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/+pkga/+pkgb/bug51709_a.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,7 @@ +classdef bug51709_a + methods (Static) + function r = smeth () + r = "pkg bug51709_a"; + end + end +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/+pkga/+pkgb/bug51709_b.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,7 @@ +classdef bug51709_b + methods (Static) + function r = smeth () + r = "pkg bug51709_b"; + end + end +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/+pkga/+pkgb/f1.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = f1 () + r = "pkg f1"; +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/+pkga/+pkgb/f2.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = f2 () + r = "pkg f2"; +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_derived/fhdr_derived.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,5 @@ +function r = fhdr_derived (n) + s.a = n; + p = fhdr_parent (n); + r = class (s, 'fhdr_derived', p); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_other/fhdr_other.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,4 @@ +function r = fhdr_other (n) + s.d = fhdr_derived (n); + r = class (s, 'fhdr_other'); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_other/getsize_arrayfun.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = getsize_arrayfun (x) + r = arrayfun (@(i) numel (x(i).d), 1:numel (x), 'uniformoutput', true); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_other/getsize_cellfun.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = getsize_cellfun (x) + r = cellfun (@numel, {x.d}); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_other/getsize_loop.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,7 @@ +function r = getsize_loop (x) + n = numel (x); + r = zeros (1, n); + for i = 1:n + r(i) = numel (x(i).d); + end +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_parent/fhdr_parent.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,4 @@ +function r = fhdr_parent (n) + s.a = rand (n, 1); + r = class (s, 'fhdr_parent'); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/@fhdr_parent/numel.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = numel (x, varargin) + r = numel (x.a, varargin{:}); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/bug51709_a.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,7 @@ +classdef bug51709_a + methods (Static) + function r = smeth () + r = "top bug51709_a"; + end + end +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/derived-resolution.tst Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,67 @@ +## Copyright (C) 2012-2019 John W. Eaton +## +## 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 script for legacy OOP. +%% Requires the path to contain the directory ctor-vs-method. +%% +%% Note: This script and all classes are also intended to run +%% in Matlab to test compatibility. Don't break that! + +%% FIXME: Can't use 'clear -classes' because it also clears all functions in the +%% namespace of test.m (bug #35881). This is a problem only if Octave would +%% re-use a class definition that was defined somewhere else. Unfortunately, +%% that is exactly the case when running 'make check' since the ctor-vs-method +%% test also uses an @parent, @derived, and @other class. +%% Until the bug is fixed, it suffices to make the class names unique so that +%% there is no re-use. Using the prefix fhdr (fcn-handle/derived-resolution) +%% for this directory. +%%!shared +%%! #clear -classes + +%!test +%! p = fhdr_parent (7); +%! assert (numel (p), 7); + +%!test +%! d = fhdr_derived (13); +%! assert (numel (d), 13); + +%!test +%! p = fhdr_parent (11); +%! f = @numel; +%! assert (f (p), 11); + +%!test +%! d = fhdr_parent (21); +%! f = @numel; +%! assert (f (d), 21); + +%!test +%! o(1) = fhdr_other (13); +%! o(2) = fhdr_other (42); +%! assert (getsize_loop (o), [13, 42]); + +%!test +%! o(1) = fhdr_other (13); +%! o(2) = fhdr_other (42); +%! assert (getsize_cellfun (o), [13, 42]); + +%!test +%! o(1) = fhdr_other (13); +%! o(2) = fhdr_other (42); +%! assert (getsize_arrayfun (o), [13, 42]);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/f1.m Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,3 @@ +function r = f1 () + r = "top f1"; +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/module.mk Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,19 @@ +fcn_handle_TEST_FILES = \ + %reldir%/+pkga/+pkgb/bug51709_a.m \ + %reldir%/+pkga/+pkgb/bug51709_b.m \ + %reldir%/+pkga/+pkgb/f1.m \ + %reldir%/+pkga/+pkgb/f2.m \ + %reldir%/@fhdr_derived/fhdr_derived.m \ + %reldir%/@fhdr_other/fhdr_other.m \ + %reldir%/@fhdr_other/getsize_arrayfun.m \ + %reldir%/@fhdr_other/getsize_cellfun.m \ + %reldir%/@fhdr_other/getsize_loop.m \ + %reldir%/@fhdr_parent/fhdr_parent.m \ + %reldir%/@fhdr_parent/numel.m \ + %reldir%/bug51709_a.m \ + %reldir%/derived-resolution.tst \ + %reldir%/f1.m \ + %reldir%/package-function.tst \ + %reldir%/static-method.tst + +TEST_FILES += $(fcn_handle_TEST_FILES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/package-function.tst Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,29 @@ +## Copyright (C) 2019 John W. Eaton +## +## 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 <46659> +%! fh = @pkga.pkgb.f2; +%! assert (fh (), "pkg f2"); + +%!test <55975> +%! fh = @pkga.pkgb.f1; +%! assert (fh (), "pkg f1"); + +## Also test without function handle. +%!assert <55975> (pkga.pkgb.f1 (), "pkg f1"); +%!assert (pkga.pkgb.f2 (), "pkg f2");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/fcn-handle/static-method.tst Thu Mar 21 19:06:09 2019 +0000 @@ -0,0 +1,29 @@ +## Copyright (C) 2019 John W. Eaton +## +## 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 <51709> +%! fh = @pkga.pkgb.bug51709_a.smeth; +%! assert (fh (), "pkg bug51709_a"); + +%!test <55975> +%! fh = @pkga.pkgb.bug51709_b.smeth; +%! assert (fh (), "pkg bug51709_b"); + +## Also test without function handle. +%!assert <55975> (pkga.pkgb.bug51709_a.smeth (), "pkg bug51709_a"); +%!assert (pkga.pkgb.bug51709_b.smeth (), "pkg bug51709_b");
--- a/test/module.mk Fri Mar 22 08:05:04 2019 +0100 +++ b/test/module.mk Thu Mar 21 19:06:09 2019 +0000 @@ -85,7 +85,7 @@ include %reldir%/classdef-multiple-inheritance/module.mk include %reldir%/classes/module.mk include %reldir%/ctor-vs-method/module.mk -include %reldir%/fcn-handle-derived-resolution/module.mk +include %reldir%/fcn-handle/module.mk include %reldir%/local-functions/module.mk include %reldir%/mex/module.mk include %reldir%/nest/module.mk