Mercurial > octave
changeset 33164:b4f8f14dc1fb stable
Refresh fcn-info on current directory change (bug #65406).
* interpreter.cc (interpreter::chdir): Update the last prompt time stamp to
avoid skipping a fcn-info refresh so that functions in the new current directory
can shadow functions further back in the load path order.
* test/load-path/refresh-load-path.tst: Add new test to this issue.
* test/load-path/in-load-path/load_path_fcn.m,
test/load-path/not-in-load-path/load_path_fcn.m: Add helper functions for new
test.
* test/load-path/module.mk: Add files of new test to build system.
* test/Makefile.am: Include new module.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Thu, 07 Mar 2024 18:08:40 +0100 |
parents | baf7621aa073 |
children | 2c9b649e96c8 6f74463268b8 |
files | libinterp/corefcn/interpreter.cc test/Makefile.am test/load-path/in-load-path/load_path_fcn.m test/load-path/module.mk test/load-path/not-in-load-path/load_path_fcn.m test/load-path/refresh-load-path.tst |
diffstat | 6 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Tue Mar 05 09:00:30 2024 +0100 +++ b/libinterp/corefcn/interpreter.cc Thu Mar 07 18:08:40 2024 +0100 @@ -1407,6 +1407,10 @@ m_load_path.read_dir_config ("."); m_load_path.update (); + // Updating the last prompt time stamp avoids skipping a fcn-info refresh + // so that functions in the new current directory can shadow functions + // further back in the load path order. + Vlast_prompt_time.stamp (); m_event_manager.directory_changed (sys::env::get_current_directory ());
--- a/test/Makefile.am Tue Mar 05 09:00:30 2024 +0100 +++ b/test/Makefile.am Thu Mar 07 18:08:40 2024 +0100 @@ -124,6 +124,7 @@ include file-encoding/module.mk include json/module.mk include jupyter-notebook/module.mk +include load-path/module.mk include local-functions/module.mk include mex/module.mk include nest/module.mk
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/load-path/in-load-path/load_path_fcn.m Thu Mar 07 18:08:40 2024 +0100 @@ -0,0 +1,3 @@ +function out = load_path_fcn () +out = "in-load-path"; +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/load-path/module.mk Thu Mar 07 18:08:40 2024 +0100 @@ -0,0 +1,7 @@ +load_path_TEST_FILES = \ + %reldir%/.oct-config \ + %reldir%/refresh-load-path.tst \ + %reldir%/in-load-path/load_path_fcn.m \ + %reldir%/not-in-load-path/load_path_fcn.m + +TEST_FILES += $(load_path_TEST_FILES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/load-path/not-in-load-path/load_path_fcn.m Thu Mar 07 18:08:40 2024 +0100 @@ -0,0 +1,3 @@ +function out = load_path_fcn () +out = "not-in-load-path"; +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/load-path/refresh-load-path.tst Thu Mar 07 18:08:40 2024 +0100 @@ -0,0 +1,38 @@ +######################################################################## +## +## 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 <*65406> +%! path_orig = path (); +%! pwd_orig = pwd (); +%! unwind_protect +%! addpath (fullfile (pwd_orig, "in-load-path")); +%! assert (load_path_fcn (), "in-load-path"); +%! +%! cd ("not-in-load-path"); +%! assert (load_path_fcn (), "not-in-load-path"); +%! unwind_protect_cleanup +%! path (path_orig); +%! cd (pwd_orig); +%! end_unwind_protect