code
stringlengths
1
1.73M
language
stringclasses
1 value
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'test/unit/util/observable' require 'test/unit/testresult' module Test module Unit module UI # Provides an interface to write any given U...
Ruby
#-- # # Original Author:: Nathaniel Talbott. # Author:: Kazuhiro NISHIYAMA. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # Copyright:: Copyright (c) 2003 Kazuhiro NISHIYAMA. All rights reserved. # License:: Ruby license. require 'tk' require 'test/unit/ui/testrunnermediator' require 't...
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'gtk' require 'test/unit/ui/testrunnermediator' require 'test/unit/ui/testrunnerutilities' module Test module Unit module UI module GTK # Runs a Test...
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'fox' require 'test/unit/ui/testrunnermediator' require 'test/unit/ui/testrunnerutilities' include Fox module Test module Unit module UI module Fox ...
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. module Test module Unit module UI SILENT = 0 PROGRESS_ONLY = 1 NORMAL = 2 VERBOSE = 3 # Provides some utilities common to most, if not all, ...
Ruby
#-- # # Author:: Kenta MURATA. # Copyright:: Copyright (c) 2000-2002 Kenta MURATA. All rights reserved. # License:: Ruby license. require "gtk2" require "test/unit/ui/testrunnermediator" require "test/unit/ui/testrunnerutilities" module Test module Unit module UI module GTK2 Gtk.init cla...
Ruby
#-- # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit/util/observable' module Test module Unit # Collects Test::Unit::Failure and Test::Unit::Error so that # they can be displayed to the user. To this end...
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. module Test module Unit # Thrown by Test::Unit::Assertions when an assertion fails. class AssertionFailedError < StandardError end end end
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. module Test module Unit module Util # Allows the storage of a Proc passed through '&' in a # hash. # # Note: this may be inefficient, since the hash...
Ruby
module Test module Unit module Util module BacktraceFilter TESTUNIT_FILE_SEPARATORS = %r{[\\/:]} TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3] TESTUNIT_RB_FILE = /\.rb\Z/ def filter_backtrace(backtrace, prefix=nil) return ["No backtrace"...
Ruby
#-- # # Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit/util/procwrapper' module Test module Unit module Util # This is a utility class that allows anything mixing # it in to notify a set of liste...
Ruby
require 'test/unit/testcase' require 'test/unit/autorunner' module Test # :nodoc: # # = Test::Unit - Ruby Unit Testing Framework # # == Introduction # # Unit testing is making waves all over the place, largely due to the # fact that it is a core practice of XP. While XP is great, unit testing # has b...
Ruby
require 'test/unit' require 'stringio' dir = File.expand_path(__FILE__) 2.times {dir = File.dirname(dir)} $:.replace([File.join(dir, "ruby")] | $:) require 'ut_eof' class TestStringIO < Test::Unit::TestCase include TestEOF def open_file(content) f = StringIO.new(content) yield f end alias open_file_rw ...
Ruby
require 'test/unit' require 'uri/mailto' module URI class TestMailTo < Test::Unit::TestCase def setup @u = URI::MailTo end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_build ok = [] bad = [] # RFC2368, 6. Examples # mailto:c...
Ruby
require 'test/unit' require 'uri/http' module URI class TestHTTP < Test::Unit::TestCase def setup end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse u = URI.parse('http://a') assert_kind_of(URI::HTTP, u) assert_equal(['http', ...
Ruby
require 'test/unit' require 'uri/ftp' module URI class TestFTP < Test::Unit::TestCase def setup end def test_parse url = URI.parse('ftp://user:pass@host.com/abc/def') assert_kind_of(URI::FTP, url) exp = [ 'ftp', 'user:pass', 'host.com', URI::FTP.default_port, 'abc/def', nil, ...
Ruby
require 'test/unit' require 'uri' module URI class TestGeneric < Test::Unit::TestCase def setup @url = 'http://a/b/c/d;p?q' @base_url = URI.parse(@url) end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse # 0 assert_kind_of(URI...
Ruby
require 'test/unit' require 'uri' module URI class TestCommon < Test::Unit::TestCase def setup end def teardown end def test_extract assert_equal(['http://example.com'], URI.extract('http://example.com')) assert_equal(['http://example.com'], URI.extract('(http://example.com)')) assert...
Ruby
require 'test/unit' require 'uri/ldap' module URI class TestLDAP < Test::Unit::TestCase def setup end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse url = 'ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn?base?(sn=ttate*)' u = URI.parse(url) ...
Ruby
require 'test/unit' require 'yaml/store' class YAMLStoreTest < Test::Unit::TestCase def setup @yamlstore_file = "yamlstore.tmp.#{Process.pid}" @yamlstore = YAML::Store.new(@yamlstore_file) end def teardown File.unlink(@yamlstore_file) rescue nil end def test_opening_new_file_in_readonly_mode_sh...
Ruby
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- # vim:sw=4:ts=4 # $Id: test_yaml.rb 16084 2008-04-19 11:45:39Z knu $ # require 'test/unit' require 'yaml' # [ruby-core:01946] module YAML_Tests StructTest = Struct::new( :c ) end class YAML_Unit_Tests < Test::Unit::TestCase # # Convert between ...
Ruby
require "monitor" require "thread" require "test/unit" class TestMonitor < Test::Unit::TestCase def setup @monitor = Monitor.new end def test_enter ary = [] queue = Queue.new th = Thread.start { queue.pop @monitor.enter for i in 6 .. 10 ary.push(i) Thread.pass ...
Ruby
#!/usr/bin/env ruby # # $RoughId: test.rb,v 1.4 2001/07/13 15:38:27 knu Exp $ # $Id: test_digest.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'test/unit' require 'digest' %w[digest/md5 digest/rmd160 digest/sha1 digest/sha2].each do |lib| begin require lib rescue LoadError end end module TestDigest Da...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2003 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'test/unit/failure' module Test::Unit class TestFailure < TestCase def test_display f = Failure.new("name", [%q{location:1 in 'l'}], "message1\nmessa...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit/testcase' require 'test/unit/testresult' module Test module Unit class TC_TestResult < TestCase def setup @my_result = TestResult.new @my...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' module Test module Unit class TC_Assertions < TestCase def check(value, message="") add_assertion if (!value) raise AssertionF...
Ruby
require 'test/unit' require 'test/unit/collector/dir' require 'pp' module Test module Unit module Collector class TestDir < TestCase class FileSystem class Directory def initialize(name, fs, parent=self, &block) @name = name @fs = fs @...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'test/unit/collector/objectspace' module Test module Unit module Collector class TC_ObjectSpace < TestCase def setup @tc1 = Cl...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' module Test module Unit class TC_TestCase < TestCase def test_creation tc = Class.new(TestCase) do def test_with_arguments(arg1, arg2)...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' module Test module Unit class TC_Error < TestCase TF_Exception = Struct.new('TF_Exception', :message, :backtrace) def test_display ex = TF...
Ruby
# Author:: Masaki Suketa. # Adapted by:: Nathaniel Talbott. # Copyright:: Copyright (c) Masaki Suketa. All rights reserved. # Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'rubyunit' module RUNIT class TestTestResult < RUNIT::TestCase def setup @r...
Ruby
# Author:: Masaki Suketa. # Adapted by:: Nathaniel Talbott. # Copyright:: Copyright (c) Masaki Suketa. All rights reserved. # Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'rubyunit' module RUNIT class TargetAssert include RUNIT::Assert end class T...
Ruby
# Author:: Masaki Suketa. # Adapted by:: Nathaniel Talbott. # Copyright:: Copyright (c) Masaki Suketa. All rights reserved. # Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'rubyunit' module RUNIT class DummyError < StandardError end class TestTestCase ...
Ruby
# Author:: Masaki Suketa. # Adapted by:: Nathaniel Talbott. # Copyright:: Copyright (c) Masaki Suketa. All rights reserved. # Copyright:: Copyright (c) 2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'rubyunit' module RUNIT class TestTestSuite < RUNIT::TestCase def setup @te...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit/util/observable' module Test module Unit module Util class TC_Observable < TestCase class TF_Observable include Observable ...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'test/unit/util/procwrapper' module Test module Unit module Util class TC_ProcWrapper < TestCase def munge_proc(&a_proc) retur...
Ruby
require 'test/unit' require 'test/unit/util/backtracefilter' module Test::Unit::Util class TestBacktraceFilter < Test::Unit::TestCase include BacktraceFilter def test_filter_backtrace backtrace = [%q{C:\some\old\path/test/unit/assertions.rb:44:in 'assert'}, %q{tc_thing.rb:4:in 'a'}, ...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' module Test module Unit class TC_TestSuite < TestCase def setup @testcase1 = Class.new(TestCase) do def test_succeed1 asse...
Ruby
# # test/strscan/test_stringscanner.rb # require 'strscan' require 'test/unit' class TestStringScanner < Test::Unit::TestCase def test_s_new s = StringScanner.new('test string') assert_instance_of StringScanner, s assert_equal false, s.eos? assert_equal false, s.tainted? str = 'test string' ...
Ruby
require 'test/unit/testsuite' require 'test/unit/testcase' require 'stringio' require 'tempfile' begin require 'zlib' rescue LoadError end if defined? Zlib class TestZlibDeflate < Test::Unit::TestCase def test_initialize z = Zlib::Deflate.new s = z.deflate("foo", Zlib::FINISH) assert_equal("...
Ruby
# $Id: test_dryrun.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'test/unit' require 'fileutils' class TestFileUtilsDryRun < Test::Unit::TestCase include FileUtils::DryRun def test_visibility FileUtils::METHODS.each do |m| assert_equal true, FileUtils::DryRun.respond_to?(m, true), ...
Ruby
# $Id: fileasserts.rb 11708 2007-02-12 23:01:19Z shyouhei $ module Test module Unit module Assertions # redefine def assert_same_file(from, to) _wrap_assertion { assert_block("file #{from} != #{to}") { File.read(from) == File.read(to) } } end ...
Ruby
# $Id: test_verbose.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'test/unit' require 'fileutils' class TestFileUtilsVerbose < Test::Unit::TestCase include FileUtils::Verbose def test_visibility FileUtils::METHODS.each do |m| assert_equal true, FileUtils::Verbose.respond_to?(m, true), ...
Ruby
# $Id: test_nowrite.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'fileutils' require 'fileasserts' require 'tmpdir' require 'test/unit' class TestFileUtilsNoWrite < Test::Unit::TestCase include FileUtils::NoWrite def test_visibility FileUtils::METHODS.each do |m| assert_equal true, FileUtils::NoWr...
Ruby
# $Id: test_fileutils.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'fileutils' require 'fileasserts' require 'pathname' require 'tmpdir' require 'test/unit' class TestFileUtils < Test::Unit::TestCase TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}" end prevdir = Dir.pwd tmproot = TestFileUtils::TMPROOT Dir.mkdir t...
Ruby
require 'test/unit' require 'securerandom' require 'tempfile' # This testcase does NOT aim to test cryptographically strongness and randomness. class TestSecureRandom < Test::Unit::TestCase def setup @it = SecureRandom end def test_s_random_bytes assert_equal(16, @it.random_bytes.size) 65.times do |...
Ruby
require 'test/unit' require 'kconv' class TestKconv < Test::Unit::TestCase EUC_STR = "\ \xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\ \xa5\xd7\xa5\xed\xa5\xb0\xa5\xe9\xa5\xdf\xa5\xf3\xa5\xb0\xb8\xc0\xb8\xec \x52\x75\x62\x79" UTF8_STR = "\ \xe3\x82\xaa\xe3\x83\x96\xe3\x82\xb8\xe3\x82\xa7\ \xe3\x...
Ruby
require 'test/unit' require 'nkf' class TestNKF < Test::Unit::TestCase EUC_STR = "\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\ \xa5\xb9\xa5\xaf\xa5\xea\xa5\xd7\xa5\xc8\xb8\xc0\xb8\xec\ Ruby" def test_guess str_euc = EUC_STR str_jis = NKF.nkf('-j', str_euc) assert_equal(::NKF::JIS,...
Ruby
require 'test/unit' require 'ostruct' class TC_OpenStruct < Test::Unit::TestCase def assert_not_respond_to(object, method, message="") _wrap_assertion do full_message = build_message(message, <<EOT, object, object.class, method) <?> of type <?> expected not to respond_to\\?<?>. EOT _wrap_assertion do...
Ruby
require 'timeout' module WEBrick_Testing class DummyLog < WEBrick::BasicLog def initialize() super(self) end def <<(*args) end end def start_server(config={}) raise "already started" if @__server @__started = false Thread.new { @__server = WEBrick::HTTPServer.new( { ...
Ruby
require 'test/unit' require "xmlrpc/datetime" class Test_DateTime < Test::Unit::TestCase def test_new dt = createDateTime() assert_instance_of(XMLRPC::DateTime, dt) end def test_new_exception assert_raises(ArgumentError) { XMLRPC::DateTime.new(4.5, 13, 32, 25, 60, 60) } assert_raises(ArgumentE...
Ruby
require 'test/unit' require "xmlrpc/marshal" class Test_Marshal < Test::Unit::TestCase # for test_parser_values class Person include XMLRPC::Marshallable attr_reader :name def initialize(name) @name = name end end def test1_dump_response assert_nothing_raised(NameError) { XMLR...
Ruby
require 'test/unit' require 'xmlrpc/datetime' require "xmlrpc/parser" require 'yaml' module GenericParserTest def datafile(base) File.join(File.dirname(__FILE__), "data", base) end def load_data(name) [File.read(datafile(name) + ".xml"), YAML.load(File.read(datafile(name) + ".expected"))] end def ...
Ruby
require 'test/unit' require 'time' require 'webrick' require File.join(File.dirname(__FILE__), 'webrick_testing') require "xmlrpc/server" require 'xmlrpc/client' class TestCookie < Test::Unit::TestCase include WEBrick_Testing def create_servlet s = XMLRPC::WEBrickServlet.new def s.logged_in_users @...
Ruby
require 'test/unit' require 'webrick' require File.join(File.dirname(__FILE__), 'webrick_testing') require "xmlrpc/server" require 'xmlrpc/client' class Test_Webrick < Test::Unit::TestCase include WEBrick_Testing def create_servlet s = XMLRPC::WEBrickServlet.new s.add_handler("test.add") do |a,b| a...
Ruby
require 'test/unit' require "xmlrpc/create" require "xmlrpc/parser" require "xmlrpc/config" class Test_Features < Test::Unit::TestCase def setup @params = [nil, {"test" => nil}, [nil, 1, nil]] end def test_nil_create XMLRPC::XMLWriter.each_installed_writer do |writer| c = XMLRPC::Create.new(write...
Ruby
require "test/unit" require "webrick" require "stringio" require File.join(File.dirname(__FILE__), "utils.rb") class WEBrick::TestFileHandler < Test::Unit::TestCase def default_file_handler(filename) klass = WEBrick::HTTPServlet::DefaultFileHandler klass.new(WEBrick::Config::HTTP, filename) end def wind...
Ruby
require "test/unit" require "net/http" require "tempfile" require "webrick" require "webrick/httpauth/basicauth" require File.join(File.dirname(__FILE__), "utils.rb") class TestWEBrickHTTPAuth < Test::Unit::TestCase def test_basic_auth TestWEBrick.start_httpserver{|server, addr, port| realm = "WEBrick's re...
Ruby
require "test/unit" require "net/http" require "webrick" require File.join(File.dirname(__FILE__), "utils.rb") class TestWEBrickHTTPServer < Test::Unit::TestCase def test_mount httpd = WEBrick::HTTPServer.new( :Logger => WEBrick::Log.new(TestWEBrick::NullWriter), :DoNotListen=>true ) httpd.mo...
Ruby
begin loadpath = $:.dup $:.replace($: | [File.expand_path("../ruby", File.dirname(__FILE__))]) require 'envutil' ensure $:.replace(loadpath) end require "webrick" begin require "webrick/https" rescue LoadError end require "webrick/httpproxy" module TestWEBrick NullWriter = Object.new def NullWriter.<<(ms...
Ruby
require "test/unit" require "webrick/httputils" class TestWEBrickHTTPUtils < Test::Unit::TestCase include WEBrick::HTTPUtils def test_normilize_path assert_equal("/foo", normalize_path("/foo")) assert_equal("/foo/bar/", normalize_path("/foo/bar/")) assert_equal("/", normalize_path("/f...
Ruby
require "webrick" require File.join(File.dirname(__FILE__), "utils.rb") require "test/unit" class TestWEBrickCGI < Test::Unit::TestCase def test_cgi accepted = started = stopped = 0 requested0 = requested1 = 0 config = { :CGIInterpreter => TestWEBrick::RubyBin, :DocumentRoot => File.dirname(_...
Ruby
require "test/unit" require "tempfile" require "webrick" require File.join(File.dirname(__FILE__), "utils.rb") class TestWEBrickServer < Test::Unit::TestCase class Echo < WEBrick::GenericServer def run(sock) while line = sock.gets sock << line end end end def test_server TestWEBr...
Ruby
require "test/unit" require "webrick/cookie" class TestWEBrickCookie < Test::Unit::TestCase def test_new cookie = WEBrick::Cookie.new("foo","bar") assert_equal("foo", cookie.name) assert_equal("bar", cookie.value) assert_equal("foo=bar", cookie.to_s) end def test_time cookie = WEBrick::Cooki...
Ruby
require "webrick" require "stringio" require "test/unit" class TestWEBrickHTTPRequest < Test::Unit::TestCase def test_parse_09 msg = <<-_end_of_message_ GET / foobar # HTTP/0.9 request don't have header nor entity body. _end_of_message_ req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)...
Ruby
require "test/unit" require "webrick/httpversion" class TestWEBrickHTTPVersion < Test::Unit::TestCase def setup @v09 = WEBrick::HTTPVersion.new("0.9") @v10 = WEBrick::HTTPVersion.new("1.0") @v11 = WEBrick::HTTPVersion.new("1.001") end def test_to_s() assert_equal("0.9", @v09.to_s) assert_equ...
Ruby
require "test/unit" require "webrick/accesslog" class TestWEBrickAccessLog < Test::Unit::TestCase def test_format format = "%{Referer}i and %{User-agent}i" params = {"i" => {"Referer" => "ref", "User-agent" => "agent"}} assert_equal("ref and agent", WEBrick::AccessLog.format(format, params)) end end
Ruby
#!ruby -d require "webrick/cgi" class TestApp < WEBrick::CGI def do_GET(req, res) res["content-type"] = "text/plain" if (p = req.path_info) && p.length > 0 res.body = p elsif (q = req.query).size > 0 res.body = q.keys.sort.collect{|key| q[key].list.sort.collect{|v| "#{key}=#...
Ruby
#!ruby -d require "webrick/cgi" class TestApp < WEBrick::CGI def do_GET(req, res) res["content-type"] = "text/plain" if (p = req.path_info) && p.length > 0 res.body = p elsif (q = req.query).size > 0 res.body = q.keys.sort.collect{|key| q[key].list.sort.collect{|v| "#{key}=#...
Ruby
require 'test/unit' class TestWhileuntil < Test::Unit::TestCase def test_while tmp = open("while_tmp", "w") tmp.print "tvi925\n"; tmp.print "tvi920\n"; tmp.print "vt100\n"; tmp.print "Amiga\n"; tmp.print "paper\n"; tmp.close tmp = open("while_tmp", "r") assert_instance_of(File, t...
Ruby
require 'test/unit' class TestEval < Test::Unit::TestCase # eval with binding def test_ev local1 = "local1" lambda { local2 = "local2" return binding }.call end def test_eval assert_nil(eval("")) $bad=false eval 'while false; $bad = true; print "foo\n" end' assert(!$bad...
Ruby
require 'test/unit' require 'tempfile' $:.replace([File.dirname(File.expand_path(__FILE__))] | $:) require 'envutil' class TestBeginEndBlock < Test::Unit::TestCase DIR = File.dirname(File.expand_path(__FILE__)) def q(content) "\"#{content}\"" end def test_beginendblock ruby = EnvUtil.rubybin targ...
Ruby
require 'test/unit' class TestDefined < Test::Unit::TestCase class Foo def foo p :foo end protected :foo def bar(f) yield(defined?(self.foo)) yield(defined?(f.foo)) end end def defined_test return !defined?(yield) end def test_defined $x = nil assert(defin...
Ruby
require 'test/unit' class TestCall < Test::Unit::TestCase def aaa(a, b=100, *rest) res = [a, b] res += rest if rest return res end def test_call assert_raises(ArgumentError) {aaa()} assert_raises(ArgumentError) {aaa} assert_equal([1, 100], aaa(1)) assert_equal([1, 2], aaa(1, 2)) ...
Ruby
require 'test/unit' require 'tmpdir' require 'tempfile' class TestIO < Test::Unit::TestCase def mkcdtmpdir Dir.mktmpdir {|d| Dir.chdir(d) { yield } } end def test_gets_rs r, w = IO.pipe w.print "\377xyz" w.close assert_equal("\377", r.gets("\377"), "[ruby-dev:24460]")...
Ruby
require 'test/unit' class TestFloat < Test::Unit::TestCase def test_float assert_equal(2, 2.6.floor) assert_equal(-3, (-2.6).floor) assert_equal(3, 2.6.ceil) assert_equal(-2, (-2.6).ceil) assert_equal(2, 2.6.truncate) assert_equal(-2, (-2.6).truncate) assert_equal(3, 2.6.round) assert...
Ruby
require 'test/unit' class TestConst < Test::Unit::TestCase TEST1 = 1 TEST2 = 2 module Const TEST3 = 3 TEST4 = 4 end module Const2 TEST3 = 6 TEST4 = 8 end def test_const self.class.class_eval { include Const } assert_equal([1,2,3,4], [TEST1,TEST2,TEST3,TEST4]) sel...
Ruby
require 'test/unit' module TestEOF def test_eof_0 open_file("") {|f| assert_equal("", f.read(0)) assert_equal("", f.read(0)) assert_equal("", f.read) assert_nil(f.read(0)) assert_nil(f.read(0)) } open_file("") {|f| assert_nil(f.read(1)) assert_equal("", f.read) ...
Ruby
require 'test/unit' class TestCase < Test::Unit::TestCase def test_case case 5 when 1, 2, 3, 4, 6, 7, 8 assert(false) when 5 assert(true) end case 5 when 5 assert(true) when 1..10 assert(false) end case 5 when 1..10 assert(true) else a...
Ruby
require 'test/unit' class TestArray < Test::Unit::TestCase def test_0_literal assert_equal([1, 2, 3, 4], [1, 2] + [3, 4]) assert_equal([1, 2, 1, 2], [1, 2] * 2) assert_equal("1:2", [1, 2] * ":") assert_equal([1, 2].hash, [1, 2].hash) assert_equal([2,3], [1,2,3] & [2,3,4]) assert_equal([1,2,...
Ruby
require 'test/unit' class TestIfunless < Test::Unit::TestCase def test_if_unless $x = 'test'; assert(if $x == $x then true else false end) $bad = false unless $x == $x $bad = true end assert(!$bad) assert(unless $x != $x then true else false end) end end
Ruby
require 'test/unit' class TestMath < Test::Unit::TestCase def test_math assert_equal(2, Math.sqrt(4)) self.class.class_eval { include Math } assert_equal(2, sqrt(4)) end end
Ruby
require 'test/unit' require 'tmpdir' require 'fileutils' class TestDir < Test::Unit::TestCase ROOT = File.join(Dir.tmpdir, "__test_dir__#{$$}") def setup Dir.mkdir(ROOT) for i in ?a..?z if i % 2 == 0 FileUtils.touch(File.join(ROOT, i.chr)) else FileUtils.mkdir(File.join(ROOT,...
Ruby
module EnvUtil def rubybin if ruby = ENV["RUBY"] return ruby end ruby = "ruby" rubyexe = ruby+".exe" 3.times do if File.exist? ruby and File.executable? ruby and !File.directory? ruby return File.expand_path(ruby) end if File.exist? rubyexe and File.executable? ruby...
Ruby
require 'test/unit' dir = File.dirname(File.expand_path(__FILE__)) orgpath = $:.dup begin $:.push(dir) require 'marshaltestlib' ensure $:.replace(orgpath) end class TestMarshal < Test::Unit::TestCase include MarshalTestLib def encode(o) stress, GC.stress = GC.stress, true Marshal.dump(o) ensure ...
Ruby
require 'test/unit' class TestObjectSpace < Test::Unit::TestCase def self.deftest_id2ref(obj) /:(\d+)/ =~ caller[0] file = $` line = $1.to_i code = <<"End" define_method("test_id2ref_#{line}") {\ o = ObjectSpace._id2ref(obj.object_id);\ assert_same(obj, o, "didn't round trip: \#{obj.i...
Ruby
def end1 END {} end end1 eval <<EOE def end2 END {} end EOE
Ruby
errout = ARGV.shift BEGIN { puts "b1" local_begin1 = "local_begin1" $global_begin1 = "global_begin1" ConstBegin1 = "ConstBegin1" } BEGIN { puts "b2" BEGIN { puts "b2-1" } } # for scope check raise if defined?(local_begin1) raise unless defined?($global_begin1) raise unless defined?(::ConstBegin1) ...
Ruby
require 'test/unit' class TestSymbol < Test::Unit::TestCase # [ruby-core:3573] def assert_eval_inspected(sym) n = sym.inspect assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(n))} end def test_inspect_invalid # 2) Symbol#inspect sometimes returns invalid symbol representations: asse...
Ruby
require 'test/unit' class TestInteger < Test::Unit::TestCase VS = [ -0x1000000000000000000000000000000000000000000000002, -0x1000000000000000000000000000000000000000000000001, -0x1000000000000000000000000000000000000000000000000, -0xffffffffffffffffffffffffffffffffffffffffffffffff, -0x10000000000...
Ruby
require 'test/unit' class TestClone < Test::Unit::TestCase module M001; end module M002; end module M003; include M002; end module M002; include M001; end module M003; include M002; end def test_clone foo = Object.new def foo.test "test" end bar = foo.clone def bar.test2 "t...
Ruby
require 'test/unit' require File.expand_path('envutil', File.dirname(__FILE__)) class TestString < Test::Unit::TestCase def check_sum(str, bits=16) sum = 0 str.each_byte {|c| sum += c} sum = sum & ((1 << bits) - 1) if bits != 0 assert_equal(sum, str.sum(bits)) end def test_sum assert_equal(0,...
Ruby
require 'test/unit' class TestVariable < Test::Unit::TestCase class Gods @@rule = "Uranus" def ruler0 @@rule end def self.ruler1 # <= per method definition style @@rule end class << self # <= multiple method definition style def ruler2 @@rule end end end ...
Ruby
require "test/unit" require "fileutils" require "tmpdir" class TestFileExhaustive < Test::Unit::TestCase def setup @dir = Dir.mktmpdir("rubytest-file") File.chown(-1, Process.gid, @dir) @file = make_tmp_filename("file") @zerofile = make_tmp_filename("zerofile") @nofile = make_tmp_filename("nofile...
Ruby
require 'test/unit' class TestAlias < Test::Unit::TestCase class Alias0 def foo; "foo" end end class Alias1<Alias0 alias bar foo def foo; "foo+" + super end end class Alias2<Alias1 alias baz foo undef foo end class Alias3<Alias2 def foo defined? super end def bar ...
Ruby
require 'test/unit' $:.replace([File.dirname(File.expand_path(__FILE__))] | $:) require 'ut_eof' require 'envutil' class TestPipe < Test::Unit::TestCase include TestEOF def open_file(content) r, w = IO.pipe w << content w.close begin yield r ensure r.close end end def test_...
Ruby
require 'test/unit' class TestBignum < Test::Unit::TestCase def fact(n) return 1 if n == 0 f = 1 while n>0 f *= n n -= 1 end return f end def test_bignum $x = fact(40) assert_equal($x, $x) assert_equal($x, fact(40)) assert($x < $x+2) assert($x > $x-2) asse...
Ruby
require 'test/unit' class TestSleep < Test::Unit::TestCase def test_sleep_5sec start = Time.now sleep 5 slept = Time.now-start assert_in_delta(5.0, slept, 0.1, "[ruby-core:18015]: longer than expected") end end
Ruby
__method__.to_s
Ruby
require 'test/unit' require 'timeout' require 'fcntl' class TestReadPartial < Test::Unit::TestCase def make_pipe r, w = IO.pipe begin yield r, w ensure r.close unless r.closed? w.close unless w.closed? end end def pipe make_pipe {|r, w| yield r, w } return unl...
Ruby