From 70783052560c344529bc736c95a6362af89a17bf Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 9 Dec 2021 14:11:45 +0100 Subject: [PATCH] print exception for tests (if occur or -v) --- bin/example.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/example.rb b/bin/example.rb index 3b9c839..006c188 100755 --- a/bin/example.rb +++ b/bin/example.rb @@ -41,6 +41,11 @@ class Capture STDERR.printf "[% 4d] \e[1;31mer\e[0m %s tests %s\e[J\n", @counter, $0.shellescape, command.shelljoin end + def logexception prefix, exception + loginfo "#{prefix} (#{exception.class.name}) #{exception}" + exception.backtrace[0...-Kernel.caller.length].each {|l| loginfo " #{l}" } + end + def loginfo text STDERR.printf " %s\n", text end @@ -64,7 +69,7 @@ class Capture end rescue Object logfail command - loginfo "unexpected raise: (#{$!.class.name}) #$!" + logexception "unexpected raise:", $! STDERR.puts end @@ -76,16 +81,16 @@ class Capture if message === $!.message logok command if @verbose - loginfo "raised: (#{$!.class.name}) #$!" + logexception "raised:", $! STDERR.puts end else - loginfo "unexpected message: (#{$!.class.name}) #$!" + logexception "unexpected message:", $! STDERR.puts end rescue Object logfail command - loginfo "unexpected raised: (#{$!.class.name}) #$!" + logexception "unexpected raised:", $! STDERR.puts end end