Skip to content
Snippets Groups Projects
Commit fd2517ac authored by Julian C. Dunn's avatar Julian C. Dunn Committed by Mike Mackintosh
Browse files

Convert to Minitest.

parent aebc4361
No related branches found
No related tags found
No related merge requests found
require 'test_helper' require 'test_helper'
class IPv4Test < Test::Unit::TestCase class IPv4Test < Minitest::Test
def setup def setup
@klass = IPAddress::IPv4 @klass = IPAddress::IPv4
...@@ -73,25 +73,19 @@ class IPv4Test < Test::Unit::TestCase ...@@ -73,25 +73,19 @@ class IPv4Test < Test::Unit::TestCase
assert_instance_of @klass, ip assert_instance_of @klass, ip
end end
assert_instance_of IPAddress::Prefix32, @ip.prefix assert_instance_of IPAddress::Prefix32, @ip.prefix
assert_raise (ArgumentError) do assert_raises (ArgumentError) do
@klass.new @klass.new
end end
assert_nothing_raised do
@klass.new "10.0.0.0/8"
end
end end
def test_initialize_format_error def test_initialize_format_error
@invalid_ipv4.each do |i| @invalid_ipv4.each do |i|
assert_raise(ArgumentError) {@klass.new(i)} assert_raises(ArgumentError) {@klass.new(i)}
end end
assert_raise (ArgumentError) {@klass.new("10.0.0.0/asd")} assert_raises (ArgumentError) {@klass.new("10.0.0.0/asd")}
end end
def test_initialize_without_prefix def test_initialize_without_prefix
assert_nothing_raised do
@klass.new("10.10.0.0")
end
ip = @klass.new("10.10.0.0") ip = @klass.new("10.10.0.0")
assert_instance_of IPAddress::Prefix32, ip.prefix assert_instance_of IPAddress::Prefix32, ip.prefix
assert_equal 32, ip.prefix.to_i assert_equal 32, ip.prefix.to_i
...@@ -111,7 +105,7 @@ class IPv4Test < Test::Unit::TestCase ...@@ -111,7 +105,7 @@ class IPv4Test < Test::Unit::TestCase
end end
def test_initialize_should_require_ip def test_initialize_should_require_ip
assert_raise(ArgumentError) { @klass.new } assert_raises(ArgumentError) { @klass.new }
end end
def test_method_data def test_method_data
...@@ -400,8 +394,8 @@ class IPv4Test < Test::Unit::TestCase ...@@ -400,8 +394,8 @@ class IPv4Test < Test::Unit::TestCase
end end
def test_method_split def test_method_split
assert_raise(ArgumentError) {@ip.split(0)} assert_raises(ArgumentError) {@ip.split(0)}
assert_raise(ArgumentError) {@ip.split(257)} assert_raises(ArgumentError) {@ip.split(257)}
assert_equal @ip.network, @ip.split(1).first assert_equal @ip.network, @ip.split(1).first
...@@ -431,9 +425,8 @@ class IPv4Test < Test::Unit::TestCase ...@@ -431,9 +425,8 @@ class IPv4Test < Test::Unit::TestCase
end end
def test_method_subnet def test_method_subnet
assert_raise(ArgumentError) {@network.subnet(23)} assert_raises(ArgumentError) {@network.subnet(23)}
assert_raise(ArgumentError) {@network.subnet(33)} assert_raises(ArgumentError) {@network.subnet(33)}
assert_nothing_raised {@ip.subnet(30)}
arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26",
"172.16.10.192/26"] "172.16.10.192/26"]
assert_equal arr, @network.subnet(26).map {|s| s.to_string} assert_equal arr, @network.subnet(26).map {|s| s.to_string}
...@@ -444,7 +437,7 @@ class IPv4Test < Test::Unit::TestCase ...@@ -444,7 +437,7 @@ class IPv4Test < Test::Unit::TestCase
end end
def test_method_supernet def test_method_supernet
assert_raise(ArgumentError) {@ip.supernet(24)} assert_raises(ArgumentError) {@ip.supernet(24)}
assert_equal "0.0.0.0/0", @ip.supernet(0).to_string assert_equal "0.0.0.0/0", @ip.supernet(0).to_string
assert_equal "0.0.0.0/0", @ip.supernet(-2).to_string assert_equal "0.0.0.0/0", @ip.supernet(-2).to_string
assert_equal "172.16.10.0/23", @ip.supernet(23).to_string assert_equal "172.16.10.0/23", @ip.supernet(23).to_string
...@@ -546,7 +539,7 @@ class IPv4Test < Test::Unit::TestCase ...@@ -546,7 +539,7 @@ class IPv4Test < Test::Unit::TestCase
assert_equal prefix, res.prefix assert_equal prefix, res.prefix
assert_equal "#{ip}/#{prefix}", res.to_string assert_equal "#{ip}/#{prefix}", res.to_string
end end
assert_raise(ArgumentError){ @klass.parse_classful("192.168.256.257") } assert_raises(ArgumentError){ @klass.parse_classful("192.168.256.257") }
end end
end # class IPv4Test end # class IPv4Test
......
require 'test_helper' require 'test_helper'
class IPv6Test < Test::Unit::TestCase class IPv6Test < Minitest::Test
def setup def setup
@klass = IPAddress::IPv6 @klass = IPAddress::IPv6
...@@ -53,15 +53,12 @@ class IPv6Test < Test::Unit::TestCase ...@@ -53,15 +53,12 @@ class IPv6Test < Test::Unit::TestCase
def test_initialize def test_initialize
assert_instance_of @klass, @ip assert_instance_of @klass, @ip
@valid_ipv6.keys.each do |ip|
assert_nothing_raised {@klass.new ip}
end
@invalid_ipv6.each do |ip| @invalid_ipv6.each do |ip|
assert_raise(ArgumentError) {@klass.new ip} assert_raises(ArgumentError) {@klass.new ip}
end end
assert_equal 64, @ip.prefix assert_equal 64, @ip.prefix
assert_raise(ArgumentError) { assert_raises(ArgumentError) {
@klass.new "::10.1.1.1" @klass.new "::10.1.1.1"
} }
end end
...@@ -263,18 +260,18 @@ class IPv6Test < Test::Unit::TestCase ...@@ -263,18 +260,18 @@ class IPv6Test < Test::Unit::TestCase
compressed = "2001:db8:0:cd30::" compressed = "2001:db8:0:cd30::"
expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000" expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000"
assert_equal expanded, @klass.expand(compressed) assert_equal expanded, @klass.expand(compressed)
assert_not_equal expanded, @klass.expand("2001:0db8:0::cd3") refute_equal expanded, @klass.expand("2001:0db8:0::cd3")
assert_not_equal expanded, @klass.expand("2001:0db8::cd30") refute_equal expanded, @klass.expand("2001:0db8::cd30")
assert_not_equal expanded, @klass.expand("2001:0db8::cd3") refute_equal expanded, @klass.expand("2001:0db8::cd3")
end end
def test_classmethod_compress def test_classmethod_compress
compressed = "2001:db8:0:cd30::" compressed = "2001:db8:0:cd30::"
expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000" expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000"
assert_equal compressed, @klass.compress(expanded) assert_equal compressed, @klass.compress(expanded)
assert_not_equal compressed, @klass.compress("2001:0db8:0::cd3") refute_equal compressed, @klass.compress("2001:0db8:0::cd3")
assert_not_equal compressed, @klass.compress("2001:0db8::cd30") refute_equal compressed, @klass.compress("2001:0db8::cd30")
assert_not_equal compressed, @klass.compress("2001:0db8::cd3") refute_equal compressed, @klass.compress("2001:0db8::cd3")
end end
def test_classmethod_parse_data def test_classmethod_parse_data
...@@ -297,7 +294,7 @@ class IPv6Test < Test::Unit::TestCase ...@@ -297,7 +294,7 @@ class IPv6Test < Test::Unit::TestCase
end # class IPv6Test end # class IPv6Test
class IPv6UnspecifiedTest < Test::Unit::TestCase class IPv6UnspecifiedTest < Minitest::Test
def setup def setup
@klass = IPAddress::IPv6::Unspecified @klass = IPAddress::IPv6::Unspecified
...@@ -310,7 +307,6 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase ...@@ -310,7 +307,6 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase
end end
def test_initialize def test_initialize
assert_nothing_raised {@klass.new}
assert_instance_of @klass, @ip assert_instance_of @klass, @ip
end end
...@@ -331,7 +327,7 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase ...@@ -331,7 +327,7 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase
end # class IPv6UnspecifiedTest end # class IPv6UnspecifiedTest
class IPv6LoopbackTest < Test::Unit::TestCase class IPv6LoopbackTest < Minitest::Test
def setup def setup
@klass = IPAddress::IPv6::Loopback @klass = IPAddress::IPv6::Loopback
...@@ -344,7 +340,6 @@ class IPv6LoopbackTest < Test::Unit::TestCase ...@@ -344,7 +340,6 @@ class IPv6LoopbackTest < Test::Unit::TestCase
end end
def test_initialize def test_initialize
assert_nothing_raised {@klass.new}
assert_instance_of @klass, @ip assert_instance_of @klass, @ip
end end
...@@ -364,7 +359,7 @@ class IPv6LoopbackTest < Test::Unit::TestCase ...@@ -364,7 +359,7 @@ class IPv6LoopbackTest < Test::Unit::TestCase
end # class IPv6LoopbackTest end # class IPv6LoopbackTest
class IPv6MappedTest < Test::Unit::TestCase class IPv6MappedTest < Minitest::Test
def setup def setup
@klass = IPAddress::IPv6::Mapped @klass = IPAddress::IPv6::Mapped
...@@ -390,14 +385,11 @@ class IPv6MappedTest < Test::Unit::TestCase ...@@ -390,14 +385,11 @@ class IPv6MappedTest < Test::Unit::TestCase
end end
def test_initialize def test_initialize
assert_nothing_raised {@klass.new("::172.16.10.1")}
assert_instance_of @klass, @ip assert_instance_of @klass, @ip
@valid_mapped.each do |ip, u128| @valid_mapped.each do |ip, u128|
assert_nothing_raised {@klass.new ip}
assert_equal u128, @klass.new(ip).to_u128 assert_equal u128, @klass.new(ip).to_u128
end end
@valid_mapped_ipv6.each do |ip, u128| @valid_mapped_ipv6.each do |ip, u128|
assert_nothing_raised {@klass.new ip}
assert_equal u128, @klass.new(ip).to_u128 assert_equal u128, @klass.new(ip).to_u128
end end
end end
......
require 'test_helper' require 'test_helper'
class Prefix32Test < Test::Unit::TestCase class Prefix32Test < Minitest::Test
def setup def setup
@netmask0 = "0.0.0.0" @netmask0 = "0.0.0.0"
...@@ -89,12 +89,9 @@ class Prefix32Test < Test::Unit::TestCase ...@@ -89,12 +89,9 @@ class Prefix32Test < Test::Unit::TestCase
end end
def test_initialize def test_initialize
assert_raise (ArgumentError) do assert_raises (ArgumentError) do
@klass.new 33 @klass.new 33
end end
assert_nothing_raised do
@klass.new 8
end
assert_instance_of @klass, @klass.new(8) assert_instance_of @klass, @klass.new(8)
end end
...@@ -122,7 +119,7 @@ class Prefix32Test < Test::Unit::TestCase ...@@ -122,7 +119,7 @@ class Prefix32Test < Test::Unit::TestCase
end # class Prefix32Test end # class Prefix32Test
class Prefix128Test < Test::Unit::TestCase class Prefix128Test < Minitest::Test
def setup def setup
@u128_hash = { @u128_hash = {
...@@ -135,12 +132,9 @@ class Prefix128Test < Test::Unit::TestCase ...@@ -135,12 +132,9 @@ class Prefix128Test < Test::Unit::TestCase
end end
def test_initialize def test_initialize
assert_raise (ArgumentError) do assert_raises (ArgumentError) do
@klass.new 129 @klass.new 129
end end
assert_nothing_raised do
@klass.new 64
end
assert_instance_of @klass, @klass.new(64) assert_instance_of @klass, @klass.new(64)
end end
......
require 'test_helper' require 'test_helper'
class IPAddressTest < Test::Unit::TestCase class IPAddressTest < Minitest::Test
def setup def setup
@valid_ipv4 = "172.16.10.1/24" @valid_ipv4 = "172.16.10.1/24"
...@@ -38,17 +38,14 @@ class IPAddressTest < Test::Unit::TestCase ...@@ -38,17 +38,14 @@ class IPAddressTest < Test::Unit::TestCase
end end
def test_method_IPAddress def test_method_IPAddress
assert_nothing_raised {@method.call(@valid_ipv4)}
assert_nothing_raised {@method.call(@valid_ipv6)}
assert_nothing_raised {@method.call(@valid_mapped)}
assert_instance_of @ipv4class, @method.call(@valid_ipv4) assert_instance_of @ipv4class, @method.call(@valid_ipv4)
assert_instance_of @ipv6class, @method.call(@valid_ipv6) assert_instance_of @ipv6class, @method.call(@valid_ipv6)
assert_instance_of @mappedclass, @method.call(@valid_mapped) assert_instance_of @mappedclass, @method.call(@valid_mapped)
assert_raise(ArgumentError) {@method.call(@invalid_ipv4)} assert_raises(ArgumentError) {@method.call(@invalid_ipv4)}
assert_raise(ArgumentError) {@method.call(@invalid_ipv6)} assert_raises(ArgumentError) {@method.call(@invalid_ipv6)}
assert_raise(ArgumentError) {@method.call(@invalid_mapped)} assert_raises(ArgumentError) {@method.call(@invalid_mapped)}
assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[0]) assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[0])
assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[1]) assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[1])
......
require 'rubygems' require 'rubygems'
require 'minitest/autorun' require 'minitest/autorun'
require 'test/unit'
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'ipaddress' require 'ipaddress'
module Test::Unit if Minitest.const_defined?('Test')
# We're on Minitest 5+. Nothing to do here.
else
# Minitest 4 doesn't have Minitest::Test yet.
Minitest::Test = MiniTest::Unit::TestCase
end
module Minitest
class TestCase class Test
def self.must(name, &block) def self.must(name, &block)
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment