1 # Copyright (C) 2019 Harald Sitter <sitter@kde.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 GLOBAL_COVERAGE_ROOT
= File
.dirname(__dir__
) # ../
20 # Simplecov is a bit meh and expects src and coverage to be under the
21 # same root. Since we get run through cmake that assumption absolutely
22 # doesn't hold true, so we'll need to figure out the coverage_dir relative
23 # to the root and the root must always be the source :/
24 # The relativity only works because internally the path gets expanded, this
25 # isn't fully reliable, but oh well...
26 # https://github.com/colszowka/simplecov/issues/716
27 GLOBAL_COVERAGE_DIR
= begin
29 src_path
= Pathname
.new(GLOBAL_COVERAGE_ROOT
)
30 coverage_path
= Pathname
.new(File
.join(Dir
.pwd
, 'coverage'))
31 coverage_path
.relative_path_from(src_path
).to_s
37 SimpleCov
.formatter
= SimpleCov
::Formatter::MultiFormatter.new(
39 SimpleCov
::Formatter::HTMLFormatter
44 root GLOBAL_COVERAGE_ROOT
45 coverage_dir GLOBAL_COVERAGE_DIR
48 warn
'SimpleCov not loaded'
51 # FIXME: add coverage report for jenkins?
53 $LOAD_PATH.unshift(File
.absolute_path('../', __dir__
)) # ../
55 def __test_method_name__
56 return @method_name if defined?(:@method_name)
59 until caller
.start_with
?('test_')
60 caller
= caller_locations(index
, 1)[0].label
66 # system() variant which sets up merge-coverage. simplecov supports merging
67 # of multiple coverage sets. we use this to get coverage metrics on the
68 # binaries without having to refactor the script into runnable classes.
69 def covered_system(cmd
, *argv)
72 alias_method(:real_system, :system)
73 define_method(:system) do |*args
|
74 return true if args
.include?('kdialog') # disable kdialog call
82 root GLOBAL_COVERAGE_ROOT
83 coverage_dir GLOBAL_COVERAGE_DIR
84 command_name
"#{cmd}_#{__test_method_name__}"
87 warn
'SimpleCov not loaded'
91 load
"#{__dir__}/../#{cmd}"
92 puts
'all good, fork ending!'
95 waitedpid, status = Process.waitpid2(pid)
96 assert_equal(pid, waitedpid)
97 status.success? # behave like system and return the success only