Skip to content

Commit

Permalink
undo somehow works now
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed May 20, 2024
1 parent 4754d4c commit 5f66226
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/parallel_tests/test/runtime_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class RuntimeLogger
@@prepared = false

class << self
def log_test_run(file)
def log_test_run(test)
prepare

result = nil
time = ParallelTests.delta { result = yield }
log(file, time)
log(test, time)

result
end
Expand Down Expand Up @@ -51,14 +51,20 @@ def prepare
File.write(logfile, '')
end

def log(file, time)
return unless file
def log(test, time)
return unless message = message(test, time)
with_locked_log do |logfile|
logfile.seek 0, IO::SEEK_END
logfile.puts "#{file.sub("#{Dir.pwd}/", "")}:#{time}"
logfile.seek(0, IO::SEEK_END)
logfile.puts message
end
end

def message(test, delta)
return unless method = test.public_instance_methods(true).detect { |m| m =~ /^test_/ }
filename = test.instance_method(method).source_location.first.sub("#{Dir.pwd}/", "")
"#{filename}:#{delta}"
end

def logfile
ParallelTests::Test::Runner.runtime_log
end
Expand All @@ -67,16 +73,18 @@ def logfile
end
end

if defined?(Minitest::Test) # Minitest 5
Minitest::Test.prepend(
Module.new do
def run(*)
ParallelTests::Test::RuntimeLogger.log_test_run(method(name).source_location.first) do
super
if defined?(Minitest::Runnable) # Minitest 5
class << Minitest::Runnable
prepend(
Module.new do
def run(*)
ParallelTests::Test::RuntimeLogger.log_test_run(self) do
super
end
end
end
end
)
)
end

class << Minitest
prepend(
Expand Down

0 comments on commit 5f66226

Please sign in to comment.