rubydoctest 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.0.0 2008-06-23
2
+
3
+ * Added doctest: and doctest_require: special directives.
4
+ * Bug fixes.
5
+ * Documentation and wiki.
6
+
7
+ == 0.3.0 2008-06-17
8
+
9
+ * Added ability to put doctest code within .rb file comments
10
+
1
11
  == 0.2.1 2008-05-26
2
12
 
3
13
  * Adding self-doctesting doctests
data/License.txt CHANGED
@@ -1,20 +1,19 @@
1
- Copyright (c) 2008 FIXME full name
1
+ Copyright (c) 2008 Tom Locke, Nic Williams, Duane Johnson
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
10
9
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
13
12
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/Manifest.txt CHANGED
@@ -4,26 +4,34 @@ Manifest.txt
4
4
  PostInstall.txt
5
5
  README.txt
6
6
  Rakefile
7
+ Ruby DocTest.tmproj
7
8
  bin/rubydoctest
8
9
  config/hoe.rb
9
10
  config/requirements.rb
11
+ lib/code_block.rb
12
+ lib/doctest_require.rb
13
+ lib/lines.rb
14
+ lib/result.rb
10
15
  lib/rubydoctest.rb
11
16
  lib/rubydoctest/version.rb
17
+ lib/runner.rb
18
+ lib/special_directive.rb
19
+ lib/statement.rb
20
+ lib/test.rb
12
21
  rubydoctest.gemspec
13
22
  script/console
14
23
  script/destroy
15
24
  script/generate
25
+ script/rstakeout
16
26
  script/txt2html
17
27
  setup.rb
18
28
  tasks/deployment.rake
19
29
  tasks/doctests.rake
20
30
  tasks/environment.rake
21
31
  tasks/website.rake
22
- test/doctest/file_relative.doctest
23
- test/doctest/runner.doctest
24
- test/doctest/simple.doctest
25
- test/test_helper.rb
26
- test/test_rubydoctest.rb
32
+ textmate/DocTest (Markdown).textmate
33
+ textmate/DocTest (Ruby).textmate
34
+ textmate/DocTest (Text).textmate
27
35
  website/index.html
28
36
  website/index.txt
29
37
  website/javascripts/rounded_corners_lite.inc.js
data/PostInstall.txt CHANGED
@@ -1,8 +1,7 @@
1
1
 
2
- rubydoctest comes as an executable that takes a file or directory:
2
+ rubydoctest comes as an executable that takes a list of files:
3
3
 
4
- rubydoctest .
5
- rubydoctest some/path/to/tests
4
+ rubydoctest lib/*.rb
6
5
  rubydoctest simple.doctest
7
6
 
8
7
 
data/README.txt CHANGED
@@ -1,24 +1,37 @@
1
- = rubydoctest
1
+ = Ruby DocTest
2
2
 
3
- * http://github.com/tablatom/rubydoctest
3
+ Official repository:
4
+ * http://github.com/tablatom/rubydoctest
4
5
 
5
- == DESCRIPTION:
6
+ Wiki documentation:
7
+ * http://github.com/tablatom/rubydoctest/wikis
6
8
 
7
- Ruby version of Python's doctest tool, but a bit different.
9
+ == Description:
8
10
 
9
- == FEATURES/PROBLEMS:
11
+ Ruby version of Python's doctest tool, but a bit different. Ruby DocTest
12
+ allows you to:
10
13
 
11
- * FIX (list of features or problems)
14
+ 1. Write tests in irb format and keep them as comments next to your Ruby code.
15
+ 2. Write markdown documents with irb format tests embedded in them.
12
16
 
13
- == SYNOPSIS:
17
+ == Synopsis:
14
18
 
15
- rubydoctest comes as an executable that takes a file or directory:
19
+ rubydoctest comes as an executable that takes a list of files:
16
20
 
17
- rubydoctest .
21
+ rubydoctest lib/*.rb
18
22
  rubydoctest simple.doctest
19
23
 
20
- == EXAMPLE:
24
+ == Examples:
21
25
 
26
+ Here is how you might use RubyDocTest within a ruby source file (say called five.rb):
27
+
28
+ # doctest: Add 5 and 5 to get 10
29
+ # >> five_and_five
30
+ # => 10
31
+ def five_and_five
32
+ 5 + 5
33
+ end
34
+
22
35
  Here is an example doctest file (say called simple.doctest):
23
36
 
24
37
  # Simple test of RubyDocTest
@@ -33,30 +46,9 @@ Here is an example doctest file (say called simple.doctest):
33
46
  >> 1 + 2
34
47
  => 4
35
48
 
36
- Test a some multiline statements
37
-
38
- >>
39
- class Person
40
- attr_accessor :name
41
- end
42
-
43
- >> Person
44
- => Person
45
- >> p = Person.new
46
- >> p.name = "Tom"
47
- >> p.name
48
- => "Tom"
49
-
50
-
51
- >> "a
52
- b"
53
- => "a\nb"
54
-
55
- >> 1 +
56
- ?> 2
57
- => 3
49
+ See the doc directory of this project for more .doctest examples and documentation.
58
50
 
59
- == INSTALL:
51
+ == Installation:
60
52
 
61
53
  Major releases:
62
54
 
@@ -66,9 +58,9 @@ Build from source:
66
58
 
67
59
  git clone git://github.com/tablatom/rubydoctest.git
68
60
  cd rubydoctest
69
- rake manifest && rake install
61
+ rake manifest:refresh && rake install
70
62
 
71
- == SELF-DOCTESTING:
63
+ == Testing DocTest:
72
64
 
73
65
  Ruby DocTest uses itself to test and document itself.
74
66
 
@@ -79,31 +71,30 @@ using script/rstakeout
79
71
 
80
72
  rake test:doctest:auto
81
73
 
82
- == TEXTMATE BUNDLE:
74
+ == TextMate Bundle:
83
75
 
84
76
  See http://github.com/drnic/ruby-doctest-tmbundle
85
77
 
86
- == LICENSE:
78
+ == License:
87
79
 
88
80
  (The MIT License)
89
81
 
90
- Copyright (c) 2008 FIX
91
-
92
- Permission is hereby granted, free of charge, to any person obtaining
93
- a copy of this software and associated documentation files (the
94
- 'Software'), to deal in the Software without restriction, including
95
- without limitation the rights to use, copy, modify, merge, publish,
96
- distribute, sublicense, and/or sell copies of the Software, and to
97
- permit persons to whom the Software is furnished to do so, subject to
98
- the following conditions:
99
-
100
- The above copyright notice and this permission notice shall be
101
- included in all copies or substantial portions of the Software.
102
-
103
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
104
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
105
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
106
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
107
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
108
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
109
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
82
+ Copyright (c) 2008 Tom Locke, Nic Williams, Duane Johnson
83
+
84
+ Permission is hereby granted, free of charge, to any person obtaining a copy
85
+ of this software and associated documentation files (the 'Software'), to deal
86
+ in the Software without restriction, including without limitation the rights
87
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88
+ copies of the Software, and to permit persons to whom the Software is
89
+ furnished to do so, subject to the following conditions:
90
+
91
+ The above copyright notice and this permission notice shall be included in all
92
+ copies or substantial portions of the Software.
93
+
94
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
95
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
96
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
97
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
99
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
100
+ SOFTWARE.
@@ -0,0 +1,197 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>currentDocument</key>
6
+ <string>rubydoctest.gemspec</string>
7
+ <key>documents</key>
8
+ <array>
9
+ <dict>
10
+ <key>expanded</key>
11
+ <true/>
12
+ <key>name</key>
13
+ <string>rubydoctest</string>
14
+ <key>regexFolderFilter</key>
15
+ <string>!.*/(\.[^/]*|rails|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
16
+ <key>sourceDirectory</key>
17
+ <string></string>
18
+ </dict>
19
+ </array>
20
+ <key>fileHierarchyDrawerWidth</key>
21
+ <integer>315</integer>
22
+ <key>metaData</key>
23
+ <dict>
24
+ <key>Manifest.txt</key>
25
+ <dict>
26
+ <key>caret</key>
27
+ <dict>
28
+ <key>column</key>
29
+ <integer>0</integer>
30
+ <key>line</key>
31
+ <integer>0</integer>
32
+ </dict>
33
+ <key>firstVisibleColumn</key>
34
+ <integer>0</integer>
35
+ <key>firstVisibleLine</key>
36
+ <integer>0</integer>
37
+ </dict>
38
+ <key>PostInstall.txt</key>
39
+ <dict>
40
+ <key>caret</key>
41
+ <dict>
42
+ <key>column</key>
43
+ <integer>0</integer>
44
+ <key>line</key>
45
+ <integer>0</integer>
46
+ </dict>
47
+ <key>firstVisibleColumn</key>
48
+ <integer>0</integer>
49
+ <key>firstVisibleLine</key>
50
+ <integer>0</integer>
51
+ </dict>
52
+ <key>Rakefile</key>
53
+ <dict>
54
+ <key>caret</key>
55
+ <dict>
56
+ <key>column</key>
57
+ <integer>0</integer>
58
+ <key>line</key>
59
+ <integer>0</integer>
60
+ </dict>
61
+ <key>firstVisibleColumn</key>
62
+ <integer>0</integer>
63
+ <key>firstVisibleLine</key>
64
+ <integer>0</integer>
65
+ </dict>
66
+ <key>config/hoe.rb</key>
67
+ <dict>
68
+ <key>caret</key>
69
+ <dict>
70
+ <key>column</key>
71
+ <integer>73</integer>
72
+ <key>line</key>
73
+ <integer>64</integer>
74
+ </dict>
75
+ <key>columnSelection</key>
76
+ <false/>
77
+ <key>firstVisibleColumn</key>
78
+ <integer>0</integer>
79
+ <key>firstVisibleLine</key>
80
+ <integer>26</integer>
81
+ <key>selectFrom</key>
82
+ <dict>
83
+ <key>column</key>
84
+ <integer>66</integer>
85
+ <key>line</key>
86
+ <integer>64</integer>
87
+ </dict>
88
+ <key>selectTo</key>
89
+ <dict>
90
+ <key>column</key>
91
+ <integer>73</integer>
92
+ <key>line</key>
93
+ <integer>64</integer>
94
+ </dict>
95
+ </dict>
96
+ <key>lib/lines.rb</key>
97
+ <dict>
98
+ <key>caret</key>
99
+ <dict>
100
+ <key>column</key>
101
+ <integer>0</integer>
102
+ <key>line</key>
103
+ <integer>0</integer>
104
+ </dict>
105
+ <key>firstVisibleColumn</key>
106
+ <integer>0</integer>
107
+ <key>firstVisibleLine</key>
108
+ <integer>0</integer>
109
+ </dict>
110
+ <key>lib/result.rb</key>
111
+ <dict>
112
+ <key>caret</key>
113
+ <dict>
114
+ <key>column</key>
115
+ <integer>3</integer>
116
+ <key>line</key>
117
+ <integer>62</integer>
118
+ </dict>
119
+ <key>firstVisibleColumn</key>
120
+ <integer>0</integer>
121
+ <key>firstVisibleLine</key>
122
+ <integer>16</integer>
123
+ </dict>
124
+ <key>lib/rubydoctest/version.rb</key>
125
+ <dict>
126
+ <key>caret</key>
127
+ <dict>
128
+ <key>column</key>
129
+ <integer>13</integer>
130
+ <key>line</key>
131
+ <integer>3</integer>
132
+ </dict>
133
+ <key>firstVisibleColumn</key>
134
+ <integer>0</integer>
135
+ <key>firstVisibleLine</key>
136
+ <integer>0</integer>
137
+ </dict>
138
+ <key>lib/runner.rb</key>
139
+ <dict>
140
+ <key>caret</key>
141
+ <dict>
142
+ <key>column</key>
143
+ <integer>53</integer>
144
+ <key>line</key>
145
+ <integer>129</integer>
146
+ </dict>
147
+ <key>firstVisibleColumn</key>
148
+ <integer>0</integer>
149
+ <key>firstVisibleLine</key>
150
+ <integer>0</integer>
151
+ </dict>
152
+ <key>rubydoctest.gemspec</key>
153
+ <dict>
154
+ <key>caret</key>
155
+ <dict>
156
+ <key>column</key>
157
+ <integer>45</integer>
158
+ <key>line</key>
159
+ <integer>14</integer>
160
+ </dict>
161
+ <key>firstVisibleColumn</key>
162
+ <integer>0</integer>
163
+ <key>firstVisibleLine</key>
164
+ <integer>0</integer>
165
+ </dict>
166
+ <key>tasks/deployment.rake</key>
167
+ <dict>
168
+ <key>caret</key>
169
+ <dict>
170
+ <key>column</key>
171
+ <integer>0</integer>
172
+ <key>line</key>
173
+ <integer>0</integer>
174
+ </dict>
175
+ <key>firstVisibleColumn</key>
176
+ <integer>0</integer>
177
+ <key>firstVisibleLine</key>
178
+ <integer>0</integer>
179
+ </dict>
180
+ </dict>
181
+ <key>openDocuments</key>
182
+ <array>
183
+ <string>lib/runner.rb</string>
184
+ <string>lib/rubydoctest/version.rb</string>
185
+ <string>tasks/deployment.rake</string>
186
+ <string>Manifest.txt</string>
187
+ <string>PostInstall.txt</string>
188
+ <string>Rakefile</string>
189
+ <string>config/hoe.rb</string>
190
+ <string>rubydoctest.gemspec</string>
191
+ </array>
192
+ <key>showFileHierarchyDrawer</key>
193
+ <true/>
194
+ <key>windowFrame</key>
195
+ <string>{{61, 4}, {935, 874}}</string>
196
+ </dict>
197
+ </plist>
data/bin/rubydoctest CHANGED
@@ -1,35 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- USAGE = "USAGE: rdoctest [ --html ] [ --trace ] [ --debugger ] <path>"
4
-
5
- SUFFIX = "{r,}doctest"
3
+ if ARGV.empty?
4
+ puts <<-DIRECTIONS
5
+ USAGE: rubydoctest [options] <files>
6
+
7
+ rubydoctest parses Ruby files (.rb) or DocTest files (.doctest) for irb-style
8
+ sessions in comments, and runs the commented sessions as tests.
9
+
10
+ Options:
11
+ Output Format:
12
+ --html - output in HTML format
13
+ --plain - force output in plain text (no Ansi colors)
14
+
15
+ Debug:
16
+ --ignore-interactive - do not heed !!! special directives
17
+ --trace - turn backtrace on to debug Ruby DocTest
18
+ --debugger - include ruby-debug library / gem
19
+
20
+ See http://github.com/tablatom/rubydoctest/wikis for more information.
21
+ DIRECTIONS
22
+ exit 0
23
+ end
6
24
 
7
- file = ARGV.pop or (puts USAGE; exit 1)
25
+ options, files = ARGV.partition{ |a| a =~ /^--/ }
8
26
 
9
27
  requires = ['rubygems', File.dirname(__FILE__) + "/../lib/rubydoctest"]
10
- requires << 'ruby-debug' if ARGV.include?("--debugger")
11
-
12
- command = if ARGV.include?("--rcov")
13
- args = (ARGV - ["--rcov"]).map { |a| %("#{a}") }.join(' ')
14
- "rcov -x /gems/,rdoctest"
15
- else
16
- "ruby"
17
- end
18
- trace = "RubyDocTest.trace = true;" if ARGV.include?("--trace")
28
+ requires << 'ruby-debug' if options.include?("--debugger")
29
+ ruby_lines = []
30
+ ruby_lines << "RubyDocTest.trace = true;" if options.include?("--trace")
31
+ ruby_lines << "RubyDocTest.ignore_interactive = true;" if options.include?("--ignore-interactive")
19
32
 
20
33
  requires = requires.map {|lib| "require '#{lib}'; "}.join
21
34
 
22
- puts "<html><body><pre>" if ARGV.include?("--html")
23
-
24
- files = if File.directory?(file)
25
- Dir["#{file}/**/*.#{SUFFIX}"]
26
- else
27
- [file]
28
- end
29
-
30
- files.reverse_each do |f|
31
- puts "*** " + f.sub("#{file}/", "").sub(".#{SUFFIX}", ""), "" if files.length > 1
32
- system %(#{command} -e "#{requires} #{trace} RubyDocTest.new(File.read('#{f}'), '#{f}').run")
35
+ def files_runner(command, files, requires, lines)
36
+ files.reverse_each do |f|
37
+ system %(#{command} -e "#{requires} #{lines.join(" ")} RubyDocTest::Runner.new(File.read('#{f}'), '#{f}').run")
38
+ end
33
39
  end
34
40
 
35
- puts "</pre></body></html>" if ARGV.include?("--html")
41
+ if options.include?("--plain")
42
+ ruby_lines << "RubyDocTest.output_format = :plain;"
43
+ files_runner("ruby", files, requires, ruby_lines)
44
+ elsif options.include?("--html")
45
+ ruby_lines << "RubyDocTest.output_format = :html;"
46
+ puts "<html><body><pre>"
47
+ files_runner("ruby", files, requires, ruby_lines)
48
+ puts "</pre></body></html>"
49
+ else
50
+ files_runner("ruby", files, requires, ruby_lines)
51
+ end