1 # Copyright (C) 2017 all contributors <repobrowse@80x24.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 # frozen_string_literal: true
4 $stdout.sync = $stderr.sync = Thread.abort_on_exception = true
5 $-w = true if RUBY_VERSION.to_f >= 2.0
14 # fork-aware coverage data gatherer, see also test/covshow.rb
17 COVMATCH = %r{(/lib/repobrowse\b|extras/).*rb\z}
18 COVDUMPFILE = File.expand_path("coverage.dump")
23 # do not create the file, Makefile does this before any tests run
24 File.open(COVDUMPFILE, IO::RDWR) do |covtmp|
28 # we own this file (at least until somebody tries to use NFS :x)
29 covtmp.flock(File::LOCK_EX)
32 prev = prev.empty? ? {} : Marshal.load(prev)
33 res.each do |filename, counts|
34 # filter out stuff that's not in our project
35 COVMATCH =~ filename or next
37 # For compatibility with https://bugs.ruby-lang.org/issues/9508
38 # TODO: support those features if that gets merged into mainline
39 unless Array === counts
40 counts = counts[:lines]
43 merge = prev[filename] || []
45 counts.each_with_index do |count, i|
47 merge[i] = (merge[i] || 0) + count
49 prev[filename] = merge
53 covtmp.write(Marshal.dump(prev))
54 covtmp.flock(File::LOCK_UN)
59 # we need to nest at_exit to fire after minitest runs
60 at_exit { at_exit { __covmerge } }
64 Dir.mktmpdir do |tmp_dir|
65 git_dir = "#{tmp_dir}/tmp.git"
66 assert(system(*%W(git init -q --bare #{git_dir})), 'initialize git dir')
67 assert(system(*%W(git --git-dir=#{git_dir} fast-import --quiet),
68 in: "#{File.dirname(__FILE__)}/git.fast-import-data"),
69 'fast-import test repo')
70 yield tmp_dir, git_dir
79 Logger: WEBrick::Log.new(logq),
82 Port: 0, # WEBrick will choose a random port
85 config[:AccessLog] = [] unless test_verbose?
86 th = Thread.new do |s|
87 srv = Rack::Server.new(config)
88 srv.start { |s| q.push(s) }
91 assert_instance_of WEBrick::HTTPServer, s
99 warn "W: #{l.inspect}"
102 yield logq, host, port
109 ENV['TEST_VERBOSE'].to_i != 0