]> Sergey Matveev's repositories - zsh-autoenv.git/blob - tests/_autoenv_utils.t
f4f2e2ce6dae04eb4b094f5a86576a3c516dc01c
[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   */_autoenv_utils.t/sub/file (glob)
17
18
19 Tests for _autoenv_authorize. {{{
20
21 Auth file is empty.
22
23   $ cd ../..
24   $ ! [[ -f "$AUTOENV_AUTH_FILE" ]] || cat $AUTOENV_AUTH_FILE
25
26 Failed authorization should keep the auth file empty.
27
28   $ _autoenv_authorize does-not-exist
29   Missing file argument for _autoenv_hash_pair!
30   [1]
31   $ cat $AUTOENV_AUTH_FILE
32
33 Now adding some auth pair.
34
35   $ echo first > first
36   $ _autoenv_authorize first
37   $ cat $AUTOENV_AUTH_FILE
38   :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
39
40 And a second one.
41
42   $ echo second > second
43   $ _autoenv_authorize second
44   $ cat $AUTOENV_AUTH_FILE
45   :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
46   :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
47
48 And a third.
49
50   $ echo third > third
51   $ _autoenv_authorize third
52   $ cat $AUTOENV_AUTH_FILE
53   :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
54   :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
55   :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
56
57 Re-add the second one, with the same hash.
58
59   $ _autoenv_authorize second
60   $ cat $AUTOENV_AUTH_FILE
61   :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:2 (glob)
62   :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
63   :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
64
65 Re-add the first one, with a new hash.
66
67   $ echo one more line >> first
68   $ _autoenv_authorize first
69   $ cat $AUTOENV_AUTH_FILE
70   :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:2 (glob)
71   :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:2 (glob)
72   :/tmp/cramtests-*/_autoenv_utils.t/first:3620404822.20:2 (glob)
73 }}}
74
75
76 Explicit calls to _autoenv_get_file_mtime to test alternative implementation
77 of _autoenv_get_file_mtime (via ZDOTDIR.invalid-module_path/).
78
79   $ _autoenv_get_file_mtime non-existing
80   0
81   $ touch -t 201401010101 file
82   $ _autoenv_get_file_mtime file
83   1388538060
84   $ mkdir dir
85   $ touch -t 201401010102 dir
86   $ _autoenv_get_file_mtime dir
87   1388538120