gemdev 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,67 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
+ require 'strscan'
3
4
 
4
- module Kernel
5
- alias development_gem_orginal_require require
5
+ module Gem
6
+ class Specification
7
+ # The full path to the gem (install path + full name).
8
+ #
9
+ # return:: [String] the full gem path
10
+ #
11
+ def full_gem_path
12
+ @full_gem_path || File.join(installation_path, "gems", full_name)
13
+ end
14
+
15
+ def full_gem_path=(input)
16
+ @full_gem_path = input
17
+ end
18
+ end
6
19
 
7
- def require(path)
8
- development_gem_orginal_require path
9
- rescue LoadError => load_error
10
- raise load_error unless Gem.require_development(path)
20
+ class Specification
21
+ def self.load_devel(path)
22
+ gemspecs = []
23
+ fail "NESTED Specification.load calls not allowed!" if @@gather
24
+ @@gather = proc do |gs|
25
+ gs.full_gem_path = path
26
+ gemspecs << gs
27
+ end
28
+
29
+ #full rakefile is not needed or desired... just gemspecs
30
+ data = File.read(File.join(path,"Rakefile"))
31
+ scanner = StringScanner.new(data)
32
+ specs = []
33
+ while scanner.skip_until(/Gem::Specification\.new do/)
34
+ start = scanner.pos - 25 # length of 'Gem::Specification.new do'
35
+ scanner.skip_until(/\send/)
36
+
37
+ specs << data[start..scanner.pos]
38
+ end
39
+
40
+ eval(specs.join("\n"))
41
+ gemspecs
42
+ ensure
43
+ @@gather = nil
44
+ end
11
45
  end
12
46
  end
13
47
 
14
- module Gem
15
- def self.require_development(path)
16
- #File.touch(config_file) if !File.exists?(config_file)
17
-
18
- config = YAML.load_file(config_file)
19
- return false unless config.kind_of?(Hash)
20
-
21
- development = config['development']
22
- return false if development.nil? || !development.has_key?(path)
48
+ # reset the gem path searcher
49
+ @gempath_searcher = nil
50
+
51
+ if File.exists?(Gem.config_file)
52
+ config = YAML.load_file(Gem.config_file)
53
+ devel = config['development']
54
+
55
+ # File.expand_path required to change windows filepaths to unix filepaths
56
+ paths = case devel
57
+ when Array then devel
58
+ when String then Dir.glob(File.expand_path(devel))
59
+ end.collect {|p| File.expand_path(p)}
23
60
 
24
- require development[path]
25
- true
61
+ paths.each do |path|
62
+ next if File.file?(path)
63
+ Gem::Specification.load_devel(path).each do |spec|
64
+ Gem.source_index.add_spec(spec)
65
+ end
26
66
  end
27
67
  end
@@ -9,10 +9,24 @@ require 'pp'
9
9
  class Test::Unit::TestCase
10
10
 
11
11
  class << self
12
+ # Causes a whole test suite to require one of the listed platforms
13
+ # in order to run. See match_platform? for details.
14
+ #
15
+ # Simply declare like:
16
+ #
17
+ # class Test::Unit::TestCase
18
+ # require_platform 'mswin'
19
+ # end
12
20
  def require_platform(*platforms)
13
21
  @platforms = platforms
14
22
  end
15
23
 
24
+ # Returns true if RUBY_PLATFORM matches one of the specfied
25
+ # platforms. Use the prefix 'non_' to specify any plaform but the
26
+ # specified platform (ex: 'non_mswin')
27
+ #
28
+ # Some common platforms:
29
+ # - mswin:: Windows
16
30
  def match_platform?(*platforms)
17
31
  platforms.each do |platform|
18
32
  platform.to_s =~ /^(non_)?(.*)/
@@ -32,6 +46,8 @@ class Test::Unit::TestCase
32
46
  if match_platform?(*@platforms)
33
47
  original_suite
34
48
  else
49
+ # if platforms are specfied for the tests and the platform does NOT
50
+ # match, remake the suite to skip all tests.
35
51
  method_names = public_instance_methods(true)
36
52
  suite = Test::Unit::TestSuite.new(name)
37
53
  method_names.each do |method_name|
@@ -43,9 +59,11 @@ class Test::Unit::TestCase
43
59
  end
44
60
  end
45
61
 
62
+ # Platform-specific test. Useful for specifying test that should only be run on,
63
+ # for instance, windows. See match_platform? for details.
46
64
  def platform_test(*platforms, &block)
47
65
  if self.class.match_platform?(*platforms)
48
- block.call
66
+ yield
49
67
  else
50
68
  print ' '
51
69
  end
@@ -57,12 +75,15 @@ class Test::Unit::TestCase
57
75
  subset_test("EXTENDED", "x", &block)
58
76
  end
59
77
 
60
- # Subset test declaration for benchmard tests -- type: BENCHMARK
78
+ # Subset test declaration for benchmark tests -- type: BENCHMARK
61
79
  # Prints 'b' unless run.
62
- def benchmark_test(&block)
80
+ def benchmark_test(length=10, &block)
63
81
  subset_test("BENCHMARK") do
82
+ puts
64
83
  puts calling_method
65
- block.call
84
+ bm(length) do |x|
85
+ yield(x)
86
+ end
66
87
  end
67
88
  end
68
89
 
@@ -89,16 +110,63 @@ class Test::Unit::TestCase
89
110
  end
90
111
  end
91
112
  end
113
+
114
+ # Acase tests take an array of testcases. Each testcase in the array will
115
+ # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
116
+ # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
117
+ # the testcase matches the provided regexp. Example:
118
+ #
119
+ # case_test(
120
+ # [1,2,3] ,
121
+ # '[1, 2, 3]',
122
+ # 'another testcase'
123
+ # ).do |testcase|
124
+ # ...your test code...
125
+ # end
126
+ #
127
+ # ENV['CASE_TEST']=true => all tests run
128
+ # ENV['CASE']='1, 2, 3' => first two tests run
129
+ # ENV['CASE']='another' => only last test runs
130
+ def acase_test(*array)
131
+ if match_regexp?("CASE_TEST", calling_method)
132
+ array.each do |testcase|
133
+ yield(testcase) if match_regexp?("CASE", testcase)
134
+ end
135
+ end
136
+ end
92
137
 
138
+
139
+ # Subset test declaration for prompt tests -- type: PROMPT
140
+ # Prints 'p' unless run.
141
+ #
142
+ # Useful for tests that require user input. If run, then this test will
143
+ # prompt the user for an input for each item in the array. The results
144
+ # are collected in a hash and passed to the block.
145
+ #
146
+ # Example:
147
+ #
148
+ # def test_something_important
149
+ # prompt_test(:a, :b, :c).do |config|
150
+ # ...your test code...
151
+ # end
152
+ # end
153
+ #
154
+ # (if run, prompts print to $stdout the following:)
155
+ # test_something_important: Enter values or 'skip'
156
+ # a: # => enter 'avalue'
157
+ # b: # => enter 'bvalue'
158
+ # c: # => enter 'cvalue'
159
+ #
160
+ # # config => {:a => 'avalue', :b => 'bvalue', :c => 'cvalue'}
93
161
  def prompt_test(*array, &block)
94
162
  subset_test("PROMPT", "p") do
95
- puts "This test requires your input.\nEnter 'exit' to skip the test."
163
+ puts "\n#{calling_method} -- Enter values or 'skip'."
96
164
 
97
165
  config = {}
98
166
  array.each do |key|
99
167
  print "#{key}: "
100
168
  value = gets.strip
101
- flunk "exited test" if value =~ /exit/i
169
+ flunk "skipped test" if value =~ /skip/i
102
170
 
103
171
  config[key] = value
104
172
  end
@@ -109,6 +177,12 @@ class Test::Unit::TestCase
109
177
 
110
178
  protected
111
179
 
180
+ # Formats the input by using singleline_pp
181
+ def spp(input, str='')
182
+ PP.singleline_pp(input, str)
183
+ end
184
+
185
+ # Required for platform tests
112
186
  def on_test_skipped
113
187
  print ' '
114
188
  end
@@ -120,18 +194,16 @@ class Test::Unit::TestCase
120
194
 
121
195
  # Returns true if the subset type or 'ALL' is specified in ENV
122
196
  def run_subset?(type)
123
- env_true?(type) || env_true?("ALL")
197
+ env_true?(type) || env_true?("ALL") ? true : false
124
198
  end
125
199
 
126
200
  # Returns true if the pretty-print string for obj matches the regexp specified in ENV[type].
127
201
  # Returns the default value if 'ALL' is specified in ENV or type is not specified in ENV.
128
202
  def match_regexp?(type, obj, default=true)
129
- return default if env_true?("ALL")
203
+ return true if env_true?("ALL")
130
204
  return default unless ENV[type]
131
205
 
132
- str = ""
133
- PP.singleline_pp(obj, str)
134
- str =~ Regexp.new(ENV[type])
206
+ spp(obj) =~ Regexp.new(ENV[type]) ? true : false
135
207
  end
136
208
 
137
209
  # Calling method iterates over the call stack, and returns the first calling
@@ -157,7 +229,7 @@ class Test::Unit::TestCase
157
229
  type_test = "#{type}_TEST"
158
230
  if run_subset?(type) || ENV[type_test]
159
231
  if match_regexp?(type_test, calling_method)
160
- block.call
232
+ yield
161
233
  else
162
234
  print skip
163
235
  end
@@ -165,4 +237,13 @@ class Test::Unit::TestCase
165
237
  print skip
166
238
  end
167
239
  end
240
+
241
+ # Runs only if the first argument causes an 'if' statement to return true.
242
+ def switch_test(run_test, skip="!", &block)
243
+ if run_test
244
+ yield
245
+ else
246
+ print skip
247
+ end
248
+ end
168
249
  end
@@ -0,0 +1,15 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ #
7
+ # Gem specification
8
+ #
9
+ Gem::manage_gems
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = "gem_with_folder_require"
12
+ s.version = "0.1.1"
13
+ s.require_path = "lib"
14
+ s.autorequire = "folder_require"
15
+ end
@@ -0,0 +1,3 @@
1
+
2
+ module FolderRequire
3
+ end
@@ -0,0 +1,3 @@
1
+ development:
2
+ - ./test/gemdev/gem_with_folder_require
3
+ - ./test/gemdev/rakefile_with_multiple_specs
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ #
7
+ # Gem specification
8
+ #
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = "rakefile_with_multiple_specs"
11
+ s.version = "0.1.2"
12
+ s.require_path = "lib"
13
+ s.autorequire = "unrequired"
14
+ end
15
+
16
+ spec = Gem::Specification.new { |s|
17
+ s.name = "rakefile_with_multiple_specs"
18
+ s.version = "0.1.3"
19
+ s.require_path = "lib"
20
+ s.autorequire = "multiple_spec_require"
21
+ }
22
+
23
+ # out of order
24
+ spec = Gem::Specification.new do |s|
25
+ s.name = "rakefile_with_multiple_specs"
26
+ s.version = "0.1.1"
27
+ s.require_path = "lib"
28
+ s.autorequire = "unrequired"
29
+ end
@@ -0,0 +1,3 @@
1
+
2
+ module MultipleSpecRequire
3
+ end
@@ -0,0 +1,3 @@
1
+
2
+ module Unrequired
3
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), 'gemdev_test_helper.rb')
2
+
3
+ # override config accessor for testing
4
+ module Gem
5
+ def self.config_file
6
+ "./test/gemdev/gemrc"
7
+ end
8
+ end
9
+
10
+ require File.join(File.dirname(__FILE__), '../lib/gemdev')
11
+
12
+ class GemdevTest < Test::Unit::TestCase
13
+
14
+ def test_setup
15
+ assert File.exists?(Gem.config_file)
16
+ end
17
+
18
+ def test_require_unregistered_gem
19
+ assert_raise(Gem::LoadError) { gem('unregistered') }
20
+ end
21
+
22
+ def test_require_gem_with_folder
23
+ assert_raise(NameError) { Object::FolderRequire }
24
+
25
+ assert_equal true, require('folder_require')
26
+ assert Object::FolderRequire
27
+ end
28
+
29
+ def test_require_rakefile_with_multiple_specs
30
+ assert_raise(NameError) { Object::MultipleSpecRequire }
31
+ assert_raise(NameError) { Object::Unrequired }
32
+ assert_equal true, require('multiple_spec_require')
33
+ assert Object::MultipleSpecRequire
34
+ assert_raise(NameError) { Object::Unrequired }
35
+ end
36
+ end
@@ -1 +1 @@
1
- require 'extensions/test/unit/subsets'
1
+ require 'test/unit'
@@ -1,4 +1,3 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
2
 
3
- ENV["ALL"] = 'true'
4
- Dir.glob("./**/*_test.rb").each {|test| require test}
3
+ require File.join(File.dirname(__FILE__), 'subsets_test')
@@ -0,0 +1,100 @@
1
+ require File.join(File.dirname(__FILE__), 'gemdev_test_helper.rb')
2
+ require 'test/unit/subsets'
3
+
4
+ class SubsetsTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ ENV['ALL'] = nil
8
+ ENV['type'] = nil
9
+ end
10
+
11
+ #
12
+ # env_true test
13
+ #
14
+
15
+ def test_env_true_is_true_if_var_is_true
16
+ assert !ENV['type']
17
+ assert !env_true?('type')
18
+
19
+ ENV['type'] = "false"
20
+ assert !env_true?('type')
21
+
22
+ ENV['type'] = "true"
23
+ assert env_true?('type')
24
+
25
+ ENV['type'] = "True"
26
+ assert env_true?('type')
27
+
28
+ ENV['type'] = "TRUE"
29
+ assert env_true?('type')
30
+ end
31
+
32
+ #
33
+ # run subset test
34
+ #
35
+
36
+ def test_run_subset_true_if_ENV_type_is_true
37
+ assert_equal false, run_subset?('type')
38
+
39
+ ENV['type'] = "true"
40
+ assert_equal true, run_subset?('type')
41
+ end
42
+
43
+ def test_run_subset_true_if_ENV_ALL_is_true
44
+ ENV['ALL'] = "true"
45
+ assert_equal true, run_subset?('type')
46
+ end
47
+
48
+ #
49
+ # match_regexp test
50
+ #
51
+
52
+ def test_match_regexp
53
+ [1, [1,2]].each do |input|
54
+ ENV['type'] = "1"
55
+ assert_equal true, match_regexp?('type', input)
56
+ end
57
+
58
+ ["one", ["one", "two"]].each do |input|
59
+ ENV['type'] = "one"
60
+ assert_equal true, match_regexp?('type', input)
61
+ end
62
+ end
63
+
64
+ def test_match_regexp_returns_true_if_ENV_ALL_true
65
+ ENV['ALL'] = "true"
66
+ assert_equal true, match_regexp?('type', 1, "default")
67
+ end
68
+
69
+ def test_match_regexp_returns_default_unless_ENV_type_is_set
70
+ assert_equal "default", match_regexp?('type', 1, "default")
71
+ end
72
+
73
+ #
74
+ # calling method tests
75
+ #
76
+
77
+ def nested_call_to_calling_method
78
+ assert_equal 'test_calling_method', calling_method
79
+ end
80
+
81
+ def nested_call_with_alternate_pattern
82
+ assert_equal 'nested_call_with_alternate_pattern', calling_method(/^nested/)
83
+ end
84
+
85
+ def test_calling_method
86
+ assert_equal 'test_calling_method', calling_method
87
+ nested_call_to_calling_method
88
+ nested_call_with_alternate_pattern
89
+ end
90
+
91
+ #
92
+ # singleline pp test
93
+ #
94
+
95
+ def test_format_pps_input
96
+ [1, "two", [:three, 4]].each do |input|
97
+ assert_equal PP.singleline_pp(input, ''), spp(input)
98
+ end
99
+ end
100
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: gemdev
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-03-21 00:00:00 -06:00
6
+ version: 0.1.1
7
+ date: 2007-04-30 00:00:00 -06:00
8
8
  summary: Making gem development a bit easier.
9
9
  require_paths:
10
10
  - lib
@@ -29,8 +29,21 @@ post_install_message:
29
29
  authors:
30
30
  - Simon Chiang
31
31
  files:
32
+ - test/gemdev
33
+ - test/gemdev_test.rb
32
34
  - test/gemdev_test_helper.rb
33
35
  - test/gemdev_test_suite.rb
36
+ - test/subsets_test.rb
37
+ - test/gemdev/gemrc
38
+ - test/gemdev/gem_with_folder_require
39
+ - test/gemdev/rakefile_with_multiple_specs
40
+ - test/gemdev/gem_with_folder_require/lib
41
+ - test/gemdev/gem_with_folder_require/Rakefile
42
+ - test/gemdev/gem_with_folder_require/lib/folder_require.rb
43
+ - test/gemdev/rakefile_with_multiple_specs/lib
44
+ - test/gemdev/rakefile_with_multiple_specs/Rakefile
45
+ - test/gemdev/rakefile_with_multiple_specs/lib/multiple_spec_require.rb
46
+ - test/gemdev/rakefile_with_multiple_specs/lib/unrequired.rb
34
47
  - lib/gemdev.rb
35
48
  - lib/test
36
49
  - lib/test/unit