Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 6806 Bytes
1 | #!/usr/bin/env ruby |
2 | |
3 | require 'maruku' |
4 | #require 'maruku/textile2' |
5 | require 'maruku/input_textile2/t2_parser' |
6 | |
7 | $marutest_language = :markdown |
8 | |
9 | #MARKER = "\n***EOF***\n" |
10 | SPLIT = %r{\n\*\*\*[^\*]+\*\*\*\n}m |
11 | |
12 | def marker(x) |
13 | "\n*** Output of #{x} ***\n" |
14 | end |
15 | |
16 | def write_lines(i, j, lines, prefix, i_star) |
17 | i = [i, 0].max |
18 | j = [j, lines.size-1].min |
19 | for a in i..j |
20 | l = lines[a].gsub(/\t/,' ') |
21 | puts( ("%s %3d" % [prefix, a]) + |
22 | (a==i_star ? " -->" : " ")+lines[a]) |
23 | end |
24 | end |
25 | |
26 | # a = expected b = found |
27 | def equals(a, b) |
28 | a = a.split("\n") |
29 | b = b.split("\n") |
30 | |
31 | for i in 0..([a.size-1,b.size-1].max) |
32 | la = a[i] |
33 | lb = b[i] |
34 | if la != lb |
35 | puts "\n" |
36 | |
37 | |
38 | write_lines(i-3, i+3, a, "expected", i ) |
39 | write_lines(i-3, i+3, b, " found", i ) |
40 | return false |
41 | end |
42 | end |
43 | return true |
44 | end |
45 | |
46 | TOTEST = [:inspect,:to_html,:to_latex,:to_md,:to_s] |
47 | |
48 | def run_test(filename, its_ok, verbose=true) |
49 | # read file content |
50 | input = (f=File.open(filename,'r')).read; f.close |
51 | |
52 | output_html = File.join(File.dirname(filename), |
53 | File.basename(filename, File.extname(filename)) + ".html") |
54 | |
55 | # split the input in sections |
56 | |
57 | stuff = input.split(SPLIT) |
58 | if stuff.size == 1 |
59 | stuff[2] = stuff[0] |
60 | stuff[0] = "Write a comment here" |
61 | stuff[1] = "{} # params " |
62 | end |
63 | |
64 | comment = stuff.shift |
65 | params_s = stuff.shift |
66 | |
67 | params = eval(params_s||'{}') |
68 | if params == nil |
69 | raise "Null params? #{params_s.inspect}" |
70 | end |
71 | |
72 | markdown = stuff.shift |
73 | |
74 | # puts "comment: #{markdown.inspect}" |
75 | # puts "markdown: #{markdown.inspect}" |
76 | |
77 | failed = [] |
78 | relaxed = [] |
79 | crashed = [] |
80 | actual = {} |
81 | |
82 | doc = |
83 | if $marutest_language == :markdown |
84 | Maruku.new(markdown, params) |
85 | else |
86 | MaRuKu.textile2(markdown, params) |
87 | end |
88 | |
89 | for s in TOTEST |
90 | begin |
91 | if s==:to_html |
92 | actual[s] = doc.to_html |
93 | else |
94 | actual[s] = doc.send s |
95 | raise "Methods #{s} gave nil" if not actual[s] |
96 | end |
97 | rescue Exception => e |
98 | crashed << s |
99 | actual[s] = e.inspect+ "\n"+ e.backtrace.join("\n") |
100 | puts actual[s] |
101 | end |
102 | end |
103 | |
104 | File.open(output_html, 'w') do |f| |
105 | f.write doc.to_html_document |
106 | end |
107 | |
108 | begin |
109 | m = Maruku.new |
110 | d = m.instance_eval(actual[:inspect]) |
111 | rescue Exception => e |
112 | s = e.inspect + e.backtrace.join("\n") |
113 | raise "Inspect is not correct:\n ========\n#{actual[:inspect]}"+ |
114 | "============\n #{s}" |
115 | end |
116 | |
117 | expected = {} |
118 | if (stuff.size < TOTEST.size) |
119 | $stdout.write " (first time!) " |
120 | TOTEST.each do |x| expected[x] = actual[x] end |
121 | else |
122 | TOTEST.each_index do |i| |
123 | symbol = TOTEST[i] |
124 | expected[symbol] = stuff[i] |
125 | # puts "symbol: #{symbol.inspect} = #{stuff[i].inspect}" |
126 | end |
127 | end |
128 | |
129 | m = Maruku.new |
130 | |
131 | |
132 | if not its_ok.include? :inspect |
133 | begin |
134 | d = m.instance_eval(expected[:inspect]) |
135 | # puts "Eval: #{d.inspect}" |
136 | expected[:inspect] = d.inspect |
137 | rescue Exception => e |
138 | s = e.inspect + e.backtrace.join("\n") |
139 | raise "Cannot eval user-provided string:\n #{expected[:inspect].to_s}"+ |
140 | "\n #{s}" |
141 | end |
142 | end |
143 | |
144 | # m.instance_eval(actual[:inspect]) != m.instance_eval(expected[:inspect]) |
145 | |
146 | # actual[:inspect] = m.instance_eval(actual[:inspect]) |
147 | # expected[:inspect] = m.instance_eval(expected[:inspect]) |
148 | |
149 | |
150 | TOTEST.each do |x| |
151 | expected[x].strip! |
152 | actual[x].strip! |
153 | if not equals(expected[x], actual[x]) |
154 | if its_ok.include? x |
155 | expected[x] = actual[x] |
156 | $stdout.write " relax:#{x} " |
157 | relaxed << x |
158 | else |
159 | actual[x] = "-----| WARNING | -----\n" + actual[x].to_s |
160 | failed << x |
161 | end |
162 | end |
163 | end |
164 | |
165 | f = File.open(filename, 'w') |
166 | |
167 | f.write comment |
168 | f.write "\n*** Parameters: ***\n" |
169 | f.write params_s |
170 | f.write "\n*** Markdown input: ***\n" |
171 | f.write markdown |
172 | |
173 | TOTEST.each do |x| |
174 | f.write marker(x) |
175 | f.write expected[x] |
176 | end |
177 | f.write "\n*** EOF ***\n" |
178 | |
179 | if not failed.empty? or not crashed.empty? |
180 | |
181 | f.puts "\n\n\n\nFailed tests: #{failed.inspect} \n" |
182 | |
183 | TOTEST.each do |x| |
184 | f.write marker(x) |
185 | f.write actual[x] |
186 | end |
187 | |
188 | else |
189 | f.puts "\n\n\n\tOK!\n\n\n" |
190 | end |
191 | |
192 | |
193 | md_pl = markdown_pl(markdown) |
194 | |
195 | f.write "\n*** Output of Markdown.pl ***\n" |
196 | f.write md_pl |
197 | |
198 | f.write "\n*** Output of Markdown.pl (parsed) ***\n" |
199 | begin |
200 | doc = REXML::Document.new("<div>#{md_pl}</div>",{ |
201 | :compress_whitespace=>['div','p'], |
202 | :ignore_whitespace_nodes=>['div','p'], |
203 | :respect_whitespace=>['pre','code'] |
204 | }) |
205 | div = doc.root |
206 | xml ="" |
207 | indent=1 |
208 | if $rexml_new_version |
209 | formatter = if indent > -1 |
210 | REXML::Formatters::Pretty.new( indent, ie_hack=false ) |
211 | else |
212 | REXML::Formatters::Default.new( ie_hack=false ) |
213 | end |
214 | formatter.write( div, xml) |
215 | else |
216 | div.write(xml,indent,transitive=true,ie_hack=false) |
217 | end |
218 | xml.gsub!("\A<div>(.*)</div>\Z", "\1") |
219 | f.write xml |
220 | rescue Exception=>e |
221 | f.puts "Error: #{e.inspect}" |
222 | end |
223 | f.close |
224 | |
225 | |
226 | return failed, relaxed, crashed |
227 | end |
228 | |
229 | def markdown_pl(markdown) |
230 | tmp1 = "/tmp/marutest1" |
231 | tmp2 = "/tmp/marutest2" |
232 | File.open(tmp1,'w') do |f| f.puts markdown end |
233 | system "bin/Markdown.pl < #{tmp1} > #{tmp2}" |
234 | f = File.open(tmp2,'r') |
235 | s = f.read |
236 | f.close |
237 | s |
238 | end |
239 | |
240 | def passed?(args, arg) |
241 | if args.include? arg |
242 | args.delete arg |
243 | true |
244 | else |
245 | false |
246 | end |
247 | end |
248 | |
249 | def marutest(args) |
250 | dont_worry = [] |
251 | TOTEST.each do |x| |
252 | arg = "ok:#{x}" |
253 | # puts arg |
254 | if passed?(args, arg) |
255 | dont_worry << x |
256 | end |
257 | end |
258 | |
259 | if passed?(args, 'ok') |
260 | dont_worry = TOTEST.clone |
261 | end |
262 | |
263 | if dont_worry.size > 0 |
264 | puts "Relaxed on #{dont_worry.inspect}" |
265 | end |
266 | |
267 | |
268 | failed = {} |
269 | relaxed = {} |
270 | |
271 | args.each do |f| |
272 | $stdout.write f + ' '*(50-f.size) + " " |
273 | $stdout.flush |
274 | tf, tr, tcrashed = run_test(f, dont_worry) |
275 | |
276 | tf = tf + tcrashed |
277 | |
278 | |
279 | if tr.size > 0 |
280 | $stdout.write " relax #{tr.inspect} " |
281 | end |
282 | |
283 | if tf.size>0 |
284 | $stdout.write " failed on #{tf.inspect} " |
285 | else |
286 | $stdout.write " OK " |
287 | end |
288 | |
289 | if tcrashed.size > 0 |
290 | $stdout.write " CRASHED on #{tcrashed.inspect}" |
291 | end |
292 | |
293 | $stdout.write "\n" |
294 | |
295 | failed[f] = tf |
296 | relaxed[f] = tr |
297 | end |
298 | |
299 | num_failed = 0 |
300 | failed_cat = {} |
301 | |
302 | puts "\n\n\n**** FINAL REPORT ****\n\n" |
303 | |
304 | |
305 | if failed.size > 0 |
306 | failed.each do |file, fl| |
307 | num_failed += fl.size |
308 | if fl.size > 0 |
309 | puts "\t#{file}\tfailed on #{fl.inspect}" |
310 | end |
311 | fl.each do |x| |
312 | failed_cat[x] = failed_cat[x] || 0 |
313 | failed_cat[x] = failed_cat[x] + 1 |
314 | end |
315 | end |
316 | end |
317 | |
318 | if dont_worry.size > 0 |
319 | puts "Relaxed on #{dont_worry.inspect}" |
320 | end |
321 | |
322 | if relaxed.size > 0 |
323 | relaxed.each do |file, r| |
324 | if r.size > 0 |
325 | puts "\t#{file}\t\trelaxed on #{r.inspect}" |
326 | end |
327 | end |
328 | end |
329 | |
330 | if failed_cat.size > 0 |
331 | puts "\nCategories:\n" |
332 | |
333 | failed_cat.each do |x, num| |
334 | puts "\t#{x.inspect} \tfailed #{num}/#{args.size}" |
335 | end |
336 | end |
337 | |
338 | return num_failed == 0 |
339 | end |
340 | |
341 | if File.basename(__FILE__) == 'marutest' |
342 | if ARGV.empty? |
343 | puts "marutest is a tool for running Maruku's unittest." |
344 | exit 1 |
345 | end |
346 | ok = marutest(ARGV.clone) |
347 | |
348 | exit ok ? 0 : -1 |
349 | end |
350 |