1
0
mirror of https://github.com/Tarrasch/zsh-autoenv.git synced 2024-11-22 07:20:59 +02:00
zsh-autoenv/tests/_autoenv_utils.t
Rob Speed 7e0d027b21 _autoenv_get_file_upwards: do not dereference symlinks (#73)
This prevents issues where autoenv scripts use $0. When a shell enters the directory holding the autoenv scripts, it works as expected with $0 being the path to the symlink. However, if the shell enters one of its child directories the path to the script is dereferenced, and $0 is instead the path to the symlink's target.

From `man 1 zshexpn`:

> A – Turn a file name into an absolute path as the 'a' modifier does, and then pass  the  result  through  the  realpath(3) library function to resolve symbolic links.

Note: Symlinks are dereferenced elsewhere for authorization, so that behavior is unchanged.
2017-11-02 02:40:45 +01:00

99 lines
2.6 KiB
Perl

Tests for internal util methods.
$ source $TESTDIR/setup.zsh || return 1
Non-existing entries are allowed and handled without error.
$ mkdir -p sub/sub2
$ touch file sub/file sub/sub2/file
Should not get the file from the current dir.
$ _autoenv_get_file_upwards . file
$ cd sub/sub2
$ _autoenv_get_file_upwards . file
../file
$ _autoenv_get_file_upwards $PWD file
*/_autoenv_utils.t/sub/file (glob)
_autoenv_get_file_upwards should not dereference symlinks.
$ cd ../..
$ ln -s sub symlink
$ cd symlink/sub2
$ _autoenv_get_file_upwards . file
../file
$ _autoenv_get_file_upwards $PWD file
*/_autoenv_utils.t/symlink/file (glob)
Tests for _autoenv_authorize. {{{
Auth file is empty.
$ cd ../..
$ ! [[ -f "$AUTOENV_AUTH_FILE" ]] || cat $AUTOENV_AUTH_FILE
Failed authorization should keep the auth file empty.
$ _autoenv_authorize does-not-exist
Missing file argument for _autoenv_hash_pair!
[1]
$ cat $AUTOENV_AUTH_FILE
Now adding some auth pair.
$ echo first > first
$ _autoenv_authorize first
$ cat $AUTOENV_AUTH_FILE
:/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
And a second one.
$ echo second > second
$ _autoenv_authorize second
$ cat $AUTOENV_AUTH_FILE
:/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
And a third.
$ echo third > third
$ _autoenv_authorize third
$ cat $AUTOENV_AUTH_FILE
:/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
Re-add the second one, with the same hash.
$ _autoenv_authorize second
$ cat $AUTOENV_AUTH_FILE
:/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
Re-add the first one, with a new hash.
$ echo one more line >> first
$ _autoenv_authorize first
$ cat $AUTOENV_AUTH_FILE
:/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
:/tmp/cramtests-*/_autoenv_utils.t/first:3620404822.20:2 (glob)
}}}
Explicit calls to _autoenv_get_file_mtime to test alternative implementation
of _autoenv_get_file_mtime (via ZDOTDIR.invalid-module_path/).
$ _autoenv_get_file_mtime non-existing
0
$ touch -t 201401010101 file
$ _autoenv_get_file_mtime file
1388538060
$ mkdir dir
$ touch -t 201401010102 dir
$ _autoenv_get_file_mtime dir
1388538120