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