difects 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CREDITS +21 -0
- data/LICENSE +15 -0
- data/bin/difects +25 -0
- data/lib/difects/auto.rb +17 -0
- data/lib/difects/inochi.rb +93 -0
- data/lib/difects/long.rb +25 -0
- data/lib/difects/mini.rb +92 -0
- data/lib/difects/spec.rb +31 -0
- data/lib/difects/unit.rb +101 -0
- data/lib/difects.rb +1169 -0
- data/man/man1/difects.1.gz +0 -0
- data/man.html +1191 -0
- metadata +94 -0
data/CREDITS
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
%#----------------------------------------------------------------------------
|
2
|
+
## AUTHORS
|
3
|
+
%#----------------------------------------------------------------------------
|
4
|
+
|
5
|
+
Suraj N. Kurapati
|
6
|
+
|
7
|
+
%#----------------------------------------------------------------------------
|
8
|
+
## CREDITS
|
9
|
+
%#----------------------------------------------------------------------------
|
10
|
+
|
11
|
+
François Beausoleil,
|
12
|
+
Gavin Sinclair,
|
13
|
+
Iñaki Baz Castillo,
|
14
|
+
Sean O'Halpin
|
15
|
+
|
16
|
+
%#----------------------------------------------------------------------------
|
17
|
+
## LICENSE
|
18
|
+
%#----------------------------------------------------------------------------
|
19
|
+
|
20
|
+
%# See the file named "LICENSE".
|
21
|
+
%< "LICENSE"
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
(the ISC license)
|
2
|
+
|
3
|
+
Copyright 2009 Suraj N. Kurapati <sunaku@gmail.com>
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/bin/difects
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'difects'
|
4
|
+
|
5
|
+
if ARGV.delete('-h') or ARGV.delete('--help')
|
6
|
+
# try to display UNIX version of help manual
|
7
|
+
man_path = File.join(DIFECTS::INSTDIR, 'man')
|
8
|
+
unless system 'man', '-M', man_path, '-a', 'difects'
|
9
|
+
# try to display HTML version of help manual
|
10
|
+
man_html = man_path + '.html'
|
11
|
+
unless %w[$BROWSER open start].any? {|b| system "#{b} #{man_html}" }
|
12
|
+
# no luck; direct user to project website
|
13
|
+
puts "See #{DIFECTS::WEBSITE}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
exit
|
17
|
+
elsif ARGV.delete('-v') or ARGV.delete('--version')
|
18
|
+
puts DIFECTS::VERSION
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
DIFECTS.debug = ARGV.delete('-d') || ARGV.delete('--debug')
|
23
|
+
|
24
|
+
require 'difects/auto'
|
25
|
+
ARGV.each {|glob| Dir[glob].each {|test| load test } }
|
data/lib/difects/auto.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Provides painless, automatic configuration of DIFECTS.
|
2
|
+
#
|
3
|
+
# Simply require() this file and DIFECTS will be available for use anywhere
|
4
|
+
# in your program and will execute all tests before your program exits.
|
5
|
+
|
6
|
+
require 'difects'
|
7
|
+
include DIFECTS
|
8
|
+
|
9
|
+
at_exit do
|
10
|
+
DIFECTS.start
|
11
|
+
|
12
|
+
# reflect number of failures in exit status
|
13
|
+
stats = DIFECTS.stats
|
14
|
+
fails = stats[:fail] + stats[:error]
|
15
|
+
|
16
|
+
exit [fails, 255].min
|
17
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module DIFECTS
|
2
|
+
|
3
|
+
##
|
4
|
+
# Official name of this project.
|
5
|
+
#
|
6
|
+
PROJECT = 'DIFECTS'
|
7
|
+
|
8
|
+
##
|
9
|
+
# Short single-line description of this project.
|
10
|
+
#
|
11
|
+
TAGLINE = 'Assertion testing library for Ruby'
|
12
|
+
|
13
|
+
##
|
14
|
+
# Address of this project's official home page.
|
15
|
+
#
|
16
|
+
WEBSITE = 'http://snk.tuxfamily.org/lib/difects/'
|
17
|
+
|
18
|
+
##
|
19
|
+
# Number of this release of this project.
|
20
|
+
#
|
21
|
+
VERSION = '3.0.0'
|
22
|
+
|
23
|
+
##
|
24
|
+
# Date of this release of this project.
|
25
|
+
#
|
26
|
+
RELDATE = '2010-07-24'
|
27
|
+
|
28
|
+
##
|
29
|
+
# Description of this release of this project.
|
30
|
+
#
|
31
|
+
def self.inspect
|
32
|
+
"#{PROJECT} #{VERSION} (#{RELDATE})"
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Location of this release of this project.
|
37
|
+
#
|
38
|
+
INSTDIR = File.expand_path('../../..', __FILE__)
|
39
|
+
|
40
|
+
##
|
41
|
+
# RubyGems required by this project during runtime.
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
#
|
45
|
+
# RUNTIME = {
|
46
|
+
# # this project needs exactly version 1.2.3 of the "an_example" gem
|
47
|
+
# "an_example" => [ "1.2.3" ],
|
48
|
+
#
|
49
|
+
# # this project needs at least version 1.2 (but not
|
50
|
+
# # version 1.2.4 or newer) of the "another_example" gem
|
51
|
+
# "another_example" => [ ">= 1.2" , "< 1.2.4" ],
|
52
|
+
#
|
53
|
+
# # this project needs any version of the "yet_another_example" gem
|
54
|
+
# "yet_another_example" => [],
|
55
|
+
# }
|
56
|
+
#
|
57
|
+
RUNTIME = {}
|
58
|
+
|
59
|
+
##
|
60
|
+
# RubyGems required by this project during development.
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
#
|
64
|
+
# DEVTIME = {
|
65
|
+
# # this project needs exactly version 1.2.3 of the "an_example" gem
|
66
|
+
# "an_example" => [ "1.2.3" ],
|
67
|
+
#
|
68
|
+
# # this project needs at least version 1.2 (but not
|
69
|
+
# # version 1.2.4 or newer) of the "another_example" gem
|
70
|
+
# "another_example" => [ ">= 1.2" , "< 1.2.4" ],
|
71
|
+
#
|
72
|
+
# # this project needs any version of the "yet_another_example" gem
|
73
|
+
# "yet_another_example" => [],
|
74
|
+
# }
|
75
|
+
#
|
76
|
+
DEVTIME = {
|
77
|
+
'inochi' => [ '>= 3.0.0', '< 4' ],
|
78
|
+
}
|
79
|
+
|
80
|
+
# establish gem version dependencies
|
81
|
+
if respond_to? :gem
|
82
|
+
[RUNTIME, DEVTIME].each do |deps|
|
83
|
+
deps.each do |gem_name, gem_version|
|
84
|
+
begin
|
85
|
+
gem gem_name, *Array(gem_version)
|
86
|
+
rescue LoadError => error
|
87
|
+
warn "#{self.inspect}: #{error}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/difects/long.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Provides long name aliases for DIFECTS's default abbreviated vocabulary.
|
2
|
+
|
3
|
+
require 'difects'
|
4
|
+
|
5
|
+
module DIFECTS
|
6
|
+
short_to_long = {
|
7
|
+
'D' => 'Describe',
|
8
|
+
'T' => 'True',
|
9
|
+
'F' => 'False',
|
10
|
+
'E' => 'Error',
|
11
|
+
'C' => 'Catch',
|
12
|
+
'S' => 'Share',
|
13
|
+
'I' => 'Inform',
|
14
|
+
}
|
15
|
+
|
16
|
+
short_to_long.each do |src, dst|
|
17
|
+
instance_methods(false).grep(/^#{src}\b/).each do |short|
|
18
|
+
long = short.to_s.sub(src, dst)
|
19
|
+
alias_method long, short
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# for hooks
|
24
|
+
Describe = D
|
25
|
+
end
|
data/lib/difects/mini.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# MiniTest emulation layer.
|
2
|
+
|
3
|
+
require 'difects'
|
4
|
+
require 'difects/spec'
|
5
|
+
require 'difects/unit'
|
6
|
+
|
7
|
+
module DIFECTS
|
8
|
+
instance_methods(false).each do |meth|
|
9
|
+
if meth =~ /^assert_not/
|
10
|
+
alias_method 'refute' + $', meth
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
:must => '::DIFECTS.assert',
|
17
|
+
:wont => '::DIFECTS.refute',
|
18
|
+
}.
|
19
|
+
each do |outer, inner|
|
20
|
+
#
|
21
|
+
# XXX: using eval() because Ruby 1.8 does
|
22
|
+
# not support default values and
|
23
|
+
# block parameters in define_method()
|
24
|
+
#
|
25
|
+
file, line = __FILE__, __LINE__ ; eval %{
|
26
|
+
class Object
|
27
|
+
def #{outer}_be_close_to other, message = nil
|
28
|
+
#{inner}_in_delta self, other, nil, message
|
29
|
+
end
|
30
|
+
|
31
|
+
def #{outer}_be_empty message = nil
|
32
|
+
#{inner}_empty self, message
|
33
|
+
end
|
34
|
+
|
35
|
+
def #{outer}_be_instance_of klass, message = nil
|
36
|
+
#{inner}_instance_of klass, self, message
|
37
|
+
end
|
38
|
+
|
39
|
+
def #{outer}_be_kind_of klass, message = nil
|
40
|
+
#{inner}_kind_of klass, self, message
|
41
|
+
end
|
42
|
+
|
43
|
+
def #{outer}_be_nil message = nil
|
44
|
+
#{inner}_nil self, message
|
45
|
+
end
|
46
|
+
|
47
|
+
def #{outer}_be_same_as other, message = nil
|
48
|
+
#{inner}_same self, other, message
|
49
|
+
end
|
50
|
+
|
51
|
+
def #{outer}_be_within_delta other, delta = nil, message = nil
|
52
|
+
#{inner}_in_delta self, other, delta, message
|
53
|
+
end
|
54
|
+
|
55
|
+
alias #{outer}_be_within_epsilon #{outer}_be_within_delta
|
56
|
+
|
57
|
+
def #{outer}_equal expected, message = nil
|
58
|
+
#{inner}_equal expected, self, message
|
59
|
+
end
|
60
|
+
|
61
|
+
def #{outer}_include item, message = nil
|
62
|
+
#{inner}_include item, self, message
|
63
|
+
end
|
64
|
+
|
65
|
+
def #{outer}_match pattern, message = nil
|
66
|
+
#{inner}_match pattern, self, message
|
67
|
+
end
|
68
|
+
|
69
|
+
def #{outer}_raise *args, &block
|
70
|
+
#{inner}_raise(*args, &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def #{outer}_respond_to query, message = nil
|
74
|
+
#{inner}_respond_to self, query, message
|
75
|
+
end
|
76
|
+
|
77
|
+
def #{outer}_send query, *args
|
78
|
+
#{inner}_send self, query, *args
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class Proc
|
83
|
+
def #{outer}_raise *args
|
84
|
+
#{inner}_raise(*args, &self)
|
85
|
+
end
|
86
|
+
|
87
|
+
def #{outer}_throw symbol, message = nil
|
88
|
+
#{inner}_throw symbol, message, &self
|
89
|
+
end
|
90
|
+
end
|
91
|
+
}, TOPLEVEL_BINDING, file, line
|
92
|
+
end
|
data/lib/difects/spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# RSpec emulation layer.
|
2
|
+
|
3
|
+
require 'difects'
|
4
|
+
|
5
|
+
module DIFECTS
|
6
|
+
alias describe D
|
7
|
+
alias context D
|
8
|
+
alias it D
|
9
|
+
|
10
|
+
def before what, &block
|
11
|
+
meth =
|
12
|
+
case what
|
13
|
+
when :each then :<
|
14
|
+
when :all then :<<
|
15
|
+
else raise ArgumentError, what
|
16
|
+
end
|
17
|
+
|
18
|
+
send meth, &block
|
19
|
+
end
|
20
|
+
|
21
|
+
def after what, &block
|
22
|
+
meth =
|
23
|
+
case what
|
24
|
+
when :each then :>
|
25
|
+
when :all then :>>
|
26
|
+
else raise ArgumentError, what
|
27
|
+
end
|
28
|
+
|
29
|
+
send meth, &block
|
30
|
+
end
|
31
|
+
end
|
data/lib/difects/unit.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Test::Unit emulation layer.
|
2
|
+
|
3
|
+
require 'difects'
|
4
|
+
|
5
|
+
module DIFECTS
|
6
|
+
alias test D
|
7
|
+
alias setup <
|
8
|
+
alias setup! <<
|
9
|
+
alias teardown >
|
10
|
+
alias teardown! >>
|
11
|
+
|
12
|
+
[
|
13
|
+
[:assert, nil, nil ],
|
14
|
+
[:assert_not, '!', 'not '],
|
15
|
+
].
|
16
|
+
each do |prefix, polarity, action|
|
17
|
+
#
|
18
|
+
# XXX: using eval() because Ruby 1.8 does
|
19
|
+
# not support default values and
|
20
|
+
# block parameters in define_method()
|
21
|
+
#
|
22
|
+
file, line = __FILE__, __LINE__ ; module_eval %{
|
23
|
+
alias #{prefix} T#{polarity}
|
24
|
+
alias #{prefix} T#{polarity}
|
25
|
+
|
26
|
+
def #{prefix}_empty collection, message = nil
|
27
|
+
message ||= 'collection must #{action}be empty'
|
28
|
+
T#{polarity}(message) { collection.empty? }
|
29
|
+
end
|
30
|
+
|
31
|
+
def #{prefix}_equal expected, actual, message = nil
|
32
|
+
message ||= 'actual must #{action}equal expected'
|
33
|
+
T#{polarity}(message) { actual == expected }
|
34
|
+
end
|
35
|
+
|
36
|
+
def #{prefix}_in_delta expected, actual, delta = nil, message = nil
|
37
|
+
message ||= 'actual must #{action}be within delta of expected'
|
38
|
+
delta ||= 0.001
|
39
|
+
|
40
|
+
T#{polarity}(message) do
|
41
|
+
Math.abs(expected - actual) <= Math.abs(delta)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
alias #{prefix}_in_epsilon #{prefix}_in_delta
|
46
|
+
|
47
|
+
def #{prefix}_include item, collection, message = nil
|
48
|
+
message ||= 'collection must #{action}include item'
|
49
|
+
T#{polarity}(messsage) { collection.include? item }
|
50
|
+
end
|
51
|
+
|
52
|
+
def #{prefix}_instance_of klass, object, message = nil
|
53
|
+
message ||= 'object must #{action}be an instance of class'
|
54
|
+
T#{polarity}(message) { object.instance_of? klass }
|
55
|
+
end
|
56
|
+
|
57
|
+
def #{prefix}_kind_of klass, object, message = nil
|
58
|
+
message ||= 'object must #{action}be a kind of class'
|
59
|
+
T#{polarity}(message) { object.kind_of? klass }
|
60
|
+
end
|
61
|
+
|
62
|
+
def #{prefix}_nil object, message = nil
|
63
|
+
message ||= 'object must #{action}be nil'
|
64
|
+
T#{polarity}(message) { object == nil }
|
65
|
+
end
|
66
|
+
|
67
|
+
def #{prefix}_match pattern, string, message = nil
|
68
|
+
message ||= 'string must #{action}match pattern'
|
69
|
+
T#{polarity}(message) { string =~ pattern }
|
70
|
+
end
|
71
|
+
|
72
|
+
def #{prefix}_same expected, actual, message = nil
|
73
|
+
message ||= 'actual must #{action}be same as expected'
|
74
|
+
T#{polarity}(message) { actual.equal? expected }
|
75
|
+
end
|
76
|
+
|
77
|
+
def #{prefix}_operator object, operator, operand, message = nil
|
78
|
+
message ||= 'object must #{action}support operator with operand'
|
79
|
+
T#{polarity} { object.__send__ operator, operand }
|
80
|
+
end
|
81
|
+
|
82
|
+
def #{prefix}_raise *args, &block
|
83
|
+
E#{polarity}(args.pop, *args, &block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def #{prefix}_respond_to object, query, message = nil
|
87
|
+
message ||= 'object must #{action}respond to query'
|
88
|
+
T#{polarity}(message) { object.respond_to? query }
|
89
|
+
end
|
90
|
+
|
91
|
+
def #{prefix}_throw symbol, message = nil, &block
|
92
|
+
C#{polarity}(message, symbol, &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
def #{prefix}_send object, query, *args
|
96
|
+
response = object.__send__(query, *args)
|
97
|
+
T#{polarity} { response }
|
98
|
+
end
|
99
|
+
}, file, line
|
100
|
+
end
|
101
|
+
end
|