changeset 31484:601b08ce0c00

oruntests.m: Change to directory containing tests (bug #62780). * scripts/testfun/oruntests.m: Change to the directory containing the tests for the duration of the test. This aligns the behavior of this function with Octave's test suite. This also means that the file encoding specified in the .oct-config file for the respective directory is taken into account for the tests. * etc/NEWS.9.md: Add note about this change to NEWS file.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 19 Nov 2022 14:48:59 +0100
parents 75cbfaf709cb
children 07abf0487c8f
files etc/NEWS.9.md scripts/testfun/oruntests.m
diffstat 2 files changed, 33 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS.9.md	Tue Nov 15 12:25:40 2022 -0300
+++ b/etc/NEWS.9.md	Sat Nov 19 14:48:59 2022 +0100
@@ -3,6 +3,12 @@
 
 ### General improvements
 
+- `oruntests`: The current directory now changes to the directory
+containing the files with the tests for the duration of the test.  This
+aligns the behavior of this function with Octave's test suite.  This also
+means that the file encoding specified in the `.oct-config` file for the
+respective directory is taken into account for the tests.
+
 ### Graphical User Interface
 
 ### Graphics backend
--- a/scripts/testfun/oruntests.m	Tue Nov 15 12:25:40 2022 -0300
+++ b/scripts/testfun/oruntests.m	Sat Nov 19 14:48:59 2022 +0100
@@ -71,29 +71,34 @@
   no_tests = {};
   printf ("Processing files in %s:\n\n", directory);
   fflush (stdout);
-  for i = 1:numel (flist)
-    f = flist{i};
-    if ((length (f) > 2 && strcmpi (f((end-1):end), ".m"))
-        || (length (f) > 3 && strcmpi (f((end-2):end), ".cc")))
-      ff = fullfile (directory, f);
-      if (! isfile (ff))
-        continue;
+  unwind_protect
+    old_dir = cd (directory);
+    for i = 1:numel (flist)
+      f = flist{i};
+      if ((length (f) > 2 && strcmpi (f((end-1):end), ".m"))
+          || (length (f) > 3 && strcmpi (f((end-2):end), ".cc")))
+        ff = fullfile (directory, f);
+        if (! isfile (ff))
+          continue;
+        endif
+        if (has_tests (ff))
+          print_test_file_name (f);
+          [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet");
+          print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs);
+          fflush (stdout);
+        elseif (has_functions (ff))
+          no_tests(end+1) = f;
+        endif
+      elseif (f(1) == "@")
+        f = fullfile (directory, f);
+        if (isfolder (f))
+          dirs(end+1) = f;
+        endif
       endif
-      if (has_tests (ff))
-        print_test_file_name (f);
-        [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet");
-        print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs);
-        fflush (stdout);
-      elseif (has_functions (ff))
-        no_tests(end+1) = f;
-      endif
-    elseif (f(1) == "@")
-      f = fullfile (directory, f);
-      if (isfolder (f))
-        dirs(end+1) = f;
-      endif
-    endif
-  endfor
+    endfor
+  unwind_protect_cleanup
+    cd (old_dir);
+  end_unwind_protect
   if (! isempty (no_tests))
     printf ("\nThe following files in %s have no tests:\n\n", directory);
     printf ("%s", list_in_columns (no_tests));