testdata 0.2.12 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/testdata.rb +65 -11
  2. metadata +13 -4
data/lib/testdata.rb CHANGED
@@ -2,12 +2,15 @@
2
2
 
3
3
  # file: testdata.rb
4
4
 
5
+ require 'builder'
5
6
  require 'rexml/document'
6
7
 
7
8
  class Path
8
9
  include REXML
9
10
 
10
- def initialize(doc, success) @doc, @success = doc, success end
11
+ def initialize(doc, log, success)
12
+ @doc, @log, @success = doc, log, success
13
+ end
11
14
 
12
15
  def tested? description
13
16
 
@@ -19,6 +22,7 @@ class Path
19
22
  output_values = XPath.match(node, "records/io/summary[type='output']/*").map(&stringify)
20
23
 
21
24
  path_no = node.text('summary/path')
25
+ actual = XPath.first(@log.root, "records/result[path_no='#{path_no}']/actual")
22
26
 
23
27
 
24
28
  result = nil
@@ -36,14 +40,17 @@ class Path
36
40
  if raw_result then
37
41
  a = [raw_result].flatten.map(&:strip)
38
42
  b = expected.map(&:strip)
39
- #puts 'a : ' + a.inspect + ' a :' + a[0].length.to_s
40
- #puts 'b : ' + b.inspect + ' b :' + b[0].length.to_s
41
- result = [raw_result].flatten.map(&:strip) == expected.map(&:strip)
43
+ actual.text = a.join("\n")[/</] ? CData.new("\n%s\n" % a.join("\n")) : a.join("\n")
44
+
45
+ # puts 'a : ' + a.inspect + ' a :' + a[0].length.to_s
46
+ # puts 'b : ' + b.inspect + ' b :' + b[0].length.to_s
47
+ result = a == b
42
48
  else
43
49
  result = [raw_result].compact == expected
44
50
  end
45
51
 
46
52
  rescue
53
+ puts 'error: ' + ($!).to_s
47
54
  result = false
48
55
  ensure
49
56
  @success[-1][0] = result
@@ -61,14 +68,23 @@ class Testdata
61
68
 
62
69
  def initialize(s)
63
70
  #puts 'filex : ' + $0
71
+ #puts 'filez : ' + __FILE__
72
+ #puts 'pwd : ' + Dir.pwd
73
+ #exit
64
74
  @filepath = File.dirname s
65
75
  buffer = self.send('read_' + (s[/https?:\/\//] ? 'file' : 'url'), s)
66
76
  @doc = Document.new(buffer)
67
77
  raise "Testdata error: doc %s not found" % s unless @doc
68
78
  @success = []
79
+
80
+ @log = Document.new(tests)
81
+ end
82
+
83
+ def paths()
84
+ yield(path = Path.new(@doc, @log, @success))
85
+ File.open(Dir.pwd + '/.test_log.xml','w'){|f| f.write @log }
69
86
  end
70
87
 
71
- def paths() yield(path = Path.new(@doc, @success)) end
72
88
  def read_file(s) File.open(s, 'r').read end
73
89
  def read_url(xml_url) open(xml_url, 'UserAgent' => 'S-Rscript').read end
74
90
 
@@ -79,6 +95,12 @@ class Testdata
79
95
  {false: @success.select{|x| x[0] == false}.map(&:last).sort,
80
96
  nil: ((a[0]..a[-1]).to_a - a)}
81
97
  end
98
+
99
+ def find_by(s)
100
+ XPath.match(@doc.root, "records/test/summary[type='#{s}']/description/text()").map(&:to_s)
101
+ end
102
+
103
+ private
82
104
 
83
105
  def tests()
84
106
  script = XPath.first(@doc.root, "summary/script/text()").to_s
@@ -104,7 +126,7 @@ class Testdata
104
126
  path_no = node.text('summary/path').to_s
105
127
  output_values = XPath.match(node, "records/io/summary[type='output']/*").map(&stringify)
106
128
  raw_output = (output_values - ['output'])
107
- output = "#=> " + raw_output.join("\n")
129
+ output = raw_output.join("\n")
108
130
 
109
131
  values = input_values - ['input']
110
132
  body = content[i][2].strip.gsub("\n ","\n")
@@ -113,13 +135,45 @@ class Testdata
113
135
  body.gsub!(/#{keyword}(?!:)/, "'%s'" % value )
114
136
  end
115
137
  end
116
- ["# #{path_no}) #{content[i][0]}\n", body + "\n", output + "\n\n"]
138
+ [path_no, content[i][0], body, output]
117
139
  end
118
140
 
119
- r.each {|x| x.join("\n")}.join("\n")
141
+ #r.each {|x| x.join("\n")}.join("\n")
142
+ tests_to_dynarex(r)
120
143
  end
121
-
122
- def find_by(s)
123
- XPath.match(@doc.root, "records/test/summary[type='#{s}']/description/text()").map(&:to_s)
144
+
145
+ def tests_to_dynarex(tests)
146
+
147
+ xml = Builder::XmlMarkup.new( target: buffer='', indent: 2 )
148
+ xml.instruct! :xml, version: "1.0", encoding: "UTF-8"
149
+
150
+ xml.results do
151
+ xml.summary do
152
+ xml.recordx_type 'dynarex'
153
+ xml.format_mask '[!path_no] [!title] [!test] [!expected] [!actual]'
154
+ xml.schema 'results/result(path_no, title, test, expected, actual)'
155
+ end
156
+ xml.records do
157
+ tests.each do |path_no, title, test, expected|
158
+ xml.result do
159
+ xml.path_no path_no
160
+ xml.title title
161
+
162
+ xml.test do
163
+ test[/[<>]/] ? xml.cdata!("\n%s\n" % test) : test
164
+ end
165
+
166
+ xml.expected do
167
+ expected[/</] ? xml.cdata!("\n%s\n" % expected) : expected
168
+ end
169
+
170
+ xml.actual
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ buffer
124
177
  end
178
+
125
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2011-01-04 00:00:00 +00:00
12
+ date: 2011-01-09 00:00:00 +00:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description:
17
26
  email:
18
27
  executables: []