changeset 26860:7c9a681c4474

Add fixed test BIST for nested functions (bug #39257). * test/nest/counter.m: New function to test nested functions. * test/nest/module.mk: Add counter.m to build system. * test/nest/nest.tst: Add BIST test that uses counter.m.
author Rik <rik@octave.org>
date Thu, 07 Mar 2019 10:52:18 -0800
parents 0adb232f93b9
children 6236c790bd1b
files test/nest/counter.m test/nest/module.mk test/nest/nest.tst
diffstat 3 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/nest/counter.m	Thu Mar 07 10:52:18 2019 -0800
@@ -0,0 +1,8 @@
+function fcnHandle = counter
+  value = 0;
+  function currentValue = increment
+    value = value+1;
+    currentValue = value;
+  end
+  fcnHandle = @increment;
+end
--- a/test/nest/module.mk	Tue Mar 05 13:51:16 2019 +0100
+++ b/test/nest/module.mk	Thu Mar 07 10:52:18 2019 -0800
@@ -1,6 +1,7 @@
 nest_TEST_FILES = \
   %reldir%/arg_nest.m \
   %reldir%/arg_ret.m \
+  %reldir%/counter.m \
   %reldir%/nest.tst \
   %reldir%/nest_eval.m \
   %reldir%/no_closure.m \
--- a/test/nest/nest.tst	Tue Mar 05 13:51:16 2019 +0100
+++ b/test/nest/nest.tst	Thu Mar 07 10:52:18 2019 -0800
@@ -136,3 +136,10 @@
 %! assert (fh3 (), pi);
 %!
 %! clear -global g;  # cleanup after tests
+
+## Test case from <https://stackoverflow.com/q/26238491/6579744>
+%!test
+%! f1 = counter ();
+%! f2 = counter ();
+%! observed = [f1(), f1(), f2(), f1(), f2()];
+%! assert (observed, [1, 2, 1, 3, 2]);