Skip to content

Commit f7e54df

Browse files
committed
test: fix test for _comp_load
CI tests for "_comp_load" fails because Automake specifies "-h" to "tar" to create a tar ball, which breaks the symbolic-link structure used by tests of "_comp_load". In this patch, to properly test "_comp_load", we copy the fixture directory "test/fixtures/_comp_load" to a temporary directory and create needed symbolic links dynamically.
1 parent 8a36854 commit f7e54df

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

test/fixtures/_comp_load/bin/cmd1

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/_comp_load/bin/cmd2

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/t/unit/test_unit_load.py

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
import pytest
2+
import os
23

3-
from conftest import assert_bash_exec, bash_env_saved
4+
from conftest import assert_bash_exec, bash_env_saved, prepare_fixture_dir
45

56

67
@pytest.mark.bashcomp(cmd=None, cwd="_comp_load")
78
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):
938
with bash_env_saved(bash) as bash_env:
39+
bash_env.chdir(fixture_dir)
1040
bash_env.write_variable(
1141
"BASH_COMPLETION_USER_DIR",
1242
"$PWD/userdir1:$PWD/userdir2:$BASH_COMPLETION_USER_DIR",
@@ -24,8 +54,9 @@ def test_userdir_1(self, bash):
2454
)
2555
assert output.strip() == "cmd2: sourced from userdir2"
2656

27-
def test_PATH_1(self, bash):
57+
def test_PATH_1(self, bash, fixture_dir):
2858
with bash_env_saved(bash) as bash_env:
59+
bash_env.chdir(fixture_dir)
2960
bash_env.write_variable(
3061
"PATH", "$PWD/prefix1/bin:$PWD/prefix1/sbin", quote=False
3162
)
@@ -46,32 +77,35 @@ def test_PATH_1(self, bash):
4677
)
4778
assert "/prefix1/sbin/cmd2" in output
4879

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"
72105

73-
def test_cmd_path_2(self, bash):
106+
def test_cmd_path_2(self, bash, fixture_dir):
74107
with bash_env_saved(bash) as bash_env:
108+
bash_env.chdir(fixture_dir)
75109
bash_env.write_variable("PATH", "$PWD/bin:$PATH", quote=False)
76110
output = assert_bash_exec(
77111
bash, "_comp_load cmd1", want_output=True
@@ -82,12 +116,13 @@ def test_cmd_path_2(self, bash):
82116
)
83117
assert output.strip() == "cmd2: sourced from prefix1"
84118

85-
def test_cmd_intree_precedence(self, bash):
119+
def test_cmd_intree_precedence(self, bash, fixture_dir):
86120
"""
87121
Test in-tree, i.e. completions/$cmd relative to the main script
88122
has precedence over location derived from PATH.
89123
"""
90124
with bash_env_saved(bash) as bash_env:
125+
bash_env.chdir(fixture_dir)
91126
bash_env.write_variable("PATH", "$PWD/prefix1/bin", quote=False)
92127
# The in-tree `sh` completion should be loaded here,
93128
# and cause no output, unlike our `$PWD/prefix1/bin/sh` canary.

0 commit comments

Comments
 (0)