class Tryouts

def run_all *paths

def run_all *paths
  batches = paths.collect do |path|
    parse path
  end
  all, skipped_tests, failed_tests = 0, 0, 0
  skipped_batches, failed_batches = 0, 0
  msg 'Ruby %s @ %-40s' % [RUBY_VERSION, Time.now], $/
  if Tryouts.debug?
    Tryouts.debug "Found #{paths.size} files:"
    paths.each { |path| Tryouts.debug "  #{path}" }
    Tryouts.debug
  end
  batches.each do |batch|
    path = batch.path.gsub(/#{Dir.pwd}\/?/, '')
    vmsg '%-60s %s' % [path, '']
    before_handler = Proc.new do |t|
      if Tryouts.noisy && !Tryouts.fails
        vmsg Console.reverse(' %-58s ' % [t.desc.to_s])
        vmsg t.test.inspect, t.exps.inspect
      end
    end
    batch.run(before_handler) do |t|
      if t.failed?
        failed_tests += 1
        if Tryouts.noisy && Tryouts.fails
          vmsg Console.color(:red, t.failed.join($/)), $/
        else
          msg ' %s (%s:%s)' % [Console.color(:red, "FAIL"), path, t.exps.first]
        end
      elsif (t.skipped? || !t.run?) && !Tryouts.fails
        skipped_tests += 1
        if Tryouts.noisy
          vmsg Console.bright(t.skipped.join($/)), $/
        else
          msg ' SKIP (%s:%s)' % [path, t.exps.first]
        end
      elsif !Tryouts.fails
        if Tryouts.noisy
          vmsg Console.color(:green, t.passed.join($/)), $/
        else
          msg ' %s' % [Console.color(:green, 'PASS')]
        end
      end
      all += 1
    end
  end
  msg
  if all > 0
    suffix = 'tests passed'
    suffix << " (and #{skipped_tests} skipped)" if skipped_tests > 0
    msg cformat(all-failed_tests-skipped_tests, all-skipped_tests, suffix) if all-skipped_tests > 0
  end
  if batches.size > 1
    if batches.size-skipped_batches > 0
      suffix = "batches passed"
      suffix << " (and #{skipped_batches} skipped)" if skipped_batches > 0
      msg cformat(batches.size-skipped_batches-failed_batches, batches.size-skipped_batches, suffix)
    end
  end
  failed_tests # 0 means success
end