Skip to content

Commit 4f67a1a

Browse files
committed
chore(scanner): simplify console output by removing rule listing and duplication
1 parent e1c6391 commit 4f67a1a

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

scripts/version_scanner/tests/unit/test_version_scanner.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,21 @@ def test_main_stdout(capsys):
473473
main()
474474

475475
captured = capsys.readouterr()
476-
assert "=== Scan Results ===" in captured.out
477476
assert "test.py:1 [test] 3.7" in captured.out
478477

478+
479+
def test_main_does_not_print_rules(capsys):
480+
"""Test that main() does not print the list of loaded rules to stdout."""
481+
test_args = ['version_scanner.py', '-d', 'python', '-v', '3.7']
482+
with mock.patch('sys.argv', test_args):
483+
from version_scanner import main
484+
with mock.patch('version_scanner.scan_repository', return_value=[]):
485+
with pytest.raises(SystemExit):
486+
main()
487+
captured = capsys.readouterr()
488+
assert "explicit_version_string" not in captured.out
489+
490+
479491
def test_scan_file_truncation_bug(tmp_path):
480492
"""Test that searching for 3.1 does NOT match 3.10 (truncation bug)."""
481493
# Create a file with 3.10

scripts/version_scanner/version_scanner.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,7 @@ def main():
647647
config_manager = ConfigManager(args.config, args.dependency, args.version)
648648
rules = config_manager.load_config()
649649

650-
print(f"\nLoaded {len(rules)} rules:")
651-
for rule in rules:
652-
print(f" - {rule['name']}: {rule['pattern']}")
653-
650+
654651

655652

656653
# Load ignore file from script directory (Option A)
@@ -664,11 +661,8 @@ def main():
664661
all_matches = scan_repository(args.path, rules, target_packages, ignore_dirs, version_string=args.version)
665662

666663
print(f"\nFound {len(all_matches)} matches.")
667-
for m in all_matches[:10]: # Show first 10
668-
print(f" {m['file_path']}:{m['line_number']} [{m['rule_name']}] {m['matched_string']}")
669-
670-
if len(all_matches) > 10:
671-
print(f" ... and {len(all_matches) - 10} more matches.")
664+
for m in all_matches:
665+
print(format_for_console(m))
672666

673667
# Get and print summary counts
674668
rule_counts, package_counts = get_match_counts(all_matches)
@@ -689,10 +683,7 @@ def main():
689683
if args.upload:
690684
upload_to_drive(output_path, all_matches, github_repo=args.github_repo, branch=args.branch)
691685

692-
if args.stdout:
693-
print("\n=== Scan Results ===")
694-
for m in all_matches:
695-
print(format_for_console(m))
686+
696687

697688
# Distinct exit codes for CI/CD
698689
if all_matches and not args.soft_fail:

0 commit comments

Comments
 (0)