]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/_autoenv_utils.t
86e93c92eb50911232967492c54fe62d92a7203f
[zsh-autoenv.git] / tests / _autoenv_utils.t
1 Tests for internal util methods.
2
3   $ source $TESTDIR/setup.zsh || return 1
4
5 Non-existing entries are allowed and handled without error.
6
7   $ mkdir -p sub/sub2
8   $ touch file sub/file sub/sub2/file
9
10 Should not get the file from the current dir.
11
12   $ _autoenv_get_file_upwards . file
13
14   $ cd sub/sub2
15   $ _autoenv_get_file_upwards . file
16   ../file
17   $ _autoenv_get_file_upwards $PWD file
18   */_autoenv_utils.t/sub/file (glob)
19
20 _autoenv_get_file_upwards should not dereference symlinks.
21
22   $ cd ../..
23   $ ln -s sub symlink
24   $ cd symlink/sub2
25   $ _autoenv_get_file_upwards . file
26   ../file
27   $ _autoenv_get_file_upwards $PWD file
28   */_autoenv_utils.t/symlink/file (glob)
29
30 Tests for _autoenv_authorize. {{{
31
32 Auth file is empty.
33
34   $ cd ../..
35   $ ! [[ -f "$AUTOENV_AUTH_FILE" ]] || cat $AUTOENV_AUTH_FILE
36
37 Failed authorization should keep the auth file empty.
38
39   $ _autoenv_authorize does-not-exist
40   Missing file argument for _autoenv_hash_pair!
41   [1]
42   $ cat $AUTOENV_AUTH_FILE
43
44 Now adding some auth pair.
45
46   $ echo first > first
47   $ _autoenv_authorize first
48   $ cat $AUTOENV_AUTH_FILE
49   :/*/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
50
51 And a second one.
52
53   $ echo second > second
54   $ _autoenv_authorize second
55   $ cat $AUTOENV_AUTH_FILE
56   :/*/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
57   :/*/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
58
59 And a third.
60
61   $ echo third > third
62   $ _autoenv_authorize third
63   $ cat $AUTOENV_AUTH_FILE
64   :/*/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
65   :/*/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
66   :/*/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
67
68 Re-add the second one, with the same hash.
69
70   $ _autoenv_authorize second
71   $ cat $AUTOENV_AUTH_FILE
72   :/*/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
73   :/*/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
74   :/*/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
75
76 Re-add the first one, with a new hash.
77
78   $ echo one more line >> first
79   $ _autoenv_authorize first
80   $ cat $AUTOENV_AUTH_FILE
81   :/*/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
82   :/*/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
83   :/*/cramtests-*/_autoenv_utils.t/first:3620404822.20:2 (glob)
84 }}}
85
86
87 Explicit calls to _autoenv_get_file_mtime to test alternative implementation
88 of _autoenv_get_file_mtime (via ZDOTDIR.invalid-module_path/).
89
90   $ _autoenv_get_file_mtime non-existing
91   0
92   $ touch -t 201401010101 file
93   $ _autoenv_get_file_mtime file
94   1388538060
95   $ mkdir dir
96   $ touch -t 201401010102 dir
97   $ _autoenv_get_file_mtime dir
98   1388538120
99
100 Stops when last (absolute) path does not change anymore.
101
102   $ _autoenv_get_file_upwards / doesnotexist nevermatches