Mercurial > hg > octave-lyh
comparison scripts/testfun/demo.m @ 15079:dda73cb60ac5
demo.m: Allow functions in demo blocks (bug #33981).
* demo.m: Remove regexp code that checks for embedded functions in
demo blocks and issues an error.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 01 Aug 2012 16:44:16 -0700 |
parents | 5d3a684236b0 |
children | bcace51598ed |
comparison
equal
deleted
inserted
replaced
15078:fe4752f772e2 | 15079:dda73cb60ac5 |
---|---|
121 endif | 121 endif |
122 | 122 |
123 ## Process each demo without failing | 123 ## Process each demo without failing |
124 try | 124 try |
125 block = code(idx(doidx(i)):idx(doidx(i)+1)-1); | 125 block = code(idx(doidx(i)):idx(doidx(i)+1)-1); |
126 ## FIXME: need to check for embedded test functions, which cause | 126 ## Use an environment without variables |
127 ## segfaults, until issues with subfunctions in functions are resolved. | 127 eval (cstrcat ("function __demo__ ()\n", block, "\nendfunction")); |
128 embed_func = regexp (block, '^\s*function ', 'once', 'lineanchors'); | 128 ## Display the code that will be executed before executing it |
129 if (isempty (embed_func)) | 129 printf ("%s example %d:%s\n\n", name, doidx(i), block); |
130 ## Use an environment without variables | 130 __demo__; |
131 eval (cstrcat ("function __demo__ ()\n", block, "\nendfunction")); | |
132 ## Display the code that will be executed before executing it | |
133 printf ("%s example %d:%s\n\n", name, doidx(i), block); | |
134 __demo__; | |
135 else | |
136 error (["Functions embedded in %!demo blocks are not allowed.\n", ... | |
137 "Use the %!function/%!endfunction syntax instead to define shared functions for testing.\n"]); | |
138 endif | |
139 catch | 131 catch |
140 ## Let the programmer know which demo failed. | 132 ## Let the programmer know which demo failed. |
141 printf ("%s example %d: failed\n%s\n", name, doidx(i), lasterr ()); | 133 printf ("%s example %d: failed\n%s\n", name, doidx(i), lasterr ()); |
142 end_try_catch | 134 end_try_catch |
143 clear __demo__; | 135 clear __demo__; |