- Subject: Re: [jed-users] Failing unit test for valid $HOME
- From: "John E. Davis" <jed@xxxxxxxxxxx>
- Date: Thu, 13 Nov 2025 12:23:01 -0500
Hi Rafael,
Thanks for the bug report. The test_expand_filename function expands
its first argument and compares it to the value of the second
argument, which does not get expanded. The failed cases all involve
the use of "HOME" in the second argument. When I wrote the tests, I
assumed that $HOME would not contain a trailing slash. The attached
patch enforces this assumption.
Thanks,
--John
> Hi,
>
> Some unit tests in the test_expand.sl file fail in this particular case:
>
> $ HOME="/home/rlaboiss/" make -C src runtests
> make: Entering directory '/var/data/rlaboiss/debian/PKGS/jed/jed/src'
> ./test/runtests.sh /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_cmode.sl
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_expand.sl
> expand_filename (~/foo) -> /home/rlaboiss/foo, expected /home/rlaboiss//foo
> expand_filename (/foo/bar/~/xx/..) -> /home/rlaboiss/, expected /home/rlaboiss//
> expand_filename (/foo/bar/~/~/xx/..) -> /home/rlaboiss/, expected /home/rlaboiss//
> expand_filename (~/foo/bar/~/~/xx/..) -> /home/rlaboiss/, expected /home/rlaboiss//
> expand_filename (~/foo/bar/~/~xx) -> /home/rlaboiss/~xx, expected /home/rlaboiss//~xx
> expand_filename (~/foo/bar/~/xx~) -> /home/rlaboiss/xx~, expected /home/rlaboiss//xx~
> expand_filename (~/foo/bar/~) -> /home/rlaboiss/foo/bar/~, expected /home/rlaboiss//foo/bar/~
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_links.sl
> /tmp/jedtest19398.1448637/A/dev/hoo and /tmp/jedtest19398.1448637/A/dev/foo are the same
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_narrow.sl
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_region.sl
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_replace.sl
> Running /var/data/rlaboiss/debian/PKGS/jed/jed/src/objs/jed -script ./test/test_search.sl
> make: *** [Makefile:310: runtests] Error 1
> make: Leaving directory '/var/data/rlaboiss/debian/PKGS/jed/jed/src'
>
> The problem arises because there is a trailing slash in the HOME
> environment variable. This is one of the problematic unit tests:
>
> test_expand_filename ("~/foo", "$HOME/foo"$);
>
> This happens because the expand_filename command sanitizes the resulting
> path, by removing the multiple slashes, among other things.
>
> This could, theoretically, be fixed as:
>
> test_expand_filename ("~/foo", jed_standardize_filename ("$HOME/foo"$));
>
> However, the function jed_standardize_filename, defined in
> src/sysdep.c is not exported in SLang.
>
> Best,
>
> Rafael Laboissi�
> _______________________________________________
> For list information, visit <http://jedsoft.org/jed/mailinglists.html>.
>
diff --git a/src/test/test_expand.sl b/src/test/test_expand.sl
index 9f39ef3..fef05e0 100644
--- a/src/test/test_expand.sl
+++ b/src/test/test_expand.sl
@@ -29,13 +29,19 @@ test_expand_filename ("//./bar//gamma/.", "/bar/gamma/");
test_expand_filename ("//./bar//gamma/..", "/bar/");
test_expand_filename ("/..", "/");
test_expand_filename ("/.", "/");
-test_expand_filename ("~/foo", "$HOME/foo"$);
-test_expand_filename ("/foo/bar/~/xx/..", "$HOME/"$);
-test_expand_filename ("/foo/bar/~/~/xx/..", "$HOME/"$);
-test_expand_filename ("~/foo/bar/~/~/xx/..", "$HOME/"$);
-test_expand_filename ("~/foo/bar/~/~xx", "$HOME/~xx"$);
-test_expand_filename ("~/foo/bar/~/xx~", "$HOME/xx~"$);
-test_expand_filename ("~/foo/bar/~", "$HOME/foo/bar/~"$);
+
+private variable HOME = getenv ("HOME");
+if (HOME != NULL)
+{
+ HOME = strtrim_end(HOME, "/");
+ test_expand_filename ("~/foo", "$HOME/foo"$);
+ test_expand_filename ("/foo/bar/~/xx/..", "$HOME/"$);
+ test_expand_filename ("/foo/bar/~/~/xx/..", "$HOME/"$);
+ test_expand_filename ("~/foo/bar/~/~/xx/..", "$HOME/"$);
+ test_expand_filename ("~/foo/bar/~/~xx", "$HOME/~xx"$);
+ test_expand_filename ("~/foo/bar/~/xx~", "$HOME/xx~"$);
+ test_expand_filename ("~/foo/bar/~", "$HOME/foo/bar/~"$);
+}
#ifntrue
% Only for __QNX__
[2025 date index]
[2025 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]