Class: Testprune::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/testprune/cli.rb

Overview

Command-line front end. Three real commands:

run     boots the target suite under coverage instrumentation -> run.json
report  analyzes run.json and prints grouped candidates (read-only)
apply   prompts for approval, then writes a removal patch (never edits in place)

Constant Summary collapse

NOISY_PATTERNS =
%w[selenium request piper integration].freeze
<<~TXT
  testprune — audit a Ruby test suite for redundant coverage

  Usage:
    testprune run [options] [-- <test command>]
    testprune report [options]
    testprune apply [options]

  Commands:
    run      Run the target suite instrumented; capture per-test coverage + timing
    report   Analyze captured data and print removal candidates (read-only)
    apply    Review candidates, ask for approval, emit a git-applyable patch

  Options:
    -s, --source PATH      Source dir to analyze (repeatable; default: app, lib)
    -o, --output DIR       Output dir for captured data (default: .testprune)
        --baseline FRAC    Treat units run by >= FRAC of tests as shared-setup
                           noise and subtract them (0..1; default 0.5; 0 to disable)
        --json             Emit machine-readable JSON (report only)
    -h, --help             Show this help
    -v, --version          Show version
TXT

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(argv) ⇒ Object



37
38
39
# File 'lib/testprune/cli.rb', line 37

def self.start(argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/testprune/cli.rb', line 41

def run(argv)
  argv = argv.dup
  command = argv.shift
  case command
  when 'run'            then cmd_run(argv)
  when 'report'         then cmd_report(argv)
  when 'apply'          then cmd_apply(argv)
  when '-v', '--version' then puts(Testprune::VERSION)
  when nil, '-h', '--help' then puts(BANNER)
  else
    warn("testprune: unknown command #{command.inspect}\n\n#{BANNER}")
    return 1
  end
  0
rescue Testprune::Error => e
  warn("testprune: #{e.message}")
  1
end