test-more 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gemspec +18 -0
  2. data/LICENSE +21 -0
  3. data/Rakefile +67 -0
  4. data/lib/test/more.rb +223 -0
  5. data/readme.rdoc +33 -0
  6. data/test/basic.t +13 -0
  7. metadata +53 -0
data/.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ GemSpec = Gem::Specification.new do |gem|
4
+ gem.name = 'test-more'
5
+ gem.version = '0.0.1'
6
+ gem.license = 'MIT'
7
+ gem.required_ruby_version = '>= 1.9.1'
8
+
9
+ gem.authors << 'Ingy döt Net'
10
+ gem.email = 'ingy@ingy.net'
11
+ gem.summary = "Port of Perl's Test::More TAP test framework"
12
+ gem.description = <<-'.'
13
+ Port of Perl's Test::More TAP test framework.
14
+ .
15
+ gem.homepage = 'http://acmeism.org'
16
+
17
+ gem.files = `git ls-files`.lines.map{|l|l.chomp}
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright © 2013 Ingy döt Net
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the ‘Software’), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ # Load Gem constants from the gemspec
2
+ GemSpecFile = '.gemspec'
3
+ load GemSpecFile
4
+ GemName = GemSpec.name
5
+ GemVersion = GemSpec.version
6
+ GemDir = "#{GemName}-#{GemVersion}"
7
+ GemFile = "#{GemDir}.gem"
8
+ DevNull = '2>/dev/null'
9
+
10
+ # Require the Rake libraries
11
+ require 'rake'
12
+ require 'rake/testtask'
13
+ require 'rake/clean'
14
+ if File.exists? 'test/testml.yaml'
15
+ if File.exists? 'lib/rake/testml.rb'
16
+ $:.unshift "#{Dir.getwd}/lib"
17
+ end
18
+ require 'rake/testml'
19
+ end
20
+
21
+ task :default => 'help'
22
+
23
+ CLEAN.include GemDir, GemFile, 'data.tar.gz', 'metadata.gz'
24
+
25
+ desc 'Run the tests'
26
+ task :test do
27
+ system 'prove test/'
28
+ end
29
+
30
+ desc 'Build the gem'
31
+ task :build => [:clean, :test] do
32
+ sh "gem build #{GemSpecFile}"
33
+ end
34
+
35
+ desc 'Install the gem'
36
+ task :install => [:build] do
37
+ sh "gem install #{GemFile}"
38
+ end
39
+
40
+ desc 'Build, unpack and inspect the gem'
41
+ task :distdir => [:build] do
42
+ sh "tar xf #{GemFile} #{DevNull}"
43
+ Dir.mkdir GemDir
44
+ Dir.chdir GemDir
45
+ sh "tar xzf ../data.tar.gz #{DevNull}"
46
+ puts "\n>>> Entering sub-shell for #{GemDir}..."
47
+ system ENV['SHELL']
48
+ end
49
+
50
+ desc 'Build and push the gem'
51
+ task :release => [:build] do
52
+ sh "gem push #{GemFile}"
53
+ end
54
+
55
+ desc 'Print a description of the gem'
56
+ task :desc do
57
+ puts "Gem: '#{GemName}' (version #{GemVersion})"
58
+ puts
59
+ puts GemSpec.description.gsub /^/, ' '
60
+ end
61
+
62
+ desc 'List the Rakefile tasks'
63
+ task :help do
64
+ puts 'The following rake tasks are available:'
65
+ puts
66
+ puts `rake -T`.gsub /^/, ' '
67
+ end
data/lib/test/more.rb ADDED
@@ -0,0 +1,223 @@
1
+ module Test
2
+ module More
3
+ def ok got, label
4
+ if got
5
+ pass label
6
+ else
7
+ failed label
8
+ end
9
+ end
10
+
11
+ def use_ok library, label
12
+ fail "Test::More##{__method__.to_s} not yet implemented"
13
+ end
14
+
15
+ def require_ok library, label
16
+ fail "Test::More##{__method__.to_s} not yet implemented"
17
+ end
18
+
19
+ def is got, want, label
20
+ if got.to_s == want.to_s
21
+ pass label
22
+ else
23
+ failed label
24
+ diag "\
25
+ got: '#{got}'
26
+ expected: '#{want}'"
27
+ end
28
+ end
29
+
30
+ def isnt got, dont, label
31
+ if got.to_s != want.to_s
32
+ pass label
33
+ else
34
+ failed label
35
+ diag "\
36
+ got: '#{got}'
37
+ expected: anything else"
38
+ end
39
+ end
40
+
41
+ def like got, regex, label
42
+ if got =~ regex
43
+ pass label
44
+ else
45
+ failed label
46
+ diag "Got: '#{got}'"
47
+ end
48
+ end
49
+
50
+ def unlike got, regex, label
51
+ if got !~ regex
52
+ pass label
53
+ else
54
+ failed label
55
+ diag "Got: '#{got}'"
56
+ end
57
+ end
58
+
59
+ def is_deeply got, want, label
60
+ fail "Test::More##{__method__.to_s} not yet implemented"
61
+ end
62
+
63
+ def cmp_ok got, want, label
64
+ fail "Test::More##{__method__.to_s} not yet implemented"
65
+ end
66
+
67
+ def skip reason
68
+ fail "Test::More##{__method__.to_s} not yet implemented"
69
+ end
70
+
71
+ def todo label
72
+ fail "Test::More##{__method__.to_s} not yet implemented"
73
+ end
74
+
75
+ def todo_skip got, want, label
76
+ fail "Test::More##{__method__.to_s} not yet implemented"
77
+ end
78
+
79
+ def pass label
80
+ $test_more.run_incr
81
+ if ! label.empty?
82
+ puts "ok #{$test_more.run} - #{label}"
83
+ $stderr.flush
84
+ else
85
+ puts "ok #{$test_more.run}"
86
+ end
87
+ $stdout.flush
88
+ end
89
+
90
+ def failed label
91
+ $test_more.run_incr
92
+ $test_more.failed_incr
93
+ if ! label.empty?
94
+ puts "not ok #{$test_more.run} - #{label}"
95
+ else
96
+ puts "not ok #{$test_more.run}"
97
+ end
98
+ $stdout.flush
99
+ end
100
+
101
+ def eq_array got, label
102
+ fail "Test::More##{__method__.to_s} not yet implemented"
103
+ end
104
+
105
+ def eq_hash got, label
106
+ fail "Test::More##{__method__.to_s} not yet implemented"
107
+ end
108
+
109
+ def eq_set got, label
110
+ fail "Test::More##{__method__.to_s} not yet implemented"
111
+ end
112
+
113
+ def plan cmd, arg
114
+ fail 'Usage: plan tests <number>' unless cmd and arg
115
+ if cmd == 'tests'
116
+ fail 'Plan must be a number' unless arg.to_s =~ /^-?[0-9]+$/
117
+ fail 'Plan must greater then 0' unless arg > 0
118
+ $test_more.plan = arg
119
+ puts "1..#{$test_more.plan}"
120
+ elsif cmd == 'skip_all'
121
+ puts "1..0 # SKIP #{arg}"
122
+ exit 0
123
+ else
124
+ fail 'Usage: plan tests <number>'
125
+ end
126
+ $stdout.flush
127
+ end
128
+
129
+ def done_testing count=nil
130
+ count ||= $test_more.run
131
+ puts "1..#{count}"
132
+ $stdout.flush
133
+ end
134
+
135
+ def can_ok method, label
136
+ fail "Test::More##{__method__.to_s} not yet implemented"
137
+ end
138
+
139
+ def isa_ok class_, label
140
+ fail "Test::More##{__method__.to_s} not yet implemented"
141
+ end
142
+
143
+ def new_ok class_, label
144
+ fail "Test::More##{__method__.to_s} not yet implemented"
145
+ end
146
+
147
+ def diag msg
148
+ fail unless msg
149
+ msg.gsub! /\n/, "\n# "
150
+ $stderr.puts "# #{msg}"
151
+ $stderr.flush
152
+ end
153
+
154
+ def note msg
155
+ fail unless msg
156
+ msg.gsub! /\n/, "\n# "
157
+ puts "# #{msg}"
158
+ $stdout.flush
159
+ end
160
+
161
+ def explain msg
162
+ fail "Test::More##{__method__.to_s} not yet implemented"
163
+ end
164
+
165
+ def subtest label, callback
166
+ fail "Test::More##{__method__.to_s} not yet implemented"
167
+ end
168
+
169
+ def BAIL_OUT reason
170
+ fail "Test::More##{__method__.to_s} not yet implemented"
171
+ end
172
+ end
173
+
174
+ class Test::Tap
175
+ attr_accessor :plan
176
+ attr_accessor :run
177
+ attr_accessor :failed
178
+
179
+ def initialize
180
+ @plan = 0
181
+ @run = 0
182
+ @failed = 0
183
+ end
184
+
185
+ def run_incr
186
+ @run += 1
187
+ end
188
+
189
+ def failed_incr
190
+ @failed += 1
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ $test_more = Test::Tap.new
197
+
198
+ def at_exit
199
+ t = $test_more
200
+ if t.plan == 0
201
+ if t.run > 0
202
+ $stderr.puts "# Tests were run but no plan was declared."
203
+ end
204
+ else
205
+ if t.run == 0
206
+ $stderr.puts "# No tests run!"
207
+ elsif t.run != t.plan
208
+ msg = "# Looks like you planned #{t.plan} tests but ran #{t.run}."
209
+ msg.gsub! /tests/, 'test' if t.plan == 1
210
+ $stderr.puts msg
211
+ end
212
+ end
213
+ exit_code = 0
214
+ if t.failed > 0
215
+ exit_code = t.failed
216
+ exit_code = 254 if exit_code > 254
217
+ local msg = "# Looks like you failed #{t.failed tests} of #{t.run} run."
218
+ msg.gsub! /tests/, 'test' if t.failed == 1
219
+ $stderr.puts msg
220
+ end
221
+ $stderr.flush
222
+ exit exit_code
223
+ end
data/readme.rdoc ADDED
@@ -0,0 +1,33 @@
1
+ = test-more - Test::More for Ruby
2
+
3
+ A port of Perl's ubiquitous Test::More TAP testing framework.
4
+
5
+ = Synopsis
6
+
7
+ Write files ending with +.t+ under +test/+, like +test/test1.t+:
8
+
9
+ #!/usr/bin/env ruby
10
+
11
+ $:.unshift "#{Dir.getwd}/lib"
12
+ require 'test/more'
13
+ include Test::More
14
+
15
+ # plan 'tests', 3
16
+
17
+ pass 'Yessss'
18
+ ok true, 'yup'
19
+ is 1, '1', 'one'
20
+
21
+ done_testing 3
22
+
23
+ Then run the tests with the +prove+ utility like this:
24
+
25
+ prove -v test/
26
+
27
+ You can test this gem with:
28
+
29
+ rake test
30
+
31
+ = Copyright
32
+
33
+ Copyright (c) 2013 Ingy döt Net. See LICENSE for further details.
data/test/basic.t ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift "#{Dir.getwd}/lib"
4
+ require 'test/more'
5
+ include Test::More
6
+
7
+ # plan 'tests', 3
8
+
9
+ pass 'Yessss'
10
+ ok true, 'yup'
11
+ is 1, '1', 'one'
12
+
13
+ done_testing 3
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test-more
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ingy döt Net
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Port of Perl''s Test::More TAP test framework.
15
+
16
+ '
17
+ email: ingy@ingy.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gemspec
23
+ - LICENSE
24
+ - Rakefile
25
+ - lib/test/more.rb
26
+ - readme.rdoc
27
+ - test/basic.t
28
+ homepage: http://acmeism.org
29
+ licenses:
30
+ - MIT
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.9.1
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Port of Perl's Test::More TAP test framework
53
+ test_files: []