1
1
import pytest
2
+ import os
2
3
3
- from conftest import assert_bash_exec , bash_env_saved
4
+ from conftest import assert_bash_exec , bash_env_saved , prepare_fixture_dir
4
5
5
6
6
7
@pytest .mark .bashcomp (cmd = None , cwd = "_comp_load" )
7
8
class TestCompLoad :
8
- def test_userdir_1 (self , bash ):
9
+ @pytest .fixture
10
+ def fixture_dir (self , request , bash ):
11
+ """Construct the fixture directory in a temporary directory.
12
+
13
+ Some of the tests use specific setups of symbolic links. However, if
14
+ we put the symbolic links in the static fixture directory, Automake
15
+ resolves them for tarballs. As a result, the tests fail when the files
16
+ are extracted from the tarballs. There does not seem to be any option
17
+ to change the behavior of Automake.
18
+
19
+ We instead manually set up all symbolic links needed for the tests
20
+ here. The other normal files and directories are statically included
21
+ in the repository as "/test/fixtures/_comp_load". We first copy the
22
+ statically included files and directories to a temporary directory and
23
+ set up symbolic links.
24
+ """
25
+
26
+ tmpdir , _ , _ = prepare_fixture_dir (request , files = [], dirs = [])
27
+ assert_bash_exec (bash , "cp -R %s/* %s/" % (os .getcwd (), tmpdir ))
28
+ assert_bash_exec (bash , "mkdir -p %s/bin" % tmpdir )
29
+ assert_bash_exec (
30
+ bash , "ln -sf ../prefix1/bin/cmd1 %s/bin/cmd1" % tmpdir
31
+ )
32
+ assert_bash_exec (
33
+ bash , "ln -sf ../prefix1/sbin/cmd2 %s/bin/cmd2" % tmpdir
34
+ )
35
+ return str (tmpdir )
36
+
37
+ def test_userdir_1 (self , bash , fixture_dir ):
9
38
with bash_env_saved (bash ) as bash_env :
39
+ bash_env .chdir (fixture_dir )
10
40
bash_env .write_variable (
11
41
"BASH_COMPLETION_USER_DIR" ,
12
42
"$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR" ,
@@ -24,8 +54,9 @@ def test_userdir_1(self, bash):
24
54
)
25
55
assert output .strip () == "cmd2: sourced from userdir2"
26
56
27
- def test_PATH_1 (self , bash ):
57
+ def test_PATH_1 (self , bash , fixture_dir ):
28
58
with bash_env_saved (bash ) as bash_env :
59
+ bash_env .chdir (fixture_dir )
29
60
bash_env .write_variable (
30
61
"PATH" , "$PWD/prefix1/bin:$PWD/prefix1/sbin" , quote = False
31
62
)
@@ -46,32 +77,35 @@ def test_PATH_1(self, bash):
46
77
)
47
78
assert "/prefix1/sbin/cmd2" in output
48
79
49
- def test_cmd_path_1 (self , bash ):
50
- assert_bash_exec (bash , "complete -r cmd1 || :" , want_output = None )
51
- output = assert_bash_exec (
52
- bash , "_comp_load prefix1/bin/cmd1" , want_output = True
53
- )
54
- assert output .strip () == "cmd1: sourced from prefix1"
55
- output = assert_bash_exec (
56
- bash , 'complete -p "$PWD/prefix1/bin/cmd1"' , want_output = True
57
- )
58
- assert "/prefix1/bin/cmd1" in output
59
- assert_bash_exec (bash , "! complete -p cmd1" , want_output = None )
60
- output = assert_bash_exec (
61
- bash , "_comp_load prefix1/sbin/cmd2" , want_output = True
62
- )
63
- assert output .strip () == "cmd2: sourced from prefix1"
64
- output = assert_bash_exec (
65
- bash , "_comp_load bin/cmd1" , want_output = True
66
- )
67
- assert output .strip () == "cmd1: sourced from prefix1"
68
- output = assert_bash_exec (
69
- bash , "_comp_load bin/cmd2" , want_output = True
70
- )
71
- assert output .strip () == "cmd2: sourced from prefix1"
80
+ def test_cmd_path_1 (self , bash , fixture_dir ):
81
+ with bash_env_saved (bash ) as bash_env :
82
+ bash_env .chdir (fixture_dir )
83
+ assert_bash_exec (bash , "complete -r cmd1 || :" , want_output = None )
84
+ output = assert_bash_exec (
85
+ bash , "_comp_load prefix1/bin/cmd1" , want_output = True
86
+ )
87
+ assert output .strip () == "cmd1: sourced from prefix1"
88
+ output = assert_bash_exec (
89
+ bash , 'complete -p "$PWD/prefix1/bin/cmd1"' , want_output = True
90
+ )
91
+ assert "/prefix1/bin/cmd1" in output
92
+ assert_bash_exec (bash , "! complete -p cmd1" , want_output = None )
93
+ output = assert_bash_exec (
94
+ bash , "_comp_load prefix1/sbin/cmd2" , want_output = True
95
+ )
96
+ assert output .strip () == "cmd2: sourced from prefix1"
97
+ output = assert_bash_exec (
98
+ bash , "_comp_load bin/cmd1" , want_output = True
99
+ )
100
+ assert output .strip () == "cmd1: sourced from prefix1"
101
+ output = assert_bash_exec (
102
+ bash , "_comp_load bin/cmd2" , want_output = True
103
+ )
104
+ assert output .strip () == "cmd2: sourced from prefix1"
72
105
73
- def test_cmd_path_2 (self , bash ):
106
+ def test_cmd_path_2 (self , bash , fixture_dir ):
74
107
with bash_env_saved (bash ) as bash_env :
108
+ bash_env .chdir (fixture_dir )
75
109
bash_env .write_variable ("PATH" , "$PWD/bin:$PATH" , quote = False )
76
110
output = assert_bash_exec (
77
111
bash , "_comp_load cmd1" , want_output = True
@@ -82,12 +116,13 @@ def test_cmd_path_2(self, bash):
82
116
)
83
117
assert output .strip () == "cmd2: sourced from prefix1"
84
118
85
- def test_cmd_intree_precedence (self , bash ):
119
+ def test_cmd_intree_precedence (self , bash , fixture_dir ):
86
120
"""
87
121
Test in-tree, i.e. completions/$cmd relative to the main script
88
122
has precedence over location derived from PATH.
89
123
"""
90
124
with bash_env_saved (bash ) as bash_env :
125
+ bash_env .chdir (fixture_dir )
91
126
bash_env .write_variable ("PATH" , "$PWD/prefix1/bin" , quote = False )
92
127
# The in-tree `sh` completion should be loaded here,
93
128
# and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.
0 commit comments