lib/spoom/cli/coverage.rb in spoom-1.1.11 vs lib/spoom/cli/coverage.rb in spoom-1.1.12

- old
+ new

@@ -1,10 +1,10 @@ # typed: true # frozen_string_literal: true -require_relative '../coverage' -require_relative '../timeline' +require_relative "../coverage" +require_relative "../timeline" module Spoom module Cli class Coverage < Thor include Helper @@ -25,10 +25,11 @@ snapshot = Spoom::Coverage.snapshot(path: path, rbi: options[:rbi], sorbet_bin: sorbet) snapshot.print save_dir = options[:save] return unless save_dir + FileUtils.mkdir_p(save_dir) file = "#{save_dir}/#{snapshot.commit_sha || snapshot.timestamp}.json" File.write(file, snapshot.to_json) say("\nSnapshot data saved under `#{file}`") end @@ -83,18 +84,19 @@ exit(1) end ticks.each_with_index do |sha, i| date = Spoom::Git.commit_time(sha, path: path) - say("Analyzing commit `#{sha}` - #{date&.strftime('%F')} (#{i + 1} / #{ticks.size})") + say("Analyzing commit `#{sha}` - #{date&.strftime("%F")} (#{i + 1} / #{ticks.size})") Spoom::Git.checkout(sha, path: path) snapshot = T.let(nil, T.nilable(Spoom::Coverage::Snapshot)) if options[:bundle_install] Bundler.with_unbundled_env do next unless bundle_install(path, sha) + snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet) end else snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet) end @@ -102,10 +104,11 @@ snapshot.print(indent_level: 2) say("\n") next unless save_dir + file = "#{save_dir}/#{sha}.json" File.write(file, snapshot.to_json) say(" Snapshot data saved under `#{file}`\n\n") end Spoom::Git.checkout(ref_before, path: path) @@ -159,23 +162,24 @@ def open(file = "spoom_report.html") unless File.exist?(file) say_error("No report file to open `#{file}`") say_error(<<~ERR, status: nil) - If you already generated a report under another name use #{blue('spoom coverage open PATH')}. + If you already generated a report under another name use #{blue("spoom coverage open PATH")}. - To generate a report run #{blue('spoom coverage report')}. + To generate a report run #{blue("spoom coverage report")}. ERR exit(1) end exec("open #{file}") end no_commands do def parse_time(string, option) return nil unless string + Time.parse(string) rescue ArgumentError say_error("Invalid date `#{string}` for option `#{option}` (expected format `YYYY-MM-DD`)") exit(1) end @@ -194,12 +198,12 @@ def message_no_data(file) say_error("No snapshot files found in `#{file}`") say_error(<<~ERR, status: nil) - If you already generated snapshot files under another directory use #{blue('spoom coverage report PATH')}. + If you already generated snapshot files under another directory use #{blue("spoom coverage report PATH")}. - To generate snapshot files run #{blue('spoom coverage timeline --save-dir spoom_data')}. + To generate snapshot files run #{blue("spoom coverage timeline --save")}. ERR end end end end