@@ -194,7 +194,11 @@ def assert_nothing_raised(*args)
194194 end
195195 if ( ( args . empty? && !as ) ||
196196 args . any? { |a | a . instance_of? ( Module ) ? e . is_a? ( a ) : e . class == a } )
197- msg = message ( msg ) { "Exception raised:\n <#{ mu_pp ( e ) } >" }
197+ msg = message ( msg ) {
198+ "Exception raised:\n <#{ mu_pp ( e ) } >\n " +
199+ "Backtrace:\n " +
200+ e . backtrace . map { |frame | " #{ frame } " } . join ( "\n " )
201+ }
198202 raise MiniTest ::Assertion , msg . call , bt
199203 else
200204 raise
@@ -287,13 +291,15 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o
287291 args = args . dup
288292 args . insert ( ( Hash === args . first ? 1 : 0 ) , "-w" , "--disable=gems" , *$:. map { |l | "-I#{ l } " } )
289293 stdout , stderr , status = EnvUtil . invoke_ruby ( args , src , capture_stdout , true , **opt )
294+ ensure
290295 if res_c
291296 res_c . close
292297 res = res_p . read
293298 res_p . close
294299 else
295300 res = stdout
296301 end
302+ raise if $!
297303 abort = status . coredump? || ( status . signaled? && ABORT_SIGNALS . include? ( status . termsig ) )
298304 assert ( !abort , FailDesc [ status , nil , stderr ] )
299305 self . _assertions += res [ /^assertions=(\d +)/ , 1 ] . to_i
@@ -450,6 +456,49 @@ def assert_raise_with_message(exception, expected, msg = nil, &block)
450456 ex
451457 end
452458
459+ # pattern_list is an array which contains regexp and :*.
460+ # :* means any sequence.
461+ #
462+ # pattern_list is anchored.
463+ # Use [:*, regexp, :*] for non-anchored match.
464+ def assert_pattern_list ( pattern_list , actual , message = nil )
465+ rest = actual
466+ anchored = true
467+ pattern_list . each_with_index { |pattern , i |
468+ if pattern == :*
469+ anchored = false
470+ else
471+ if anchored
472+ match = /\A #{ pattern } / . match ( rest )
473+ else
474+ match = pattern . match ( rest )
475+ end
476+ unless match
477+ msg = message ( msg ) {
478+ expect_msg = "Expected #{ mu_pp pattern } \n "
479+ if /\n [^\n ]/ =~ rest
480+ actual_mesg = +"to match\n "
481+ rest . scan ( /.*\n +/ ) {
482+ actual_mesg << ' ' << $&. inspect << "+\n "
483+ }
484+ actual_mesg . sub! ( /\+ \n \z / , '' )
485+ else
486+ actual_mesg = "to match " + mu_pp ( rest )
487+ end
488+ actual_mesg << "\n after #{ i } patterns with #{ actual . length - rest . length } characters"
489+ expect_msg + actual_mesg
490+ }
491+ assert false , msg
492+ end
493+ rest = match . post_match
494+ anchored = true
495+ end
496+ }
497+ if anchored
498+ assert_equal ( "" , rest )
499+ end
500+ end
501+
453502 def assert_warning ( pat , msg = nil )
454503 result = nil
455504 stderr = EnvUtil . with_default_internal ( pat . encoding ) {
0 commit comments