Skip to content

Commit 86955f2

Browse files
committed
test/doc: add more tests of star behavior, and document it.
1 parent 9d5ae8e commit 86955f2

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

CHANGES.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- The semantics of stars in file patterns has been clarified in the docs. A
24+
leading or trailing star matches any number of path components, like a double
25+
star would. This is different than the behavior of a star in the middle of a
26+
pattern. This discrepancy was `identified by Sviatoslav Sydorenko
27+
<starbad_>`_, who `provided patient detailed diagnosis <pull 1650_>`_ and
28+
graciously agreed to a pragmatic resolution.
2429

30+
.. _starbad: https://github.com/nedbat/coveragepy/issues/1407#issuecomment-1631085209
31+
.. _pull 1650: https://github.com/nedbat/coveragepy/pull/1650
2532

2633
.. scriv-start-here
2734
@@ -32,7 +39,7 @@ Version 7.3.0 — 2023-08-12
3239

3340
- Added a :meth:`.Coverage.collect` context manager to start and stop coverage
3441
data collection.
35-
42+
3643
- Dropped support for Python 3.7.
3744

3845
- Fix: in unusual circumstances, SQLite cannot be set to asynchronous mode.

doc/_static/coverage.css

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ img.tideliftlogo {
6666
background: #efc;
6767
}
6868

69+
/* I'm not sure why I had to make this so specific to get it to take effect... */
70+
div.rst-content div.document div.wy-table-responsive table.docutils.align-default tbody tr td {
71+
vertical-align: top !important;
72+
}
73+
74+
/* And this doesn't work, and I guess I just have to live with it. */
75+
div.rst-content div.document div.wy-table-responsive table.docutils.align-default tbody tr td .line-block {
76+
margin-bottom: 0 !important;
77+
}
78+
6979
/* sphinx-code-tabs */
7080

7181
/* Some selectors here are extra-specific (.container) because this file comes

doc/source.rst

+58-6
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,67 @@ individual source lines. See :ref:`excluding` for details.
178178
File patterns
179179
-------------
180180

181-
File path patterns are used for include and omit, and for combining path
182-
remapping. They follow common shell syntax:
183-
184-
- ``*`` matches any number of file name characters, not including the directory
185-
separator.
181+
File path patterns are used for :ref:`include <config_run_include>` and
182+
:ref:`omit <config_run_omit>`, and for :ref:`combining path remapping
183+
<cmd_combine_remapping>`. They follow common shell syntax:
186184

187185
- ``?`` matches a single file name character.
188186

189-
- ``**`` matches any number of nested directory names, including none.
187+
- ``*`` matches any number of file name characters, not including the directory
188+
separator. As a special case, if a pattern starts with ``*/``, it is treated
189+
as ``**/``, and if a pattern ends with ``/*``, it is treated as ``/**``.
190+
191+
- ``**`` matches any number of nested directory names, including none. It must
192+
be used as a full component of the path, not as part of a word: ``/**/`` is
193+
allowed, but ``/a**/`` is not.
190194

191195
- Both ``/`` and ``\`` will match either a slash or a backslash, to make
192196
cross-platform matching easier.
197+
198+
- A pattern with no directory separators matches the file name in any
199+
directory.
200+
201+
Some examples:
202+
203+
.. list-table::
204+
:widths: 20 20 20
205+
:header-rows: 1
206+
207+
* - Pattern
208+
- Matches
209+
- Doesn't Match
210+
* - ``a*.py``
211+
- | anything.py
212+
| sub1/sub2/another.py
213+
- | cat.py
214+
* - ``sub/*/*.py``
215+
- | sub/a/main.py
216+
| sub/b/another.py
217+
- | sub/foo.py
218+
| sub/m1/m2/foo.py
219+
* - ``sub/**/*.py``
220+
- | sub/something.py
221+
| sub/a/main.py
222+
| sub/b/another.py
223+
| sub/m1/m2/foo.py
224+
- | sub1/anything.py
225+
| sub1/more/code/main.py
226+
* - ``*/sub/*``
227+
- | some/where/sub/more/something.py
228+
| sub/hello.py
229+
- | sub1/anything.py
230+
* - ``*/sub*/*``
231+
- | some/where/sub/more/something.py
232+
| sub/hello.py
233+
| sub1/anything.py
234+
- | some/more/something.py
235+
* - ``*/*sub/test_*.py``
236+
- | some/where/sub/test_everything.py
237+
| moresub/test_things.py
238+
- | some/where/sub/more/test_everything.py
239+
| more/test_things.py
240+
* - ``*/*sub/*sub/**``
241+
- | sub/sub/something.py
242+
| asub/bsub/more/thing.py
243+
| code/sub/sub/code.py
244+
- | sub/something.py

tests/test_files.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,24 @@ def globs_to_regex_params(
235235
),
236236
globs_to_regex_params(
237237
["*/foo"], case_insensitive=False, partial=True,
238-
matches=["abc/foo/hi.py", "foo/hi.py"],
238+
matches=["abc/foo/hi.py", "foo/hi.py", "abc/def/foo/hi.py"],
239239
nomatches=["abc/xfoo/hi.py"],
240240
),
241+
globs_to_regex_params(
242+
["*c/foo"], case_insensitive=False, partial=True,
243+
matches=["abc/foo/hi.py"],
244+
nomatches=["abc/xfoo/hi.py", "foo/hi.py", "def/abc/foo/hi.py"],
245+
),
246+
globs_to_regex_params(
247+
["foo/x*"], case_insensitive=False, partial=True,
248+
matches=["foo/x", "foo/xhi.py", "foo/x/hi.py"],
249+
nomatches=[],
250+
),
251+
globs_to_regex_params(
252+
["foo/x*"], case_insensitive=False, partial=False,
253+
matches=["foo/x", "foo/xhi.py"],
254+
nomatches=["foo/x/hi.py"],
255+
),
241256
globs_to_regex_params(
242257
["**/foo"],
243258
matches=["foo", "hello/foo", "hi/there/foo"],

0 commit comments

Comments
 (0)