dc-kwalify 0.7.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/contrib/kwalify +1 -1
  4. data/dc-kwalify.gemspec +27 -0
  5. data/lib/kwalify/main.rb +1 -1
  6. data/lib/kwalify/util/testcase-helper.rb +1 -1
  7. data/lib/kwalify/version.rb +5 -0
  8. data/lib/kwalify.rb +1 -7
  9. metadata +83 -203
  10. data/setup.rb +0 -1585
  11. data/test/Rookbook.yaml +0 -10
  12. data/test/data/users-guide/AddressBook.java.expected +0 -40
  13. data/test/data/users-guide/BABEL.data.yaml +0 -24
  14. data/test/data/users-guide/BABEL.schema.yaml +0 -30
  15. data/test/data/users-guide/ExampleAddressBook.java +0 -47
  16. data/test/data/users-guide/Group.java.expected +0 -24
  17. data/test/data/users-guide/Person.java.expected +0 -44
  18. data/test/data/users-guide/address_book.rb +0 -52
  19. data/test/data/users-guide/address_book.schema.yaml +0 -28
  20. data/test/data/users-guide/address_book.yaml +0 -27
  21. data/test/data/users-guide/answers-schema.yaml +0 -12
  22. data/test/data/users-guide/answers-validator.rb +0 -52
  23. data/test/data/users-guide/babel_genclass.result +0 -26
  24. data/test/data/users-guide/config.schema.yaml +0 -7
  25. data/test/data/users-guide/config.yaml +0 -4
  26. data/test/data/users-guide/document01a.yaml +0 -3
  27. data/test/data/users-guide/document01b.yaml +0 -3
  28. data/test/data/users-guide/document02a.yaml +0 -4
  29. data/test/data/users-guide/document02b.yaml +0 -4
  30. data/test/data/users-guide/document03a.yaml +0 -6
  31. data/test/data/users-guide/document03b.yaml +0 -6
  32. data/test/data/users-guide/document04a.yaml +0 -9
  33. data/test/data/users-guide/document04b.yaml +0 -9
  34. data/test/data/users-guide/document05a.yaml +0 -11
  35. data/test/data/users-guide/document05b.yaml +0 -12
  36. data/test/data/users-guide/document06a.yaml +0 -15
  37. data/test/data/users-guide/document06b.yaml +0 -16
  38. data/test/data/users-guide/document07a.yaml +0 -9
  39. data/test/data/users-guide/document07b.yaml +0 -7
  40. data/test/data/users-guide/document12a.json +0 -10
  41. data/test/data/users-guide/document12b.json +0 -6
  42. data/test/data/users-guide/document13a.yaml +0 -17
  43. data/test/data/users-guide/document14a.yaml +0 -3
  44. data/test/data/users-guide/document14b.yaml +0 -3
  45. data/test/data/users-guide/document15a.yaml +0 -6
  46. data/test/data/users-guide/document15b.yaml +0 -5
  47. data/test/data/users-guide/example_address_book.rb +0 -10
  48. data/test/data/users-guide/example_address_book_java.result +0 -32
  49. data/test/data/users-guide/example_address_book_ruby.result +0 -31
  50. data/test/data/users-guide/genclass_java.result +0 -4
  51. data/test/data/users-guide/howto-validation-with-parsing.rb +0 -28
  52. data/test/data/users-guide/howto-validation.rb +0 -25
  53. data/test/data/users-guide/howto3.rb +0 -6
  54. data/test/data/users-guide/howto3.result +0 -5
  55. data/test/data/users-guide/howto3.yaml +0 -8
  56. data/test/data/users-guide/howto5_databinding.result +0 -111
  57. data/test/data/users-guide/invalid01.result +0 -3
  58. data/test/data/users-guide/invalid02.result +0 -5
  59. data/test/data/users-guide/invalid03.result +0 -5
  60. data/test/data/users-guide/invalid04.result +0 -4
  61. data/test/data/users-guide/invalid05.result +0 -11
  62. data/test/data/users-guide/invalid06.result +0 -4
  63. data/test/data/users-guide/invalid07.result +0 -3
  64. data/test/data/users-guide/invalid08.result +0 -3
  65. data/test/data/users-guide/invalid12.json +0 -8
  66. data/test/data/users-guide/invalid14.result +0 -4
  67. data/test/data/users-guide/invalid15.result +0 -4
  68. data/test/data/users-guide/loadbabel.rb +0 -27
  69. data/test/data/users-guide/loadconfig.rb +0 -16
  70. data/test/data/users-guide/loadconfig.result +0 -6
  71. data/test/data/users-guide/models.rb +0 -22
  72. data/test/data/users-guide/option_ha.result +0 -6
  73. data/test/data/users-guide/option_ha_genclass_java.result +0 -7
  74. data/test/data/users-guide/schema01.yaml +0 -3
  75. data/test/data/users-guide/schema02.yaml +0 -12
  76. data/test/data/users-guide/schema03.yaml +0 -9
  77. data/test/data/users-guide/schema04.yaml +0 -20
  78. data/test/data/users-guide/schema05.yaml +0 -29
  79. data/test/data/users-guide/schema06.yaml +0 -11
  80. data/test/data/users-guide/schema12.json +0 -12
  81. data/test/data/users-guide/schema13.yaml +0 -13
  82. data/test/data/users-guide/schema14.yaml +0 -5
  83. data/test/data/users-guide/schema15.yaml +0 -21
  84. data/test/data/users-guide/valid01.result +0 -2
  85. data/test/data/users-guide/valid02.result +0 -2
  86. data/test/data/users-guide/valid03.result +0 -2
  87. data/test/data/users-guide/valid04.result +0 -2
  88. data/test/data/users-guide/valid05.result +0 -2
  89. data/test/data/users-guide/valid06.result +0 -2
  90. data/test/data/users-guide/valid07.result +0 -2
  91. data/test/data/users-guide/valid08.result +0 -2
  92. data/test/data/users-guide/valid12.result +0 -2
  93. data/test/data/users-guide/valid13.result +0 -2
  94. data/test/data/users-guide/valid14.result +0 -2
  95. data/test/data/users-guide/valid15.result +0 -2
  96. data/test/data/users-guide/validate08.rb +0 -37
  97. data/test/test-action.rb +0 -78
  98. data/test/test-action.yaml +0 -738
  99. data/test/test-databinding.rb +0 -83
  100. data/test/test-databinding.yaml +0 -339
  101. data/test/test-main.rb +0 -157
  102. data/test/test-main.yaml +0 -415
  103. data/test/test-metavalidator.rb +0 -80
  104. data/test/test-metavalidator.yaml +0 -1179
  105. data/test/test-parser-yaml.rb +0 -57
  106. data/test/test-parser-yaml.yaml +0 -1749
  107. data/test/test-rule.rb +0 -26
  108. data/test/test-rule.yaml +0 -317
  109. data/test/test-users-guide.rb +0 -75
  110. data/test/test-util.rb +0 -125
  111. data/test/test-validator.rb +0 -95
  112. data/test/test-validator.yaml +0 -986
  113. data/test/test-yaml-parser.rb +0 -47
  114. data/test/test-yaml-parser.yaml +0 -1226
  115. data/test/test.rb +0 -61
@@ -1,83 +0,0 @@
1
- ###
2
- ### $Rev$
3
- ### $Release: 0.7.2 $
4
- ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
- ###
6
-
7
- require File.dirname(__FILE__) + '/test.rb'
8
-
9
-
10
- class DataBindingTest < Test::Unit::TestCase
11
-
12
-
13
- ## define test methods
14
- filename = __FILE__.sub(/\.rb$/, '.yaml')
15
- input = Kwalify::Util.untabify(File.read(filename))
16
- TESTDATA1 = {}
17
- YAML.load_documents(input) do |ydoc|
18
- hash_list = ydoc
19
- hash_list.each do |hash|
20
- for key in hash.keys()
21
- hash[key[0..-2]] = hash.delete(key)['ruby'] if key[-1] == ?*
22
- end
23
- name = hash['name'] or raise "name is not found."
24
- TESTDATA1.key?(name) and raise "name '#{name}' is dupilcated."
25
- TESTDATA1[name] = hash
26
- #
27
- s = ''
28
- s << "def test_#{name}\n"
29
- s << " @name = '#{name}'\n"
30
- for key, val in hash
31
- s << " @#{key} = TESTDATA1['#{name}']['#{key}']\n"
32
- end
33
- s << " _test\n"
34
- s << "end\n"
35
- eval s
36
- end
37
- end
38
- load_yaml_testdata(filename, :lang=>'ruby')
39
-
40
-
41
- def _test
42
- ## schema
43
- if @schema.is_a?(String)
44
- @schema = Kwalify::Yaml::Parser.new.parse(@schema, :untabify=>true)
45
- #@schema = YAML.load(Kwalify::Util.untabify(@schema))
46
- end
47
- ## data binding
48
- #Object.class_eval {@classdef} if @classdef
49
- if @classdef
50
- Object.class_eval @classdef
51
- end
52
- validator = Kwalify::Validator.new(@schema)
53
- parser = Kwalify::Yaml::Parser.new(validator, :data_binding=>true)
54
- @testopts ||= {}
55
- parser.preceding_alias = true if @testopts['preceding_alias']
56
- ydoc = parser.parse(@data)
57
- assert_equal(parser.errors, [])
58
- ## pp
59
- result = ''
60
- def result.write(arg); self << arg.to_s; end
61
- PP.pp(ydoc, result)
62
- ## convert object-id to portable number
63
- table = {}
64
- counter = 0
65
- result.gsub!(/:0x\w+/) {|m| ":0x%03d" % (table[m] ||= (counter+=1)) }
66
- ## assert
67
- #puts result
68
- assert_text_equal(@expected, result)
69
- ## path, linenum, column
70
- if @locations
71
- #t = parser.instance_variable_get("@location_table")
72
- #require 'pp'
73
- #pp t
74
- @locations.each do |path, expected_linenum, expected_column|
75
- linenum, column = parser.location(path)
76
- assert_equal(expected_linenum, linenum)
77
- assert_equal(expected_column, column)
78
- end
79
- end
80
- end
81
-
82
-
83
- end
@@ -1,339 +0,0 @@
1
- ##
2
- ## $Rev: 63 $
3
- ## $Release: 0.7.2 $
4
- ## copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
- ##
6
- ---
7
-
8
- - name: databind1
9
- desc: sequence of mapping
10
- schema: |
11
- type: seq
12
- sequence:
13
- - type: map
14
- class: My1::Address
15
- mapping:
16
- "name": { type: str, required: yes }
17
- "tel": { type: str }
18
- "email": { type: str }
19
- "age": { type: int }
20
- "birth": { type: date }
21
- "blood": { type: str, enum: [A, B, O, AB] }
22
- classdef*:
23
- ruby: |
24
- require 'kwalify/util/hashlike'
25
- module ::My1
26
- class Address
27
- include Kwalify::Util::HashLike
28
- attr_accessor :name, :tel, :email, :age, :birth, :blood
29
- end
30
- end
31
-
32
- data: |
33
- - name: Foo
34
- tel: 012-345-7777
35
- email: foo@mail.com
36
- age: 15
37
- birth: 1990-01-01
38
- blood: A
39
- - name: Bar
40
- tel: 012-345-8889
41
- email: bar@mail.org
42
- age: 14
43
- birth: 1991-01-02
44
- - name: Foo
45
- tel: 012-345-9999
46
- email: baz@mail.net
47
- age: 13
48
- birth: 1992-01-03
49
- blood: AB
50
- expected*:
51
- ruby: |
52
- [#<My1::Address:0x001
53
- @age=15,
54
- @birth=#<Date: 4895785/2,0,2299161>,
55
- @blood="A",
56
- @email="foo@mail.com",
57
- @name="Foo",
58
- @tel="012-345-7777">,
59
- #<My1::Address:0x002
60
- @age=14,
61
- @birth=#<Date: 4896517/2,0,2299161>,
62
- @email="bar@mail.org",
63
- @name="Bar",
64
- @tel="012-345-8889">,
65
- #<My1::Address:0x003
66
- @age=13,
67
- @birth=#<Date: 4897249/2,0,2299161>,
68
- @blood="AB",
69
- @email="baz@mail.net",
70
- @name="Foo",
71
- @tel="012-345-9999">]
72
- locations:
73
- - [ "/0", 1, 3 ]
74
- - [ "/0/name", 1, 10 ]
75
- - [ "/0/tel", 2, 10 ]
76
- - [ "/0/email", 3, 10 ]
77
- - [ "/0/age", 4, 10 ]
78
- - [ "/0/birth", 5, 10 ]
79
- - [ "/0/blood", 6, 10 ]
80
- - [ "/1", 7, 3 ]
81
- - [ "/1/name", 7, 10 ]
82
- - [ "/1/tel", 8, 10 ]
83
- - [ "/1/email", 9, 10 ]
84
- - [ "/1/age", 10, 10 ]
85
- - [ "/1/birth", 11, 10 ]
86
- - [ "/2", 12, 3 ]
87
- - [ "/2/name", 12, 10 ]
88
- - [ "/2/tel", 13, 10 ]
89
- - [ "/2/email", 14, 10 ]
90
- - [ "/2/age", 15, 10 ]
91
- - [ "/2/birth", 16, 10 ]
92
-
93
-
94
- - name: databind2
95
- desc: recursive binding
96
- schema: &context_schema |
97
- type: map
98
- class: My2::Context
99
- mapping:
100
- "groups":
101
- type: seq
102
- sequence:
103
- - type: map
104
- class: My2::Group
105
- mapping:
106
- "name":
107
- type: str
108
- required: yes
109
- "desc":
110
- type: str
111
- "owner": &userschema
112
- type: map
113
- class: My2::User
114
- mapping:
115
- "name":
116
- type: str
117
- required: yes
118
- "desc":
119
- type: str
120
- "gender":
121
- type: bool
122
- "mail":
123
- type: str
124
- "manager": *userschema
125
- "users":
126
- type: seq
127
- sequence:
128
- - *userschema
129
-
130
- classdef*: &context_classdef
131
- ruby: |
132
- require 'kwalify/util/hashlike'
133
- module ::My2
134
-
135
- class Context
136
- include Kwalify::Util::HashLike
137
- attr_accessor :groups # seq
138
- attr_accessor :users # seq
139
- end
140
-
141
- class Group
142
- include Kwalify::Util::HashLike
143
- attr_accessor :name # str
144
- attr_accessor :desc # str
145
- attr_accessor :owner # map
146
- end
147
-
148
- class User
149
- include Kwalify::Util::HashLike
150
- attr_accessor :name # str
151
- attr_accessor :gender # bool
152
- attr_accessor :mail # str
153
- attr_accessor :desc # str
154
- attr_accessor :manager # map
155
- end
156
-
157
- end
158
-
159
- data: |
160
- groups:
161
- - name: admin
162
- desc: administrator group
163
- owner: &root
164
- name: root
165
- desc: root user
166
- - name: users
167
- desc: user group
168
- owner: &guest
169
- name: guest
170
- desc: guest user
171
- users:
172
- - *root
173
- - *guest
174
- - &user1
175
- name: user1
176
- - name: user2
177
- manager: *user1
178
-
179
- expected*:
180
- ruby: |
181
- #<My2::Context:0x001
182
- @groups=
183
- [#<My2::Group:0x002
184
- @desc="administrator group",
185
- @name="admin",
186
- @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
187
- #<My2::Group:0x004
188
- @desc="user group",
189
- @name="users",
190
- @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
191
- @users=
192
- [#<My2::User:0x003 @desc="root user", @name="root">,
193
- #<My2::User:0x005 @desc="guest user", @name="guest">,
194
- #<My2::User:0x006 @name="user1">,
195
- #<My2::User:0x007
196
- @manager=#<My2::User:0x006 @name="user1">,
197
- @name="user2">]>
198
-
199
- locations:
200
- - [ "/", 1, 1 ]
201
- - [ "/groups", 2, 3 ]
202
- - [ "/groups/0", 2, 5 ]
203
- - [ "/groups/0/name", 2, 17 ]
204
- - [ "/groups/0/desc", 3, 17 ]
205
- - [ "/groups/0/owner", 4, 12 ]
206
- - [ "/groups/0/owner/name", 5, 17 ]
207
- - [ "/groups/0/owner/desc", 6, 17 ]
208
- - [ "/groups/1", 7, 5 ]
209
- - [ "/groups/1/name", 7, 17 ]
210
- - [ "/groups/1/desc", 8, 17 ]
211
- - [ "/groups/1/owner", 9, 12 ]
212
- - [ "/groups/1/owner/name", 10, 17 ]
213
- - [ "/groups/1/owner/desc", 11, 17 ]
214
- - [ "/users", 13, 3 ]
215
- - [ "/users/0", 13, 5 ]
216
- - [ "/users/0/name", 5, 17 ]
217
- - [ "/users/0/desc", 6, 17 ]
218
- - [ "/users/1", 14, 5 ]
219
- - [ "/users/1/name", 10, 17 ]
220
- - [ "/users/1/desc", 11, 17 ]
221
- - [ "/users/2", 15, 5 ]
222
- - [ "/users/2/name", 16, 11 ]
223
- - [ "/users/3", 17, 5 ]
224
- - [ "/users/3/name", 17, 11 ]
225
- - [ "/users/3/manager", 18, 14 ]
226
- - [ "/users/3/manager/name", 16, 11 ]
227
-
228
-
229
- - name: databind3
230
- desc: preceding alias
231
- testopts: { preceding_alias: yes }
232
- schema: *context_schema
233
- classdef*: *context_classdef
234
- data: |
235
- groups:
236
- - name: admin
237
- desc: administrator group
238
- owner: *root
239
- - name: users
240
- desc: user group
241
- owner: *guest
242
- users:
243
- - &root
244
- name: root
245
- desc: root user
246
- - &guest
247
- name: guest
248
- desc: guest user
249
- - name: user2
250
- manager: *user1
251
- - &user1
252
- name: user1
253
-
254
- expected*:
255
- ruby: |
256
- #<My2::Context:0x001
257
- @groups=
258
- [#<My2::Group:0x002
259
- @desc="administrator group",
260
- @name="admin",
261
- @owner=#<My2::User:0x003 @desc="root user", @name="root">>,
262
- #<My2::Group:0x004
263
- @desc="user group",
264
- @name="users",
265
- @owner=#<My2::User:0x005 @desc="guest user", @name="guest">>],
266
- @users=
267
- [#<My2::User:0x003 @desc="root user", @name="root">,
268
- #<My2::User:0x005 @desc="guest user", @name="guest">,
269
- #<My2::User:0x006
270
- @manager=#<My2::User:0x007 @name="user1">,
271
- @name="user2">,
272
- #<My2::User:0x007 @name="user1">]>
273
-
274
- locations:
275
- - [ "/", 1, 1 ]
276
- - [ "/groups", 2, 3 ]
277
- - [ "/groups/0", 2, 5 ]
278
- - [ "/groups/0/name", 2, 17 ]
279
- - [ "/groups/0/desc", 3, 17 ]
280
- - [ "/groups/0/owner", 4, 17 ]
281
- - [ "/groups/0/owner/name", 10, 17 ]
282
- - [ "/groups/0/owner/desc", 11, 17 ]
283
- - [ "/groups/1", 5, 5 ]
284
- - [ "/groups/1/name", 5, 17 ]
285
- - [ "/groups/1/desc", 6, 17 ]
286
- - [ "/groups/1/owner", 7, 17 ]
287
- - [ "/groups/1/owner/name", 13, 17 ]
288
- - [ "/groups/1/owner/desc", 14, 17 ]
289
- - [ "/users", 9, 3 ]
290
- - [ "/users/0", 9, 5 ]
291
- - [ "/users/0/name", 10, 17 ]
292
- - [ "/users/0/desc", 11, 17 ]
293
- - [ "/users/1", 12, 5 ]
294
- - [ "/users/1/name", 13, 17 ]
295
- - [ "/users/1/desc", 14, 17 ]
296
- - [ "/users/2", 15, 5 ]
297
- - [ "/users/2/name", 15, 17 ]
298
- - [ "/users/2/manager", 16, 17 ]
299
- - [ "/users/2/manager/name", 18, 17 ]
300
- - [ "/users/3", 17, 5 ]
301
- - [ "/users/3/name", 18, 17 ]
302
-
303
-
304
- - name: databind4
305
- desc: default value
306
- schema: |
307
- type: map
308
- class: Config
309
- mapping:
310
- "host": {type: str, default: localhost}
311
- "port": {type: int, default: 80}
312
- "user": {type: str, required: true}
313
- "pass": {type: str, required: true}
314
-
315
- classdef*:
316
- "ruby": |
317
- require 'kwalify/util/hashlike'
318
- class Config
319
- include Kwalify::Util::HashLike
320
- def initialize
321
- @host = 'localhost'
322
- @port = 8080
323
- end
324
- attr_accessor :host, :port, :user, :pass
325
- end
326
- "java": |
327
- data: |
328
- #host: localhost
329
- port: 8080
330
- user: user1
331
- pass: password1
332
- expected*:
333
- "ruby": |
334
- #<Config:0x001
335
- @host="localhost",
336
- @pass="password1",
337
- @port=8080,
338
- @user="user1">
339
- locations:
data/test/test-main.rb DELETED
@@ -1,157 +0,0 @@
1
- ###
2
- ### $Rev$
3
- ### $Release: 0.7.2 $
4
- ### copyright(c) 2005-2010 kuwata-lab all rights reserved.
5
- ###
6
-
7
- require File.dirname(__FILE__) + '/test.rb'
8
-
9
- require 'kwalify/main'
10
-
11
-
12
- module Kwalify
13
- class Main
14
- public :_parse_argv
15
- end
16
- end
17
-
18
-
19
- class File
20
- def self.move(filename, dirname)
21
- File.rename(filename, "#{dirname}/#{filename}")
22
- end
23
- end
24
-
25
-
26
- class MainTest < Test::Unit::TestCase
27
-
28
- ## define test methods
29
- filename = __FILE__.sub(/\.rb$/, ".yaml")
30
- load_yaml_testdata(filename, :lang=>'ruby')
31
-
32
-
33
- ## temporary directory
34
- @@tmpdir = "tmp.dir"
35
- Dir.mkdir(@@tmpdir) unless test(?d, @@tmpdir)
36
-
37
-
38
- def _test
39
- if @exception
40
- classname = @exception =~ /Kwalify::(.*)/ ? $1 : @exception
41
- @exception_class = Kwalify.const_get(classname)
42
- end
43
- case @method
44
- when 'parseOptions'
45
- _test_parse_options()
46
- when 'execute'
47
- _test_execute()
48
- when 'validation'
49
- raise "*** #{@name}: schema is not defined." unless @schema
50
- raise "*** #{@name}: valid is not defined." unless @valid
51
- raise "*** #{@name}: invalid is not defined." unless @invalid
52
- _test_validation()
53
- #when 'action'
54
- # _test_action()
55
- else
56
- raise "*** #{@method}: invalid method name."
57
- end
58
- end
59
-
60
-
61
- ## validation test
62
- def _test_validation()
63
- return if $target && $target != @name
64
- raise "*** schema is not defined." unless @schema
65
- raise "*** valid is not defined." unless @valid
66
- raise "*** invalid is not defined." unless @invalid
67
- #
68
- schema_filename = @name + ".schema"
69
- valid_filename = @name + ".valid"
70
- invalid_filename = @name + ".invalid"
71
- #
72
- begin
73
- #
74
- File.open(schema_filename, 'w') { |f| f.write(@schema) }
75
- File.open(valid_filename, 'w') { |f| f.write(@valid) }
76
- File.open(invalid_filename, 'w') { |f| f.write(@invalid) }
77
- #
78
- $stdout = StringWriter.new
79
- main = Kwalify::Main.new('kwalify')
80
- args = [ "-lf", schema_filename, valid_filename ]
81
- main.execute(args)
82
- output = $stdout; $stdout = STDOUT
83
- assert_text_equal(@valid_out, output)
84
- #
85
- $stdout = StringWriter.new
86
- main = Kwalify::Main.new('kwalify')
87
- args = [ "-lf", schema_filename, invalid_filename ]
88
- main.execute(args)
89
- output = $stdout; $stdout = STDOUT
90
- assert_text_equal(@invalid_out, output)
91
- #
92
- ensure
93
- File.move(schema_filename, @@tmpdir)
94
- File.move(valid_filename, @@tmpdir)
95
- File.move(invalid_filename, @@tmpdir)
96
- end
97
- end
98
-
99
-
100
- ## execute test
101
- def _test_execute()
102
- return if $target && $target != @name
103
- raise "*** #{@name}: args is required." unless @args
104
- raise "*** #{@name}: expected is require." unless @expected
105
- #
106
- File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
107
- File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
108
- #
109
- begin
110
- main = Kwalify::Main.new("kwalify")
111
- if @exception_class
112
- $stdout = StringWriter.new
113
- ex = assert_raise(@exception_class) do
114
- main.execute(@args)
115
- end
116
- assert_text_equal(@errormsg, ex.message) if @errormsg
117
- $stdout = STDOUT
118
- else
119
- $stdout = StringWriter.new
120
- main.execute(@args)
121
- actual = $stdout; $stdout = STDOUT
122
- assert_text_equal(@expected, actual)
123
- end
124
- ensure
125
- File.move("#{@name}.schema", @@tmpdir) if @schema
126
- File.move("#{@name}.document", @@tmpdir) if @document
127
- end
128
- end
129
-
130
-
131
- ## command option test
132
- def _test_parse_options()
133
- return if $target && $target != @name
134
- main = Kwalify::Main.new("kwalify")
135
- begin
136
- filenames = main._parse_argv(@args)
137
- s = main._inspect()
138
- s << "filenames:\n"
139
- filenames.each do |filename|
140
- s << " - #{filename}\n"
141
- end
142
- actual = s
143
- assert_text_equal(@expected, actual)
144
- rescue => ex
145
- #klass = @exception
146
- if @exception_class && ex.class == @exception_class
147
- # OK
148
- assert_equal(@error_symbol, ex.error_symbol) if ex.respond_to?(:error_symbol)
149
- else
150
- # NG
151
- raise ex
152
- end
153
- end
154
- end
155
-
156
-
157
- end