From 1afc81c84f68956fc7193e7c042199fbb010126d Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Mon, 5 Feb 2024 20:24:18 +0900 Subject: [PATCH] benchmark-json: fix a bug that invalid JSON may be generated It's happen when multiple tests generate benchmarks. --- lib/grntest/reporters/benchmark-json-reporter.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/grntest/reporters/benchmark-json-reporter.rb b/lib/grntest/reporters/benchmark-json-reporter.rb index 92525fe..17ecb15 100644 --- a/lib/grntest/reporters/benchmark-json-reporter.rb +++ b/lib/grntest/reporters/benchmark-json-reporter.rb @@ -21,10 +21,6 @@ module Grntest module Reporters class BenchmarkJSONReporter < BaseReporter - def initialize(tester) - super - end - def on_start(result) puts(<<-JSON) { @@ -40,11 +36,12 @@ def on_start(result) "mhz_per_cpu": #{cpu_cycles_per_second / 1_000_000.0}, JSON end - puts(<<-JSON) + print(<<-JSON.chomp) "caches": [] }, "benchmarks": [ JSON + @first_benchmark = true end def on_worker_start(worker) @@ -79,6 +76,8 @@ def on_test_no_check(worker, result) def on_test_finish(worker, result) return if result.benchmarks.empty? + print(",") unless @first_benchmark + puts benchmarks = result.benchmarks.collect do |benchmark| name = "#{worker.suite_name}/#{result.test_name}" <<-JSON.chomp @@ -94,7 +93,8 @@ def on_test_finish(worker, result) } JSON end - puts(benchmarks.join(",\n")) + print(benchmarks.join(",\n")) + @first_benchmark = false end def on_suite_finish(worker) @@ -104,6 +104,7 @@ def on_worker_finish(worker) end def on_finish(result) + puts puts(<<-JSON) ] }