Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support include flag in diff-cover tool #355

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions diff_cover/diff_cover_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
IGNORE_UNSTAGED_HELP = "Ignores unstaged changes"
IGNORE_WHITESPACE = "When getting a diff ignore any and all whitespace"
EXCLUDE_HELP = "Exclude files, more patterns supported"
INCLUDE_HELP = "Files to include (glob pattern)"
SRC_ROOTS_HELP = "List of source directories (only for jacoco coverage reports)"
COVERAGE_FILE_HELP = "coverage report (XML or lcov.info)"
DIFF_RANGE_NOTATION_HELP = (
Expand Down Expand Up @@ -131,6 +132,10 @@ def parse_coverage_args(argv):
"--exclude", metavar="EXCLUDE", type=str, nargs="+", help=EXCLUDE_HELP
)

parser.add_argument(
"--include", metavar="INCLUDE", type=str, nargs="+", help=INCLUDE_HELP
)

parser.add_argument(
"--src-roots",
metavar="DIRECTORY",
Expand Down Expand Up @@ -191,6 +196,7 @@ def generate_coverage_report(
ignore_unstaged=False,
include_untracked=False,
exclude=None,
include=None,
src_roots=None,
diff_range_notation=None,
ignore_whitespace=False,
Expand All @@ -207,6 +213,7 @@ def generate_coverage_report(
ignore_unstaged=ignore_unstaged,
include_untracked=include_untracked,
exclude=exclude,
include=include,
)

xml_roots = [
Expand Down Expand Up @@ -285,6 +292,7 @@ def main(argv=None, directory=None):
ignore_unstaged=arg_dict["ignore_unstaged"],
include_untracked=arg_dict["include_untracked"],
exclude=arg_dict["exclude"],
include=arg_dict["include"],
src_roots=arg_dict["src_roots"],
diff_range_notation=arg_dict["diff_range_notation"],
ignore_whitespace=arg_dict["ignore_whitespace"],
Expand Down
20 changes: 14 additions & 6 deletions tests/test_diff_cover_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,23 @@ def test_parse_invalid_arg():
parse_coverage_args(argv)


def test_parse_with_exclude():
def _test_parse_with_path_patterns(name):
argv = ["reports/coverage.xml"]
arg_dict = parse_coverage_args(argv)
assert arg_dict.get("exclude") is None
assert arg_dict.get(f"{name}") is None

argv = ["reports/coverage.xml", "--exclude", "noneed/*.py"]
argv = ["reports/coverage.xml", f"--{name}", "noneed/*"]
arg_dict = parse_coverage_args(argv)
assert arg_dict.get("exclude") == ["noneed/*.py"]
assert arg_dict.get(f"{name}") == ["noneed/*"]

argv = ["reports/coverage.xml", "--exclude", "noneed/*.py", "other/**/*.py"]
argv = ["reports/coverage.xml", f"--{name}", "noneed/*", "other/**/*"]
arg_dict = parse_coverage_args(argv)
assert arg_dict.get("exclude") == ["noneed/*.py", "other/**/*.py"]
assert arg_dict.get(f"{name}") == ["noneed/*", "other/**/*"]


def test_parse_with_include():
_test_parse_with_path_patterns("include")


def test_parse_with_exclude():
_test_parse_with_path_patterns("exclude")