diff options
author | Naoto Ono <[email protected]> | 2024-07-06 18:20:41 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-07-08 10:15:04 +0900 |
commit | 5b7892545542c0d451cb1e14a1d85474ac46b537 (patch) | |
tree | 5867397f0cf6362e8f78066bbc614685fec43e0e /bootstraptest/runner.rb | |
parent | dface4427da99561a4578a4b92a8321bc2d6c023 (diff) |
Integrate Launchable into make btest
Diffstat (limited to 'bootstraptest/runner.rb')
-rwxr-xr-x | bootstraptest/runner.rb | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/bootstraptest/runner.rb b/bootstraptest/runner.rb index 764c4898dd..70805c3523 100755 --- a/bootstraptest/runner.rb +++ b/bootstraptest/runner.rb @@ -78,6 +78,7 @@ bt = Struct.new(:ruby, :platform, :timeout, :timeout_scale, + :launchable_test_reports ) BT = Class.new(bt) do def indent=(n) @@ -229,6 +230,19 @@ End exit true when /\A-j/ true + when /--launchable-test-reports=(.*)/ + if File.exist?($1) + # To protect files from overwritten, do nothing when the file exists. + return true + end + + require_relative '../tool/lib/test/unit/launchable' + BT.launchable_test_reports = writer = Launchable::JsonStreamWriter.new($1) + writer.write_array('testCases') + at_exit { + writer.close + } + true else false end @@ -345,6 +359,45 @@ def concurrent_exec_test end end +module Launchable + def show_progress(message = '') + faildesc, t = super + + if writer = BT.launchable_test_reports + if !faildesc + status = 'TEST_PASSED' + else + status = 'TEST_FAILED' + end + repo_path = File.expand_path("#{__dir__}/../") + relative_path = self.path.delete_prefix("#{repo_path}/") + # The test path is a URL-encoded representation. + # https://github.com/launchableinc/cli/blob/v1.81.0/launchable/testpath.py#L18 + test_path = {file: relative_path, testcase: self.id}.map{|key, val| + "#{encode_test_path_component(key)}=#{encode_test_path_component(val)}" + }.join('#') + writer.write_object( + { + testPath: test_path, + status: status, + duration: t, + createdAt: Time.now.to_s, + stderr: faildesc, + stdout: nil, + data: { + lineNumber: self.lineno + } + } + ) + end + end + + private + def encode_test_path_component component + component.to_s.gsub('%', '%25').gsub('=', '%3D').gsub('#', '%23').gsub('&', '%26') + end +end + def exec_test(paths) # setup load_test paths @@ -421,6 +474,7 @@ def target_platform end class Assertion < Struct.new(:src, :path, :lineno, :proc) + prepend Launchable @count = 0 @all = Hash.new{|h, k| h[k] = []} @errbuf = [] @@ -495,9 +549,9 @@ class Assertion < Struct.new(:src, :path, :lineno, :proc) $stderr.print "#{BT.progress_bs}#{BT.progress[BT_STATE.count % BT.progress.size]}" end - t = Time.now if BT.verbose + t = Time.now if BT.verbose || BT.launchable_test_reports faildesc, errout = with_stderr {yield} - t = Time.now - t if BT.verbose + t = Time.now - t if BT.verbose || BT.launchable_test_reports if !faildesc # success @@ -524,6 +578,8 @@ class Assertion < Struct.new(:src, :path, :lineno, :proc) $stderr.printf("%-*s%s", BT.width, path, BT.progress[BT_STATE.count % BT.progress.size]) end end + + [faildesc, t] rescue Interrupt $stderr.puts "\##{@id} #{path}:#{lineno}" raise |