tap-test 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.0 / 2009-12-05
2
+
3
+ Updates for Tap-0.19.0
4
+
1
5
  == 0.2.0 / 2009-06-17
2
6
 
3
7
  Updates for Tap-0.18.0
@@ -1,22 +1,21 @@
1
1
  Copyright (c) 2009, Regents of the University of Colorado.
2
2
 
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
3
+ Copyright (c) 2009, Simon Chiang.
11
4
 
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
14
11
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
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 NONINFRINGEMENT. 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/README CHANGED
@@ -18,7 +18,6 @@ test modules into other test frameworks.
18
18
  documentation, development, and bug tracking.
19
19
 
20
20
  * Website[http://tap.rubyforge.org]
21
- * Lighthouse[http://bahuvrihi.lighthouseapp.com/projects/9908-tap-task-application/tickets]
22
21
  * Github[http://github.com/bahuvrihi/tap/tree/master]
23
22
  * {Google Group}[http://groups.google.com/group/ruby-on-tap]
24
23
 
@@ -111,13 +110,11 @@ Sets up Tap::App.instance for testing tasks.
111
110
 
112
111
  == Installation
113
112
 
114
- Tap-Test is available as a gem on RubyForge[http://rubyforge.org/projects/tap]. Use:
113
+ Tap-Test is available as a gem on Gemcutter[http://gemcutter.org/gems/tap-test].
115
114
 
116
115
  % gem install tap-test
117
116
 
118
117
  == Info
119
118
 
120
- Copyright (c) 2009, Regents of the University of Colorado.
121
- Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
122
- Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
119
+ Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com]
123
120
  License:: {MIT-Style}[link:files/MIT-LICENSE.html]
@@ -38,6 +38,11 @@ module Tap
38
38
  include Tap::Test::FileTest
39
39
 
40
40
  options[:root] ||= test_root_dir
41
+
42
+ if options.has_key?(:cleanup_dirs)
43
+ self.cleanup_dirs = options.delete(:cleanup_dirs)
44
+ end
45
+
41
46
  self.class_test_root = Tap::Root.new(options)
42
47
  end
43
48
 
@@ -1,22 +1,5 @@
1
- if RUBY_PLATFORM =~ /mswin32/
2
- begin
3
- require 'rubygems'
4
- require 'win32/open3'
5
- rescue(LoadError)
6
- puts %q{
7
- Tap:Test::ShellTest requires the win32-open3 gem on Windows.
8
- Use this command and try again:
9
-
10
- % gem install win32-open3
11
-
12
- }
13
- raise
14
- end
15
- else
16
- require 'open3'
17
- end
18
-
19
1
  require 'tap/test/shell_test/class_methods'
2
+ require 'tap/test/shell_test/regexp_escape'
20
3
 
21
4
  module Tap
22
5
  module Test
@@ -67,19 +50,25 @@ module Tap
67
50
  # setup in an including module.
68
51
  def setup
69
52
  super
70
- @shell_test_notification = false
53
+ @notify_method_name = true
71
54
  end
72
55
 
73
56
  # Returns true if the ENV variable 'VERBOSE' is true. When verbose,
74
57
  # ShellTest prints the expanded commands of sh_test to $stdout.
75
58
  def verbose?
76
- ENV['VERBOSE'] == 'true'
59
+ verbose = ENV['VERBOSE']
60
+ verbose && verbose =~ /^true$/i ? true : false
77
61
  end
78
62
 
79
63
  # Returns true if the ENV variable 'QUIET' is true. When quiet,
80
64
  # ShellTest does not print any extra information to $stdout.
65
+ #
66
+ # If 'VERBOSE' and 'QUIET' are both set, verbose wins.
81
67
  def quiet?
82
- ENV['QUIET'] == 'true'
68
+ return false if verbose?
69
+
70
+ quiet = ENV['QUIET']
71
+ quiet && quiet =~ /^true$/i ? true : false
83
72
  end
84
73
 
85
74
  # Sets the specified ENV variables for the duration of the block.
@@ -115,11 +104,30 @@ module Tap
115
104
  #
116
105
  # % gem install win32-open3
117
106
  #
118
- def sh(cmd)
119
- Open3.popen3(cmd) do |i,o,s|
120
- yield(i,o,s) if block_given?
121
- return o.read
107
+ def sh(cmd, options={})
108
+ if @notify_method_name && !quiet?
109
+ @notify_method_name = false
110
+ puts
111
+ puts method_name
112
+ end
113
+
114
+ original_cmd = cmd
115
+ if cmd_pattern = options[:cmd_pattern]
116
+ cmd = cmd.sub(cmd_pattern, options[:cmd].to_s)
117
+ end
118
+
119
+ start = Time.now
120
+ result = with_env(options[:env], options[:replace_env]) do
121
+ IO.popen(cmd) do |io|
122
+ yield(io) if block_given?
123
+ io.read
124
+ end
122
125
  end
126
+
127
+ finish = Time.now
128
+ elapsed = "%.3f" % [finish-start]
129
+ puts " (#{elapsed}s) #{verbose? ? cmd : original_cmd}" unless quiet?
130
+ result
123
131
  end
124
132
 
125
133
  # Peforms a shell test. Shell tests execute the command and yield the
@@ -171,29 +179,24 @@ module Tap
171
179
  def sh_test(cmd, options={})
172
180
  options = sh_test_options.merge(options)
173
181
 
174
- unless quiet? || @shell_test_notification
175
- @shell_test_notification = true
176
- puts
177
- puts method_name
178
- end
182
+ cmd, expected = cmd.lstrip.split(/^/, 2)
183
+ cmd.strip!
184
+ result = sh(cmd, options)
179
185
 
180
- cmd, expected = cmd.lstrip.split(/\r?\n/, 2)
181
- original_cmd = cmd
182
-
183
- if cmd_pattern = options[:cmd_pattern]
184
- cmd = cmd.sub(cmd_pattern, options[:cmd].to_s)
185
- end
186
+ assert_equal(expected, result, cmd) if expected
187
+ yield(result) if block_given?
188
+ result
189
+ end
190
+
191
+ def sh_match(cmd, *regexps)
186
192
 
187
- start = Time.now
188
- result = with_env(options[:env], options[:replace_env]) do
189
- sh(cmd)
193
+ options = regexps.last.kind_of?(Hash) ? regexps.pop : {}
194
+ options = sh_test_options.merge(options)
195
+ result = sh(cmd, options)
196
+
197
+ regexps.each do |regexp|
198
+ assert_match regexp, result, cmd
190
199
  end
191
- finish = Time.now
192
-
193
- elapsed = "%.3f" % [finish-start]
194
- puts " (#{elapsed}s) #{verbose? ? cmd : original_cmd}" unless quiet?
195
-
196
- assert_equal(expected, result, cmd) if expected
197
200
  yield(result) if block_given?
198
201
  result
199
202
  end
@@ -203,6 +206,51 @@ module Tap
203
206
  def sh_test_options
204
207
  self.class.sh_test_options
205
208
  end
209
+
210
+ def assert_output_equal(a, b, msg=nil)
211
+ a = a[1..-1] if a[0] == ?\n
212
+ if a == b
213
+ assert true
214
+ else
215
+ flunk %Q{
216
+ #{msg}
217
+ ==================== expected output ====================
218
+ #{whitespace_escape(a)}
219
+ ======================== but was ========================
220
+ #{whitespace_escape(b)}
221
+ =========================================================
222
+ }
223
+ end
224
+ end
225
+
226
+ def assert_alike(a, b, msg=nil)
227
+ if b =~ a
228
+ assert true
229
+ else
230
+ flunk %Q{
231
+ #{msg}
232
+ ================= expected output like ==================
233
+ #{whitespace_escape(a)}
234
+ ======================== but was ========================
235
+ #{whitespace_escape(b)}
236
+ =========================================================
237
+ }
238
+ end
239
+ end
240
+
241
+ private
242
+
243
+ def whitespace_escape(str)
244
+ str.to_s.gsub(/\s/) do |match|
245
+ case match
246
+ when "\n" then "\\n\n"
247
+ when "\t" then "\\t"
248
+ when "\r" then "\\r"
249
+ when "\f" then "\\f"
250
+ else match
251
+ end
252
+ end
253
+ end
206
254
  end
207
255
  end
208
256
  end
@@ -9,7 +9,10 @@ module Tap
9
9
 
10
10
  # Returns a hash of the default sh_test options.
11
11
  def sh_test_options
12
- @sh_test_options ||= {}
12
+ @sh_test_options ||= {
13
+ :cmd_pattern => '% ',
14
+ :cmd => '2>&1 '
15
+ }
13
16
  end
14
17
 
15
18
  private
@@ -0,0 +1,88 @@
1
+ module Tap
2
+ module Test
3
+ module ShellTest
4
+ # RegexpEscape is a subclass of regexp that escapes all but the text in a
5
+ # special escape sequence. This allows the creation of complex regexps
6
+ # to match, for instance, console output.
7
+ #
8
+ # The RegexpEscape.escape (or equivalently the quote) method does the
9
+ # work; all regexp-active characters are escaped except for characters
10
+ # enclosed by ':.' and '.:' delimiters.
11
+ #
12
+ # RegexpEscape.escape('reg[exp]+ chars. are(quoted)') # => 'reg\[exp\]\+\ chars\.\ are\(quoted\)'
13
+ # RegexpEscape.escape('these are not: :.a(b*)c.:') # => 'these\ are\ not:\ a(b*)c'
14
+ #
15
+ # In addition, all-period regexps are automatically upgraded to '.*?';
16
+ # use the '.{n}' notation to specify n arbitrary characters.
17
+ #
18
+ # RegexpEscape.escape('_:..:_:...:_:....:') # => '_.*?_.*?_.*?'
19
+ # RegexpEscape.escape(':..{1}.:') # => '.{1}'
20
+ #
21
+ # RegexpEscape instances are initialized using the escaped input string
22
+ # and return the original string upon to_s.
23
+ #
24
+ # str = %q{
25
+ # a multiline
26
+ # :...:
27
+ # example}
28
+ # r = RegexpEscape.new(str)
29
+ #
30
+ # r =~ %q{
31
+ # a multiline
32
+ # matching
33
+ # example} # => true
34
+ #
35
+ # r !~ %q{
36
+ # a failing multiline
37
+ # example} # => true
38
+ #
39
+ # r.to_s # => str
40
+ #
41
+ class RegexpEscape < Regexp
42
+
43
+ # matches the escape sequence
44
+ ESCAPE_SEQUENCE = /:\..*?\.:/
45
+
46
+ class << self
47
+
48
+ # Escapes regexp-active characters in str, except for character
49
+ # delimited by ':.' and '.:'. See the class description for
50
+ # details.
51
+ def escape(str)
52
+ substituents = []
53
+ str.scan(ESCAPE_SEQUENCE) do
54
+ regexp_str = $&[2...-2]
55
+ regexp_str = ".*?" if regexp_str =~ /^\.*$/
56
+ substituents << regexp_str
57
+ end
58
+ substituents << ""
59
+
60
+ splits = str.split(ESCAPE_SEQUENCE).collect do |split|
61
+ super(split)
62
+ end
63
+ splits << "" if splits.empty?
64
+
65
+ splits.zip(substituents).to_a.flatten.join
66
+ end
67
+
68
+ # Same as escape.
69
+ def quote(str)
70
+ escape(str)
71
+ end
72
+ end
73
+
74
+ # Generates a new RegexpEscape by escaping the str, using the same
75
+ # options as Regexp.
76
+ def initialize(str, *options)
77
+ super(RegexpEscape.escape(str), *options)
78
+ @original_str = str
79
+ end
80
+
81
+ # Returns the original string for self
82
+ def to_s
83
+ @original_str
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -173,7 +173,7 @@ module Tap
173
173
  #
174
174
  def subset_test(type, skip=type[0..0].downcase)
175
175
  type = type.upcase
176
- if run_subset?(type) || ENV[type]
176
+ if run_subset?(type) || ENV["#{type}_TEST"]
177
177
  if match_regexp?("#{type}_TEST", name.to_s)
178
178
  yield
179
179
  else
@@ -3,18 +3,26 @@ require 'tap/app'
3
3
  module Tap
4
4
  module Test
5
5
 
6
- # Simply sets up and tears down Tap::App.instance so that tests that
7
- # instantiate classes will not inadvertently smush over into one another.
6
+ # Sets up and tears down Tap::App.instance. This prevents tests that modify
7
+ # either from inadvertently conflicting with one another.
8
8
  module TapTest
9
9
 
10
10
  # The test specific app
11
11
  attr_reader :app
12
-
12
+
13
13
  def setup
14
14
  super
15
- @app = Tap::App.instance = Tap::App.new(:debug => true, :quiet => true)
15
+ Tap::App.instance = @app = Tap::App.new(app_config)
16
16
  end
17
-
17
+
18
+ def env_config
19
+ {:gems => :none, :root => @method_root || Dir.pwd}
20
+ end
21
+
22
+ def app_config
23
+ {:debug => true, :quiet => true, :env => Tap::Env.new(env_config)}
24
+ end
25
+
18
26
  def teardown
19
27
  Tap::App.instance = nil
20
28
  super
@@ -0,0 +1,9 @@
1
+ module Tap
2
+ module Test
3
+ MAJOR = 0
4
+ MINOR = 3
5
+ TINY = 0
6
+
7
+ VERSION="#{MAJOR}.#{MINOR}.#{TINY}"
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tap-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-17 00:00:00 -06:00
12
+ date: 2009-12-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.18.0
23
+ version: 0.19.0
24
24
  version:
25
25
  description:
26
26
  email: simon.a.chiang@gmail.com
@@ -38,17 +38,21 @@ files:
38
38
  - lib/tap/test/file_test/class_methods.rb
39
39
  - lib/tap/test/shell_test.rb
40
40
  - lib/tap/test/shell_test/class_methods.rb
41
+ - lib/tap/test/shell_test/regexp_escape.rb
41
42
  - lib/tap/test/subset_test.rb
42
43
  - lib/tap/test/subset_test/class_methods.rb
43
44
  - lib/tap/test/tap_test.rb
44
45
  - lib/tap/test/unit.rb
45
46
  - lib/tap/test/utils.rb
47
+ - lib/tap/test/version.rb
46
48
  - tap.yml
47
49
  - History
48
50
  - README
49
51
  - MIT-LICENSE
50
52
  has_rdoc: true
51
53
  homepage: http://tap.rubyforge.org/tap-test/
54
+ licenses: []
55
+
52
56
  post_install_message:
53
57
  rdoc_options:
54
58
  - --main
@@ -74,9 +78,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
78
  requirements: []
75
79
 
76
80
  rubyforge_project: tap
77
- rubygems_version: 1.3.1
81
+ rubygems_version: 1.3.5
78
82
  signing_key:
79
- specification_version: 2
83
+ specification_version: 3
80
84
  summary: Test modules for Tap
81
85
  test_files: []
82
86