gemdev 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
File without changes
data/lib/gemdev.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'yaml'
3
+
4
+ module Kernel
5
+ alias development_gem_orginal_require require
6
+
7
+ def require(path)
8
+ development_gem_orginal_require path
9
+ rescue LoadError => load_error
10
+ raise load_error unless Gem.require_development(path)
11
+ end
12
+ end
13
+
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)
23
+
24
+ require development[path]
25
+ true
26
+ end
27
+ end
@@ -0,0 +1,168 @@
1
+ require 'test/unit'
2
+ require 'benchmark'
3
+ require 'pp'
4
+
5
+ # These subsets facilitate testing by using the ENV variables specified on the command line
6
+ # to indicate which tests to run. The ENV variables are set by rake, so this code implicitly
7
+ # assumes that you're running your tests through rake.
8
+ #
9
+ class Test::Unit::TestCase
10
+
11
+ class << self
12
+ def require_platform(*platforms)
13
+ @platforms = platforms
14
+ end
15
+
16
+ def match_platform?(*platforms)
17
+ platforms.each do |platform|
18
+ platform.to_s =~ /^(non_)?(.*)/
19
+
20
+ non = true if $1
21
+ match_platform = !RUBY_PLATFORM.index($2).nil?
22
+ return false unless (non && !match_platform) || (!non && match_platform)
23
+ end
24
+
25
+ true
26
+ end
27
+
28
+ alias :original_suite :suite
29
+ end
30
+
31
+ def self.suite
32
+ if match_platform?(*@platforms)
33
+ original_suite
34
+ else
35
+ method_names = public_instance_methods(true)
36
+ suite = Test::Unit::TestSuite.new(name)
37
+ method_names.each do |method_name|
38
+ catch(:invalid_test) do
39
+ suite << new('on_test_skipped') if method_name =~ /^test/
40
+ end
41
+ end
42
+ suite
43
+ end
44
+ end
45
+
46
+ def platform_test(*platforms, &block)
47
+ if self.class.match_platform?(*platforms)
48
+ block.call
49
+ else
50
+ print ' '
51
+ end
52
+ end
53
+
54
+ # Subset test declaration for extended tests -- type: EXTENDED
55
+ # Prints 'x' unless run.
56
+ def extended_test(&block)
57
+ subset_test("EXTENDED", "x", &block)
58
+ end
59
+
60
+ # Subset test declaration for benchmard tests -- type: BENCHMARK
61
+ # Prints 'b' unless run.
62
+ def benchmark_test(&block)
63
+ subset_test("BENCHMARK") do
64
+ puts calling_method
65
+ block.call
66
+ end
67
+ end
68
+
69
+ # Case tests take a hash of testcases and expected values. Each pair in the hash will
70
+ # be passed to the block if type CASE_TEST is specified. Individual cases tests can be
71
+ # specified by providing a regexp in CASE; the testcase will run if the pretty-print of
72
+ # the testcase matches the provided regexp. Example:
73
+ #
74
+ # case_test(
75
+ # [1,2,3] => 'an array testcase',
76
+ # '[1, 2, 3]' => 'the pretty print of the array',
77
+ # 'another testcase' => 'some third testcase'
78
+ # ).do |testcase, expected|
79
+ # ...your test code...
80
+ # end
81
+ #
82
+ # ENV['CASE_TEST']=true => all tests run
83
+ # ENV['CASE']='1, 2, 3' => first two tests run
84
+ # ENV['CASE']='another' => only last test runs
85
+ def case_test(hash, &block)
86
+ if match_regexp?("CASE_TEST", calling_method)
87
+ hash.each_pair do |testcase, expected|
88
+ yield(testcase, expected) if match_regexp?("CASE", testcase)
89
+ end
90
+ end
91
+ end
92
+
93
+ def prompt_test(*array, &block)
94
+ subset_test("PROMPT", "p") do
95
+ puts "This test requires your input.\nEnter 'exit' to skip the test."
96
+
97
+ config = {}
98
+ array.each do |key|
99
+ print "#{key}: "
100
+ value = gets.strip
101
+ flunk "exited test" if value =~ /exit/i
102
+
103
+ config[key] = value
104
+ end
105
+
106
+ yield(config)
107
+ end
108
+ end
109
+
110
+ protected
111
+
112
+ def on_test_skipped
113
+ print ' '
114
+ end
115
+
116
+ # Returns true if the ENV[var] is set and matches /^true%/i
117
+ def env_true?(var)
118
+ ENV[var] && ENV[var] =~ /^true$/i
119
+ end
120
+
121
+ # Returns true if the subset type or 'ALL' is specified in ENV
122
+ def run_subset?(type)
123
+ env_true?(type) || env_true?("ALL")
124
+ end
125
+
126
+ # Returns true if the pretty-print string for obj matches the regexp specified in ENV[type].
127
+ # Returns the default value if 'ALL' is specified in ENV or type is not specified in ENV.
128
+ def match_regexp?(type, obj, default=true)
129
+ return default if env_true?("ALL")
130
+ return default unless ENV[type]
131
+
132
+ str = ""
133
+ PP.singleline_pp(obj, str)
134
+ str =~ Regexp.new(ENV[type])
135
+ end
136
+
137
+ # Calling method iterates over the call stack, and returns the first calling
138
+ # method name that matches the input pattern (by default /^test/)
139
+ def calling_method(pattern=/^test/)
140
+ 0.upto(caller.length) do |i|
141
+ caller[i] =~ /:in `(.*)'$/
142
+ method_name = $1
143
+ return method_name if method_name =~ pattern
144
+ end
145
+
146
+ ''
147
+ end
148
+
149
+ # Basic method for a subset test. The provided block will run if:
150
+ # - The subset type or 'ALL' is specified in ENV
151
+ # - The calling method matches the regexp provided in the "TYPE_TEST" ENV variable
152
+ #
153
+ # Otherwise the block will be skipped and +skip+ will be printed. By default skip
154
+ # is the first letter of +type+.
155
+ def subset_test(type, skip=type[0..0].downcase, &block)
156
+ type = type.upcase
157
+ type_test = "#{type}_TEST"
158
+ if run_subset?(type) || ENV[type_test]
159
+ if match_regexp?(type_test, calling_method)
160
+ block.call
161
+ else
162
+ print skip
163
+ end
164
+ else
165
+ print skip
166
+ end
167
+ end
168
+ end
@@ -0,0 +1 @@
1
+ require 'extensions/test/unit/subsets'
@@ -0,0 +1,4 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ ENV["ALL"] = 'true'
4
+ Dir.glob("./**/*_test.rb").each {|test| require test}
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: gemdev
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-03-21 00:00:00 -06:00
8
+ summary: Making gem development a bit easier.
9
+ require_paths:
10
+ - lib
11
+ email: simon.chiang@uchsc.edu
12
+ homepage: http://rubyforge.org/projects/gemdev/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: gemdev
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Simon Chiang
31
+ files:
32
+ - test/gemdev_test_helper.rb
33
+ - test/gemdev_test_suite.rb
34
+ - lib/gemdev.rb
35
+ - lib/test
36
+ - lib/test/unit
37
+ - lib/test/unit/subsets.rb
38
+ - README
39
+ test_files:
40
+ - test/gemdev_test_suite.rb
41
+ rdoc_options: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ requirements: []
50
+
51
+ dependencies: []
52
+