tdoc 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tdoc.rb +2 -2
- data/bin/tdoc_idea.rb +124 -0
- metadata +3 -2
data/bin/tdoc.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
require 'rubygems'
|
3
3
|
require 'test/unit'
|
4
|
-
require '
|
4
|
+
require 'contest'
|
5
5
|
require 'irb'
|
6
6
|
|
7
7
|
$: << 'lib'
|
@@ -70,7 +70,7 @@ def mk_test_context(file, test_case=nil)
|
|
70
70
|
eval setup_text.to_a.join(';')
|
71
71
|
end
|
72
72
|
tests.each do |test|
|
73
|
-
should test[0] do
|
73
|
+
should test[0].to_s do
|
74
74
|
eval test[1]
|
75
75
|
end
|
76
76
|
end
|
data/bin/tdoc_idea.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'irb'
|
6
|
+
|
7
|
+
$: << 'lib'
|
8
|
+
|
9
|
+
LINST='^[#|\s]*'
|
10
|
+
EXTENSIONS={:tests => '.rdoc',:requires => '.rb'}
|
11
|
+
DEFAULT_FILE=["README#{EXTENSIONS[:tests]}"]
|
12
|
+
|
13
|
+
START_IRB="IRB.setup nil; IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context; require 'irb/ext/multi-irb'; IRB.irb nil, self"
|
14
|
+
|
15
|
+
def process(files) #called at end of script
|
16
|
+
if files.class==Array
|
17
|
+
files.each {|f|
|
18
|
+
puts "\n\n--------------------\n#{f}:\n\n"
|
19
|
+
result=system("#{$PROGRAM_NAME} #{f} #{ARGV}")
|
20
|
+
puts "\n\nERRORS IN TEST #{f}!!!\n\n" unless result
|
21
|
+
}
|
22
|
+
else
|
23
|
+
test_name=File.basename(files).sub(/\..*?$/,'')
|
24
|
+
test_case=Class.new(Test::Unit::TestCase)
|
25
|
+
Object.const_set(:"Test#{test_name.capitalize}", test_case)
|
26
|
+
mk_test_context(files, test_case)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_file(file, test_case=nil)
|
31
|
+
test_name=File.basename(file).sub(/\..*?$/,'')
|
32
|
+
text=File.read(file)
|
33
|
+
unless test_case
|
34
|
+
test_case=Class.new(Test::Unit::TestCase)
|
35
|
+
Object.const_set(:"Test#{test_name.capitalize}", test_case)
|
36
|
+
end
|
37
|
+
test_dir=File.dirname(file)
|
38
|
+
external_files={
|
39
|
+
:requires => Dir.glob("#{test_dir}/#{test_name}#{EXTENSIONS[:requires]}"),
|
40
|
+
:contexts => Dir.glob("#{test_dir}/#{test_name}/*#{EXTENSIONS[:tests]}"),
|
41
|
+
:tests => [],
|
42
|
+
}
|
43
|
+
[:requires, :tests].each do |opt|
|
44
|
+
text.scan(/#{LINST}:include:\s*(.+#{EXTENSIONS[opt]})/).each do |files|
|
45
|
+
files[0].split(',').each do |f|
|
46
|
+
external_files[opt] << f unless f.match(/^blob/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
external_files[:requires].each {|r| require "#{r}" if FileTest.exist? "#{r}" }
|
51
|
+
external_files[:tests].each {|t| parse_file("#{test_dir}/#{t}") unless t.match(/#{test_name}/)}
|
52
|
+
external_files[:contexts].each {|c| text+=File.read(c)}
|
53
|
+
end
|
54
|
+
def mk_context(text)
|
55
|
+
end
|
56
|
+
def mk_test(text)
|
57
|
+
end
|
58
|
+
|
59
|
+
def mk_test_context(file, test_case=nil)
|
60
|
+
test_name=File.basename(file).sub(/\..*?$/,'')
|
61
|
+
test_dir=File.dirname(file)
|
62
|
+
$: << test_dir unless $:.include?(test_dir)
|
63
|
+
text=File.read(file)
|
64
|
+
opts={
|
65
|
+
:requires => Dir.glob("#{test_dir}/#{test_name}#{EXTENSIONS[:requires]}"),
|
66
|
+
:contexts => Dir.glob("#{test_dir}/#{test_name}/*#{EXTENSIONS[:tests]}"),
|
67
|
+
:tests => [],
|
68
|
+
}
|
69
|
+
[:requires, :tests].each do |opt|
|
70
|
+
text.scan(/#{LINST}:include:\s*(.+#{EXTENSIONS[opt]})/).each do |files|
|
71
|
+
files[0].split(',').each do |f|
|
72
|
+
opts[opt] << f unless f.match(/^blob/)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
opts[:requires].each {|r| require "#{r}" if FileTest.exist? "#{r}" }
|
77
|
+
opts[:tests].delete_if {|c| c.match(/#{test_name}/)}
|
78
|
+
setup_text=text.sub(/(.*)\n#{LINST}setup\s*\n/m,'').sub(/\n#{LINST}end(.*)/m,'') if text.match(/#{LINST}setup\s*$/)
|
79
|
+
tests=text.split(/#{LINST}[Ee]xamples?:/).to_a[1..-1].to_a.map do |test|
|
80
|
+
test.gsub!(/#{LINST}>>\s*(.+)\n#{LINST}=>\s*(.+)/) {|m|
|
81
|
+
expected, actual=[$2,$1]
|
82
|
+
#assert_equal cannot take a hash as its first argument
|
83
|
+
expected.sub!(/^\{(.*)\}\s*$/) {|m| "Hash[#{$1}]"}
|
84
|
+
"assert_equal #{expected}, #{actual}"
|
85
|
+
}
|
86
|
+
lines=test.split(/\n/)
|
87
|
+
test_text=lines.map {|l|
|
88
|
+
if l.match(/#{LINST}!!!/)
|
89
|
+
START_IRB
|
90
|
+
else
|
91
|
+
l.match(/#{LINST}(assert.+)/) && $1
|
92
|
+
end
|
93
|
+
}.compact.join ";\n"
|
94
|
+
[lines[0], test_text]
|
95
|
+
end
|
96
|
+
tests=[['work',"assert(true);"]] if tests.empty? #avoids "no tests specified" error
|
97
|
+
context_proc=lambda {
|
98
|
+
context test_name do
|
99
|
+
setup do
|
100
|
+
eval setup_text.to_a.join(';')
|
101
|
+
end
|
102
|
+
tests.each do |test|
|
103
|
+
should test[0] do
|
104
|
+
eval test[1]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
opts[:contexts].compact.each do |c|
|
108
|
+
mk_test_context(c).call
|
109
|
+
end
|
110
|
+
end
|
111
|
+
}
|
112
|
+
if test_case
|
113
|
+
test_case.module_eval {mk_test_context(file).call}
|
114
|
+
process opts[:tests] unless opts[:tests].empty?
|
115
|
+
else
|
116
|
+
context_proc
|
117
|
+
end
|
118
|
+
end
|
119
|
+
if glob=ARGV.shift
|
120
|
+
files=Dir.glob(glob)
|
121
|
+
process(files.count > 1 ? files : files[0])
|
122
|
+
else
|
123
|
+
process(DEFAULT_FILE)
|
124
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Herb Daily
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2012-01-07 00:00:00 -03:00
|
13
13
|
default_executable: tdoc.rb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- README.rdoc
|
35
35
|
- bin/tdoc.rb
|
36
|
+
- bin/tdoc_idea.rb
|
36
37
|
- rdoc/example.rb
|
37
38
|
- rdoc/example.rdoc
|
38
39
|
- lib/rdoc/parsers/tdoc.rb
|