Module: Bparity::Recording::CoverageTracker
- Defined in:
- lib/bparity/recording.rb
Class Method Summary collapse
Class Method Details
.finish(path) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/bparity/recording.rb', line 231 def finish(path) return unless Coverage.running? root = "#{File.(Dir.pwd)}#{File::SEPARATOR}" files = Coverage.result.filter_map do |file, data| next unless File.(file).start_with?(root) branches = data.fetch(:branches, {}).flat_map do |_base, children| children.map do |location, count| { "type" => location[0].to_s, "start_line" => location[2], "end_line" => location[4], "count" => count } end end { "path" => file, "lines" => data.fetch(:lines, []), "branches" => branches } end FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.pretty_generate("files" => files)) end |
.gaps(path, source_paths: []) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/bparity/recording.rb', line 250 def gaps(path, source_paths: []) allowed = source_paths.map { |source| File.(source) } JSON.parse(File.read(path)).fetch("files").flat_map do |file| next [] unless allowed.empty? || allowed.include?(File.(file.fetch("path"))) file.fetch("branches").filter_map do |branch| next unless branch.fetch("count").zero? { "kind" => "uncovered_branch", "location" => "#{file.fetch('path')}:#{branch.fetch('start_line')}" } end end rescue Errno::ENOENT raise ConfigurationError, "Cannot read coverage file #{path}. Run `bparity record` first." rescue JSON::ParserError, KeyError raise ConfigurationError, "Coverage file #{path} is invalid. Run `bparity record` again." end |
.running? ⇒ Boolean
223 |
# File 'lib/bparity/recording.rb', line 223 def running? = Coverage.running? |
.start ⇒ Object
225 226 227 228 229 |
# File 'lib/bparity/recording.rb', line 225 def start return if Coverage.running? Coverage.start(lines: true, branches: true) end |