Sha256: 3ed3af18ce0351a95f92b934e930bad594a5821b2258ea942f1d6f8c71920ad5

Contents?: true

Size: 2 KB

Versions: 34

Compression:

Stored size: 2 KB

Contents

$silentTests = false
$testnum=0
$ntest=0
$failed = []
$curtestOK=true

module MiniRUnit
  class Failure
    def initialize(what, testnum, msg, where)
      @what, @testnum, @msg, @where = what, testnum, msg, where
    end

    def to_s
      sprintf("FAILED %s %d %s-- %s\n", @what, @testnum, @msg, @where)
    end
  end

  class Error
    def initialize(what, testnum, boom)
      @what, @testnum, @boom = what, testnum, boom
    end

    def to_s
      sprintf("EXCEPTION raised %s %d -- \n\tException: %s\n\t%s",
              @what, @testnum, @boom.to_s, @boom.backtrace.join("\n\t"))
    end
  end
end


def test_check(what)
  printf "%s : ", what unless $silentTests
  $what = what
  $testnum = 0
end

def test_ok(cond, msg="")
  $testnum+=1
  $ntest+=1
  if cond
    print "." unless $silentTests
  else
    where = caller.reject {|where| where =~ /minirunit/}[0]
    $failed.push(MiniRUnit::Failure.new($what, $testnum, msg, where))
    print "F" unless $silentTests
    $curtestOK=false
  end
end

def test_fail(msg="")
  test_ok(false, msg)
end

def test_equal(a,b)
 test_ok(a == b, "expected #{a.inspect}, found #{b.inspect}") 
end

def test_no_exception(&proc)
  raised = false
  begin
    proc.call
  rescue exception
    raised = x
  end
  test_ok(!raised, "unexpected exception #{raised}")	
end

def test_exception(type=Exception, &proc)
  raised = false
  begin
    proc.call
  rescue type=>e
    raised = true
  end
  test_ok(raised, "#{type} expected")
  e
end

def test_get_last_failed
  if $failed.empty?
    return nil
  end
  return $failed.last
end

def test_print_report
  puts
  puts "-" * 80
  $failed.each { |error| puts error }
  puts "-" * 80
  puts "Tests: #$ntest. (Ok: #{$ntest - $failed.size}; Failed: #{$failed.size})"
end

def test_load(test)
  begin
	$curtestOK=true
	load(test)
  rescue Exception => boom
	puts 'ERROR' unless $silentTests
	$failed.push(MiniRUnit::Error.new($what, $testnum, boom))
  else
	if $curtestOK
		puts 'OK' unless $silentTests
	else
		puts 'FAILED' unless $silentTests
	end
  end
end

Version data entries

34 entries across 34 versions & 5 rubygems

Version Path
saturnflyer-activerecord-jdbc-adapter-0.9.3 test/minirunit.rb
kb-activerecord-jdbc-adapter-0.9.7.1-java test/minirunit.rb
activerecord-jdbc-adapter-0.9.7-java test/minirunit.rb
activerecord-jdbc-adapter-0.9.6-java test/minirunit.rb
activerecord-jdbc-adapter-0.9.5-java test/minirunit.rb
activerecord-jdbc-adapter-0.9.4-java test/minirunit.rb
activerecord-jdbc-adapter-0.9.3-java test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.6 test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.5 test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.4 test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.3 test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.2 test/minirunit.rb
jpzwarte-activerecord-jdbc-adapter-0.9.2.1 test/minirunit.rb
activerecord-jdbc-adapter-0.9.0.1 test/minirunit.rb
activerecord-jdbc-adapter-0.9.2 test/minirunit.rb
ActiveRecord-JDBC-0.2.1 test/minirunit.rb
ActiveRecord-JDBC-0.2.3 test/minirunit.rb
ActiveRecord-JDBC-0.2.4 test/minirunit.rb
ActiveRecord-JDBC-0.0.1 test/minirunit.rb
ActiveRecord-JDBC-0.2.0 test/minirunit.rb