File: 19-backport-fix-for-parallel-test.patch

package info (click to toggle)
bash-completion 1%3A2.16.0-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,440 kB
  • sloc: python: 11,252; makefile: 2,471; sh: 934; perl: 85; awk: 55; xml: 29; ansic: 7; java: 5; ruby: 2
file content (417 lines) | stat: -rw-r--r-- 16,136 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
From: Gabriel F. T. Gomes <gabriel@inconstante.net.br>
Subject: Add missing dependency on fixtures to help parallel testing
Bug: https://github.com/scop/bash-completion/pull/1303

When running the test suite with xdist and 'pytest -n <jobs>', several
tests fail. This happens because, in these tests, the definition of the
tested command, usually in a fixture method called 'functions' might
happen only after the execution of the tests themselves, i.e. in the
methods whose names start with 'test_'.

This patch adds the missing dependency on these test-command-defining
fixtures, so that they are executed before the tests themselves.

Steps to reproduce:

1. Make sure pytest-xdist is installed. On Debian systems this can be
   verified with the following command:

     dpkg --list python3-pytest-xdist

2. Build and install bash-completion locally, for example with the
   following commands:

     autoreconf -f -i
     ./configure --prefix=$PWD/install/
     make install

3. Run the test suite with a few parallel jobs, such as with:

     export MYPATH=$PWD/install/share/bash-completion/bash_completion
     BASH_COMPLETION_TEST_BASH_COMPLETION=$MYPATH \
       pytest \
         -n 8 \
         test/t/unit/test_unit_count_args.py \
         test/t/unit/test_unit_dequote.py \
         test/t/unit/test_unit_get_first_arg.py \
         test/t/unit/test_unit_quote.py
     unset MYPATH

Before this patch, these tests fail with messages similar to:

  FAILED test/t/unit/test_unit_quote.py::TestUnitQuote::test_3 -
  AssertionError: Error running "__tester "  a "": exit status=127, output="

After this patch, all these tests, which previously failed, pass.
---
 test/t/unit/test_unit_count_args.py    | 24 +++++------
 test/t/unit/test_unit_dequote.py       | 57 ++++++++++++++------------
 test/t/unit/test_unit_get_first_arg.py | 10 ++---
 test/t/unit/test_unit_quote.py         | 13 +++---
 4 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/test/t/unit/test_unit_count_args.py b/test/t/unit/test_unit_count_args.py
index 7b018e48..66210436 100644
--- a/test/t/unit/test_unit_count_args.py
+++ b/test/t/unit/test_unit_count_args.py
@@ -76,38 +76,38 @@ class TestUnitCountArgs(TestUnitBase):
         )
         assert output == "3"
 
-    def test_10_single_hyphen_1(self, bash):
+    def test_10_single_hyphen_1(self, bash, functions):
         """- should be counted as an argument representing stdout/stdin"""
         output = self._test(bash, "(a -b - c -d e)", 5, "a -b - c -d e", 12)
         assert output == "3"
 
-    def test_10_single_hyphen_2(self, bash):
+    def test_10_single_hyphen_2(self, bash, functions):
         """- in an option argument should be skipped"""
         output = self._test(
             bash, "(a -b - c - e)", 5, "a -b - c - e", 11, arg='-a "-b"'
         )
         assert output == "3"
 
-    def test_11_double_hyphen_1(self, bash):
+    def test_11_double_hyphen_1(self, bash, functions):
         """all the words after -- should be counted"""
         output = self._test(
             bash, "(a -b -- -c -d e)", 5, "a -b -- -c -d e", 14
         )
         assert output == "3"
 
-    def test_11_double_hyphen_2(self, bash):
+    def test_11_double_hyphen_2(self, bash, functions):
         """all the words after -- should be counted"""
         output = self._test(bash, "(a b -- -c -d e)", 5, "a b -- -c -d e", 13)
         assert output == "4"
 
-    def test_12_exclude_optarg_1(self, bash):
+    def test_12_exclude_optarg_1(self, bash, functions):
         """an option argument should be skipped even if it matches the argument pattern"""
         output = self._test(
             bash, "(a -o -x b c)", 4, "a -o -x b c", 10, arg='-a "-o" -i "-x"'
         )
         assert output == "2"
 
-    def test_12_exclude_optarg_2(self, bash):
+    def test_12_exclude_optarg_2(self, bash, functions):
         """an option argument should be skipped even if it matches the argument pattern"""
         output = self._test(
             bash,
@@ -119,7 +119,7 @@ class TestUnitCountArgs(TestUnitBase):
         )
         assert output == "2"
 
-    def test_12_exclude_optarg_3(self, bash):
+    def test_12_exclude_optarg_3(self, bash, functions):
         """an option argument should be skipped even if it matches the argument pattern"""
         output = self._test(
             bash,
@@ -131,21 +131,21 @@ class TestUnitCountArgs(TestUnitBase):
         )
         assert output == "1"
 
-    def test_13_plus_option_optarg(self, bash):
+    def test_13_plus_option_optarg(self, bash, functions):
         """When +o is specified to be an option taking an option argument, it should not be counted as an argument"""
         output = self._test(
             bash, "(a +o b c)", 3, "a +o b c", 7, arg='-a "+o"'
         )
         assert output == "1"
 
-    def test_14_no_optarg_chain_1(self, bash):
+    def test_14_no_optarg_chain_1(self, bash, functions):
         """an option argument should not take another option argument"""
         output = self._test(
             bash, "(a -o -o -o -o c)", 5, "a -o -o -o -o c", 14, arg='-a "-o"'
         )
         assert output == "1"
 
-    def test_14_no_optarg_chain_2(self, bash):
+    def test_14_no_optarg_chain_2(self, bash, functions):
         """an option argument should not take another option argument"""
         output = self._test(
             bash,
@@ -157,14 +157,14 @@ class TestUnitCountArgs(TestUnitBase):
         )
         assert output == "2"
 
-    def test_15_double_hyphen_optarg(self, bash):
+    def test_15_double_hyphen_optarg(self, bash, functions):
         """-- should lose its meaning when it is an option argument"""
         output = self._test(
             bash, "(a -o -- -b -c d)", 5, "a -o -- -b -c d", 14, arg='-a "-o"'
         )
         assert output == "1"
 
-    def test_16_empty_word(self, bash):
+    def test_16_empty_word(self, bash, functions):
         """An empty word should not take an option argument"""
         output = self._test(bash, "(a '' x '' y d)", 5, "a  x  y d", 8)
         assert output == "5"
diff --git a/test/t/unit/test_unit_dequote.py b/test/t/unit/test_unit_dequote.py
index 1c8a0f10..117a4877 100644
--- a/test/t/unit/test_unit_dequote.py
+++ b/test/t/unit/test_unit_dequote.py
@@ -9,123 +9,126 @@ from conftest import assert_bash_exec, bash_env_saved
     ignore_env=r"^\+declare -f __tester$",
 )
 class TestDequote:
-    def test_1_char(self, bash):
+    @pytest.fixture
+    def functions(self, bash):
         assert_bash_exec(
             bash,
             '__tester() { local REPLY=dummy v=var;_comp_dequote "$1";local ext=$?;((${#REPLY[@]}))&&printf \'<%s>\' "${REPLY[@]}";echo;return $ext;}',
         )
+
+    def test_1_char(self, bash, functions):
         output = assert_bash_exec(bash, "__tester a", want_output=True)
         assert output.strip() == "<a>"
 
-    def test_2_str(self, bash):
+    def test_2_str(self, bash, functions):
         output = assert_bash_exec(bash, "__tester abc", want_output=True)
         assert output.strip() == "<abc>"
 
-    def test_3_null(self, bash):
+    def test_3_null(self, bash, functions):
         output = assert_bash_exec(bash, "__tester ''", want_output=True)
         assert output.strip() == ""
 
-    def test_4_empty(self, bash):
+    def test_4_empty(self, bash, functions):
         output = assert_bash_exec(bash, "__tester \"''\"", want_output=True)
         assert output.strip() == "<>"
 
-    def test_5_brace(self, bash):
+    def test_5_brace(self, bash, functions):
         output = assert_bash_exec(bash, "__tester 'a{1..3}'", want_output=True)
         assert output.strip() == "<a1><a2><a3>"
 
-    def test_6_glob(self, bash):
+    def test_6_glob(self, bash, functions):
         output = assert_bash_exec(bash, "__tester 'a?b'", want_output=True)
         assert output.strip() == "<a b><a$b><a&b><a'b>"
 
-    def test_7_quote_1(self, bash):
+    def test_7_quote_1(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester '\"a\"'\\'b\\'\\$\\'c\\'", want_output=True
         )
         assert output.strip() == "<abc>"
 
-    def test_7_quote_2(self, bash):
+    def test_7_quote_2(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester '\\\"\\'\\''\\$\\`'", want_output=True
         )
         assert output.strip() == "<\"'$`>"
 
-    def test_7_quote_3(self, bash):
+    def test_7_quote_3(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester \\$\\'a\\\\tb\\'", want_output=True
         )
         assert output.strip() == "<a\tb>"
 
-    def test_7_quote_4(self, bash):
+    def test_7_quote_4(self, bash, functions):
         output = assert_bash_exec(
             bash, '__tester \'"abc\\"def"\'', want_output=True
         )
         assert output.strip() == '<abc"def>'
 
-    def test_7_quote_5(self, bash):
+    def test_7_quote_5(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester \\'abc\\'\\\\\\'\\'def\\'", want_output=True
         )
         assert output.strip() == "<abc'def>"
 
-    def test_8_param_1(self, bash):
+    def test_8_param_1(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '$v'", want_output=True)
         assert output.strip() == "<var>"
 
-    def test_8_param_2(self, bash):
+    def test_8_param_2(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '${v}'", want_output=True)
         assert output.strip() == "<var>"
 
-    def test_8_param_3(self, bash):
+    def test_8_param_3(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '${#v}'", want_output=True)
         assert output.strip() == "<3>"
 
-    def test_8_param_4(self, bash):
+    def test_8_param_4(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '${v[0]}'", want_output=True)
         assert output.strip() == "<var>"
 
-    def test_9_qparam_1(self, bash):
+    def test_9_qparam_1(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '\"$v\"'", want_output=True)
         assert output.strip() == "<var>"
 
-    def test_9_qparam_2(self, bash):
+    def test_9_qparam_2(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester '\"${v[@]}\"'", want_output=True
         )
         assert output.strip() == "<var>"
 
-    def test_10_pparam_1(self, bash):
+    def test_10_pparam_1(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '$?'", want_output=True)
         assert output.strip() == "<0>"
 
-    def test_10_pparam_2(self, bash):
+    def test_10_pparam_2(self, bash, functions):
         output = assert_bash_exec(bash, "__tester '${#1}'", want_output=True)
         assert output.strip() == "<5>"  # The string `${#1}` is five characters
 
-    def test_unsafe_1(self, bash):
+    def test_unsafe_1(self, bash, functions):
         output = assert_bash_exec(
             bash, "! __tester '$(echo hello >&2)'", want_output=True
         )
         assert output.strip() == ""
 
-    def test_unsafe_2(self, bash):
+    def test_unsafe_2(self, bash, functions):
         output = assert_bash_exec(
             bash, "! __tester '|echo hello >&2'", want_output=True
         )
         assert output.strip() == ""
 
-    def test_unsafe_3(self, bash):
+    def test_unsafe_3(self, bash, functions):
         output = assert_bash_exec(
             bash, "! __tester '>| important_file.txt'", want_output=True
         )
         assert output.strip() == ""
 
-    def test_unsafe_4(self, bash):
+    def test_unsafe_4(self, bash, functions):
         output = assert_bash_exec(
             bash, "! __tester '`echo hello >&2`'", want_output=True
         )
         assert output.strip() == ""
 
-    def test_glob_default(self, bash):
+    def test_glob_default(self, bash, functions):
         with bash_env_saved(bash) as bash_env:
             bash_env.shopt("failglob", False)
             bash_env.shopt("nullglob", False)
@@ -134,7 +137,7 @@ class TestDequote:
             )
             assert output.strip() == "<non-existent-*.txt>"
 
-    def test_glob_noglob(self, bash):
+    def test_glob_noglob(self, bash, functions):
         with bash_env_saved(bash) as bash_env:
             bash_env.set("noglob", True)
             output = assert_bash_exec(
@@ -144,7 +147,7 @@ class TestDequote:
             )
             assert output.strip() == "<non-existent-*.txt>"
 
-    def test_glob_failglob(self, bash):
+    def test_glob_failglob(self, bash, functions):
         with bash_env_saved(bash) as bash_env:
             bash_env.shopt("failglob", True)
             output = assert_bash_exec(
@@ -152,7 +155,7 @@ class TestDequote:
             )
             assert output.strip() == ""
 
-    def test_glob_nullglob(self, bash):
+    def test_glob_nullglob(self, bash, functions):
         with bash_env_saved(bash) as bash_env:
             bash_env.shopt("failglob", False)
             bash_env.shopt("nullglob", True)
diff --git a/test/t/unit/test_unit_get_first_arg.py b/test/t/unit/test_unit_get_first_arg.py
index 415e2178..823ee413 100644
--- a/test/t/unit/test_unit_get_first_arg.py
+++ b/test/t/unit/test_unit_get_first_arg.py
@@ -69,22 +69,22 @@ class TestUnitGetFirstArg:
         output = self._test(bash, "(a -b --foo d e f)", 5, '-a "@(-c|--foo)"')
         assert output == "e"
 
-    def test_9_skip_optarg_3(self, bash):
+    def test_9_skip_optarg_3(self, bash, functions):
         output = self._test(bash, "(a -b - c d e)", 5, '-a "-b"')
         assert output == "c"
 
-    def test_9_skip_optarg_4(self, bash):
+    def test_9_skip_optarg_4(self, bash, functions):
         output = self._test(bash, "(a -b -c d e f)", 5, '-a "-[bc]"')
         assert output == "d"
 
-    def test_9_skip_optarg_5(self, bash):
+    def test_9_skip_optarg_5(self, bash, functions):
         output = self._test(bash, "(a +o b c d)", 4, '-a "+o"')
         assert output == "c"
 
-    def test_9_skip_optarg_6(self, bash):
+    def test_9_skip_optarg_6(self, bash, functions):
         output = self._test(bash, "(a -o -o -o -o b c)", 6, '-a "-o"')
         assert output == "b"
 
-    def test_9_skip_optarg_7(self, bash):
+    def test_9_skip_optarg_7(self, bash, functions):
         output = self._test(bash, "(a -o -- -b -c d e)", 6, '-a "-o"')
         assert output == "d"
diff --git a/test/t/unit/test_unit_quote.py b/test/t/unit/test_unit_quote.py
index 35087825..fb621ac9 100644
--- a/test/t/unit/test_unit_quote.py
+++ b/test/t/unit/test_unit_quote.py
@@ -8,35 +8,38 @@ from conftest import TestUnitBase, assert_bash_exec
     ignore_env=r"^\+declare -f __tester$",
 )
 class TestUnitQuote(TestUnitBase):
-    def test_1(self, bash):
+    @pytest.fixture
+    def functions(self, bash):
         assert_bash_exec(
             bash,
             '__tester() { local REPLY; _comp_quote "$1"; printf %s "$REPLY"; }',
         )
+
+    def test_1(self, bash, functions):
         output = assert_bash_exec(
             bash, '__tester "a b"', want_output=True, want_newline=False
         )
         assert output.strip() == "'a b'"
 
-    def test_2(self, bash):
+    def test_2(self, bash, functions):
         output = assert_bash_exec(
             bash, '__tester "a  b"', want_output=True, want_newline=False
         )
         assert output.strip() == "'a  b'"
 
-    def test_3(self, bash):
+    def test_3(self, bash, functions):
         output = assert_bash_exec(
             bash, '__tester "  a "', want_output=True, want_newline=False
         )
         assert output.strip() == "'  a '"
 
-    def test_4(self, bash):
+    def test_4(self, bash, functions):
         output = assert_bash_exec(
             bash, "__tester \"a'b'c\"", want_output=True, want_newline=False
         )
         assert output.strip() == r"'a'\''b'\''c'"
 
-    def test_5(self, bash):
+    def test_5(self, bash, functions):
         output = assert_bash_exec(
             bash, '__tester "a\'"', want_output=True, want_newline=False
         )
-- 
2.47.1