kwalify 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +24 -19
- data/README.txt +51 -51
- data/bin/kwalify +2 -2
- data/contrib/inline-require +151 -0
- data/contrib/kwalify +2850 -0
- data/doc-api/classes/CommandOptionError.html +184 -0
- data/doc-api/classes/CommandOptionParser.html +325 -0
- data/doc-api/classes/Kwalify.html +270 -0
- data/doc-api/classes/Kwalify/AssertionError.html +148 -0
- data/doc-api/classes/Kwalify/BaseError.html +296 -0
- data/doc-api/classes/Kwalify/CommandOptionError.html +168 -0
- data/doc-api/classes/Kwalify/ErrorHelper.html +218 -0
- data/doc-api/classes/Kwalify/HashInterface.html +240 -0
- data/doc-api/classes/Kwalify/KwalifyError.html +111 -0
- data/doc-api/classes/Kwalify/Main.html +336 -0
- data/doc-api/classes/Kwalify/MetaValidator.html +432 -0
- data/doc-api/classes/Kwalify/Parser.html +155 -0
- data/doc-api/classes/Kwalify/PlainYamlParser.html +520 -0
- data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +165 -0
- data/doc-api/classes/Kwalify/Rule.html +411 -0
- data/doc-api/classes/Kwalify/SchemaError.html +148 -0
- data/doc-api/classes/Kwalify/Types.html +301 -0
- data/doc-api/classes/Kwalify/ValidationError.html +148 -0
- data/doc-api/classes/Kwalify/Validator.html +311 -0
- data/doc-api/classes/Kwalify/YamlParser.html +535 -0
- data/doc-api/classes/Kwalify/YamlSyntaxError.html +168 -0
- data/doc-api/classes/Test.html +107 -0
- data/doc-api/classes/Test/Unit.html +101 -0
- data/doc-api/classes/YamlHelper.html +259 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +179 -0
- data/doc-api/files/kwalify/errors_rb.html +114 -0
- data/doc-api/files/kwalify/main_rb.html +117 -0
- data/doc-api/files/kwalify/messages_rb.html +107 -0
- data/doc-api/files/kwalify/meta-validator_rb.html +117 -0
- data/doc-api/files/kwalify/rule_rb.html +116 -0
- data/doc-api/files/kwalify/types_rb.html +114 -0
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +115 -0
- data/doc-api/files/kwalify/util/hash-interface_rb.html +107 -0
- data/doc-api/files/kwalify/util/option-parser_rb.html +107 -0
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +115 -0
- data/doc-api/files/kwalify/util/yaml-helper_rb.html +114 -0
- data/doc-api/files/kwalify/validator_rb.html +117 -0
- data/doc-api/files/kwalify/yaml-parser_rb.html +117 -0
- data/doc-api/files/kwalify_rb.html +120 -0
- data/doc-api/fr_class_index.html +50 -0
- data/doc-api/fr_file_index.html +41 -0
- data/doc-api/fr_method_index.html +109 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/users-guide.html +693 -193
- data/examples/address-book/Makefile +5 -0
- data/examples/address-book/address-book.schema.yaml +2 -1
- data/examples/invoice/Makefile +5 -0
- data/examples/invoice/invoice.schema.yaml +3 -2
- data/examples/tapkit/Makefile +5 -0
- data/examples/tapkit/main.rb +7 -0
- data/examples/tapkit/tapkit.schema.yaml +6 -1
- data/lib/kwalify.rb +3 -3
- data/lib/kwalify/errors.rb +2 -2
- data/lib/kwalify/main.rb +161 -84
- data/lib/kwalify/messages.rb +17 -11
- data/lib/kwalify/meta-validator.rb +11 -2
- data/lib/kwalify/rule.rb +13 -3
- data/lib/kwalify/templates/genclass-java.eruby +195 -0
- data/lib/kwalify/templates/genclass-ruby.eruby +84 -0
- data/lib/kwalify/types.rb +18 -18
- data/lib/kwalify/util/assert-text-equal.rb +44 -0
- data/lib/kwalify/util/hash-interface.rb +37 -0
- data/lib/kwalify/util/option-parser.rb +2 -2
- data/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/kwalify/util/yaml-helper.rb +2 -2
- data/lib/kwalify/validator.rb +2 -2
- data/lib/kwalify/yaml-parser.rb +12 -9
- data/test/test-main.rb +77 -78
- data/test/test-main.yaml +543 -769
- data/test/test-metavalidator.rb +27 -47
- data/test/test-metavalidator.yaml +21 -2
- data/test/test-rule.rb +6 -39
- data/test/test-rule.yaml +2 -2
- data/test/test-validator.rb +36 -869
- data/test/test-validator.yaml +28 -20
- data/test/test-yamlparser.rb +30 -1248
- data/test/test-yamlparser.yaml +138 -110
- data/test/test.rb +33 -13
- data/test/tmp.dir/Context.java +40 -0
- data/test/tmp.dir/Group.java +33 -0
- data/test/tmp.dir/User.java +43 -0
- data/test/tmp.dir/action1.document +18 -0
- data/test/tmp.dir/action1.schema +32 -0
- data/test/tmp.dir/action2.document +18 -0
- data/test/tmp.dir/action2.schema +32 -0
- data/test/tmp.dir/emacs.document +6 -0
- data/test/tmp.dir/emacs.schema +6 -0
- data/test/tmp.dir/meta1.document +0 -0
- data/test/tmp.dir/meta1.schema +3 -0
- data/test/tmp.dir/meta2.document +0 -0
- data/test/tmp.dir/meta2.schema +3 -0
- data/test/tmp.dir/silent1.document +3 -0
- data/test/tmp.dir/silent1.schema +3 -0
- data/test/tmp.dir/silent2.document +7 -0
- data/test/tmp.dir/silent2.schema +3 -0
- data/test/tmp.dir/stream.invalid +8 -0
- data/test/tmp.dir/stream.schema +3 -0
- data/test/tmp.dir/stream.valid +8 -0
- data/test/tmp.dir/untabify.document +5 -0
- data/test/tmp.dir/untabify.schema +10 -0
- metadata +98 -12
- data/lib/kwalify/util/assert-diff.rb +0 -44
@@ -0,0 +1,44 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 51 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'test/unit/testcase'
|
8
|
+
require 'tempfile'
|
9
|
+
|
10
|
+
|
11
|
+
class Test::Unit::TestCase # :nodoc:
|
12
|
+
|
13
|
+
def assert_text_equal(expected, actual, message=nil, options={}) # :nodoc:
|
14
|
+
diffopt = options[:diffopt] || '-u'
|
15
|
+
flag_cut = options.key?(:cut) ? options[:key] : true
|
16
|
+
|
17
|
+
if expected == actual
|
18
|
+
assert(true)
|
19
|
+
return
|
20
|
+
end
|
21
|
+
if expected[-1] != ?\n || actual[-1] != ?\n
|
22
|
+
expected += "\n"
|
23
|
+
actual += "\n"
|
24
|
+
end
|
25
|
+
begin
|
26
|
+
expfile = Tempfile.new(".expected.")
|
27
|
+
expfile.write(expected); expfile.flush()
|
28
|
+
actfile = Tempfile.new(".actual.")
|
29
|
+
actfile.write(actual); actfile.flush()
|
30
|
+
diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
|
31
|
+
ensure
|
32
|
+
expfile.close(true) if expfile
|
33
|
+
actfile.close(true) if actfile
|
34
|
+
end
|
35
|
+
# cut 1st & 2nd lines
|
36
|
+
message = (flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff) unless message
|
37
|
+
#raise Test::Unit::AssertionFailedError.new(message)
|
38
|
+
assert_block(message) { false } # or assert(false, message)
|
39
|
+
end
|
40
|
+
|
41
|
+
alias assert_equal_with_diff assert_text_equal # for compatibility
|
42
|
+
alias assert_text_equals assert_text_equal # for typo
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 51 $$
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
module Kwalify
|
8
|
+
|
9
|
+
module HashInterface
|
10
|
+
|
11
|
+
def [](key)
|
12
|
+
instance_variable_get("@{key}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def []=(key, val)
|
16
|
+
instance_variable_set("@{key}", val)
|
17
|
+
end
|
18
|
+
|
19
|
+
def keys()
|
20
|
+
instance_variables.collect { |name| name[1, name.length-1] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def key?(key)
|
24
|
+
instance_variables.include?("@#{key}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def each
|
28
|
+
instance_variables.each do |name|
|
29
|
+
key = name[1, name.length-1]
|
30
|
+
val = instance_varaible_get(name)
|
31
|
+
yield(key, val)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
###
|
2
|
+
### $Rev: 51 $
|
3
|
+
### $Release: 0.6.0 $
|
4
|
+
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'yaml'
|
8
|
+
require 'test/unit/testcase'
|
9
|
+
|
10
|
+
|
11
|
+
class Test::Unit::TestCase # :nodoc:
|
12
|
+
|
13
|
+
|
14
|
+
def self._untabify(str, width=8) # :nodoc:
|
15
|
+
sb = []
|
16
|
+
str.scan(/(.*?)\t/m) do |s, |
|
17
|
+
len = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
|
18
|
+
sb << s << (" " * (width - len % width))
|
19
|
+
end
|
20
|
+
str = (sb << $').join if $'
|
21
|
+
return str
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def self.load_yaml_documents(filename, options={}) # :nodoc:
|
26
|
+
str = File.read(filename)
|
27
|
+
if filename =~ /\.rb$/
|
28
|
+
str =~ /^__END__$/ or raise "*** error: __END__ is not found in '#{filename}'."
|
29
|
+
str = $'
|
30
|
+
end
|
31
|
+
str = _untabify(str) unless options[:tabify] == false
|
32
|
+
#
|
33
|
+
identkey = options[:identkey] || 'name'
|
34
|
+
list = []
|
35
|
+
table = {}
|
36
|
+
YAML.load_documents(str) do |ydoc|
|
37
|
+
if ydoc.is_a?(Hash)
|
38
|
+
list << ydoc
|
39
|
+
elsif ydoc.is_a?(Array)
|
40
|
+
list += ydoc
|
41
|
+
else
|
42
|
+
raise "*** invalid ydoc: #{ydoc.inspect}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
#
|
46
|
+
list.each do |ydoc|
|
47
|
+
ident = ydoc[identkey]
|
48
|
+
ident or raise "*** #{identkey} is not found."
|
49
|
+
table[ident] and raise "*** #{identkey} '#{ident}' is duplicated."
|
50
|
+
table[ident] = ydoc
|
51
|
+
yield(ydoc) if block_given?
|
52
|
+
end
|
53
|
+
#
|
54
|
+
return list
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def self.load_yaml_testdata(filename, options={}) # :nodoc:
|
59
|
+
identkey = options[:identkey] || 'name'
|
60
|
+
testmethod = options[:testmethod] || '_test'
|
61
|
+
lang = options[:lang]
|
62
|
+
load_yaml_documents(filename, options) do |ydoc|
|
63
|
+
ident = ydoc[identkey]
|
64
|
+
s = "def test_#{ident}\n"
|
65
|
+
ydoc.each do |key, val|
|
66
|
+
if key[-1] == ?*
|
67
|
+
key = key[0, key.length-1]
|
68
|
+
val = val[lang]
|
69
|
+
end
|
70
|
+
s << " @#{key} = #{val.inspect}\n"
|
71
|
+
end
|
72
|
+
s << " #{testmethod}\n"
|
73
|
+
s << "end\n"
|
74
|
+
#$stderr.puts "*** #{method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
|
75
|
+
module_eval s # not eval!
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def self.method_name # :nodoc:
|
81
|
+
return (caller[0] =~ /in `(.*?)'/) && $1
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def self.load_yaml_testdata_with_each_lang(filename, options={}) # :nodoc:
|
86
|
+
identkey = options[:identkey] || 'name'
|
87
|
+
testmethod = options[:testmethod] || '_test'
|
88
|
+
langs = defined?($lang) && $lang ? [ $lang ] : options[:langs]
|
89
|
+
langs or raise "*** #{method_name()}(): option ':langs' is required."
|
90
|
+
#
|
91
|
+
load_yaml_documents(filename, options) do |ydoc|
|
92
|
+
ident = ydoc[identkey]
|
93
|
+
langs.each do |lang|
|
94
|
+
s = "def test_#{ident}_#{lang}\n"
|
95
|
+
s << " @lang = #{lang.inspect}\n"
|
96
|
+
ydoc.each do |key, val|
|
97
|
+
if key[-1] == ?*
|
98
|
+
key = key[0, key.length-1]
|
99
|
+
val = val[lang]
|
100
|
+
end
|
101
|
+
s << " @#{key} = #{val.inspect}\n"
|
102
|
+
end
|
103
|
+
s << " #{testmethod}\n"
|
104
|
+
s << "end\n"
|
105
|
+
#$stderr.puts "*** #{method_name()}(): eval_str=<<'END'\n#{s}END" if $DEBUG
|
106
|
+
module_eval s # not eval!
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end
|
data/lib/kwalify/validator.rb
CHANGED
data/lib/kwalify/yaml-parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 51 $
|
3
|
+
### $Release: 0.6.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
@@ -193,7 +193,7 @@ module Kwalify
|
|
193
193
|
case value
|
194
194
|
when /^-( |$)/
|
195
195
|
data = parse_sequence(value_start_column, value)
|
196
|
-
when /^(
|
196
|
+
when /^(:?:?[-.\w]+\*?|'.*?'|".*?"|=|<<) *:( |$)/
|
197
197
|
#when /^:?["']?[-.\w]+["']? *:( |$)/ #'
|
198
198
|
data = parse_mapping(value_start_column, value)
|
199
199
|
when /^\[/, /^\{/
|
@@ -471,12 +471,13 @@ module Kwalify
|
|
471
471
|
|
472
472
|
def parse_block_text(column, value)
|
473
473
|
assert value =~ /^[>|\|]/
|
474
|
-
value =~ /^([>|\|])([-+]?)\s*(.*)$/
|
474
|
+
value =~ /^([>|\|])([-+]?)(\d+)?\s*(.*)$/
|
475
475
|
char = $1
|
476
476
|
indicator = $2
|
477
477
|
sep = char == "|" ? "\n" : " "
|
478
|
-
|
479
|
-
text = $
|
478
|
+
margin = $3 && !$3.empty? ? $3.to_i : nil
|
479
|
+
#text = $4.empty? ? '' : $4 + sep
|
480
|
+
text = $4
|
480
481
|
s = ''
|
481
482
|
empty = ''
|
482
483
|
min_indent = -1
|
@@ -493,8 +494,9 @@ module Kwalify
|
|
493
494
|
empty = ''
|
494
495
|
end
|
495
496
|
end
|
496
|
-
s << empty if indicator == '+'
|
497
|
+
s << empty if indicator == '+' && char != '>'
|
497
498
|
s[-1] = "" if indicator == '-'
|
499
|
+
min_indent = column + margin - 1 if margin
|
498
500
|
if min_indent > 0
|
499
501
|
sp = ' ' * min_indent
|
500
502
|
s.gsub!(/^#{sp}/, '')
|
@@ -502,6 +504,7 @@ module Kwalify
|
|
502
504
|
if char == '>'
|
503
505
|
s.gsub!(/([^\n])\n([^\n])/, '\1 \2')
|
504
506
|
s.gsub!(/\n(\n+)/, '\1')
|
507
|
+
s << empty if indicator == '+'
|
505
508
|
end
|
506
509
|
getline() if current_line() =~ /^\s*\#/
|
507
510
|
return create_scalar(text + s)
|
@@ -547,11 +550,11 @@ module Kwalify
|
|
547
550
|
|
548
551
|
def parse_mapping(column, value)
|
549
552
|
#assert value =~ /^(:?["']?[-.\w]+["']? *):(( +)(.*))?$/ #'
|
550
|
-
assert value =~ /^((?::?[-.\w]
|
553
|
+
assert value =~ /^((?::?[-.\w]+\*?|'.*?'|".*?"|=|<<) *):(( +)(.*))?$/
|
551
554
|
map = create_mapping() # {}
|
552
555
|
while true
|
553
556
|
#unless value =~ /^(:?["']?[-.\w]+["']? *):(( +)(.*))?$/ #'
|
554
|
-
unless value =~ /^((?::?[-.\w]
|
557
|
+
unless value =~ /^((?::?[-.\w]+\*?|'.*?'|".*?"|=|<<) *):(( +)(.*))?$/
|
555
558
|
#* key=:mapping_noitem msg="mapping item is expected."
|
556
559
|
raise syntax_error(:mapping_noitem)
|
557
560
|
end
|
data/test/test-main.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
###
|
2
|
-
### $Rev:
|
3
|
-
### $Release: 0.
|
2
|
+
### $Rev: 51 $
|
3
|
+
### $Release: 0.6.0 $
|
4
4
|
### copyright(c) 2005 kuwata-lab all rights reserved.
|
5
5
|
###
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
$LOAD_PATH << libdir << TESTDIR
|
11
|
-
end
|
7
|
+
require File.dirname(__FILE__) + '/test.rb'
|
8
|
+
|
9
|
+
require 'kwalify/main'
|
12
10
|
|
13
|
-
require 'test/unit'
|
14
|
-
require 'test/unit/ui/console/testrunner'
|
15
|
-
require 'kwalify'
|
16
|
-
require 'kwalify/util/assert-diff'
|
17
|
-
require 'kwalify/main.rb'
|
18
|
-
require 'yaml'
|
19
11
|
|
20
12
|
module Kwalify
|
21
13
|
class Main
|
@@ -23,64 +15,19 @@ module Kwalify
|
|
23
15
|
end
|
24
16
|
end
|
25
17
|
|
18
|
+
|
26
19
|
class File
|
27
20
|
def self.move(filename, dirname)
|
28
|
-
File.rename(filename, "#{dirname}
|
21
|
+
File.rename(filename, "#{dirname}/#{filename}")
|
29
22
|
end
|
30
23
|
end
|
31
24
|
|
25
|
+
|
32
26
|
class MainTest < Test::Unit::TestCase
|
33
27
|
|
34
28
|
## define test methods
|
35
29
|
filename = __FILE__.sub(/\.rb$/, ".yaml")
|
36
|
-
|
37
|
-
@@docs = {}
|
38
|
-
YAML.load_documents(str) do |doc|
|
39
|
-
name = doc['name']
|
40
|
-
!@@docs.key?(name) or raise "*** test name '#{name}' is duplicated."
|
41
|
-
@@docs[name] = doc
|
42
|
-
doc.each do |key, val|
|
43
|
-
doc[$1] ||= val['ruby'] if key =~ /\A(.*)\*\z/
|
44
|
-
end
|
45
|
-
s = <<-END
|
46
|
-
def test_#{name}
|
47
|
-
doc = @@docs['#{name}']
|
48
|
-
@name = doc['name']
|
49
|
-
@desc = doc['desc']
|
50
|
-
@args = doc['args']
|
51
|
-
@inspect = doc['inspect']
|
52
|
-
@exception = #{doc['exception'] ? "Kwalify::" + doc['exception'] : 'nil'}
|
53
|
-
@error_symbol = doc['error_symbol']
|
54
|
-
@expected = doc['expected']
|
55
|
-
@schema = doc['schema']
|
56
|
-
@document = doc['document']
|
57
|
-
@valid = doc['valid']
|
58
|
-
@invalid = doc['invalid']
|
59
|
-
@valid_out = doc['valid-out']
|
60
|
-
@invalid_out = doc['invalid-out']
|
61
|
-
@method = doc['method']
|
62
|
-
# @options = doc['options']
|
63
|
-
|
64
|
-
case @method
|
65
|
-
when 'parseOptions'
|
66
|
-
_test_parse_options()
|
67
|
-
when 'execute'
|
68
|
-
raise "*** #{doc['name']}: args is not defined." unless doc['args']
|
69
|
-
raise "*** #{doc['name']}: expected is not defined." unless doc['expected']
|
70
|
-
_test_execute()
|
71
|
-
when 'validation'
|
72
|
-
_test_validation()
|
73
|
-
raise "*** #{doc['name']}: schema is not defined." unless doc['schema']
|
74
|
-
raise "*** #{doc['name']}: valid is not defined." unless doc['valid']
|
75
|
-
raise "*** #{doc['name']}: invalid is not defined." unless doc['invalid']
|
76
|
-
|
77
|
-
else
|
78
|
-
raise "*** #{@method}: invalid method name."
|
79
|
-
end
|
80
|
-
end
|
81
|
-
END
|
82
|
-
eval s
|
83
|
-
end
|
30
|
+
load_yaml_testdata(filename, :lang=>'ruby')
|
84
31
|
|
85
32
|
|
86
33
|
## temporary directory
|
@@ -88,6 +35,28 @@ class MainTest < Test::Unit::TestCase
|
|
88
35
|
Dir.mkdir(@@tmpdir) unless test(?d, @@tmpdir)
|
89
36
|
|
90
37
|
|
38
|
+
def _test
|
39
|
+
if @exception
|
40
|
+
@exception_class = Kwalify.const_get(@exception)
|
41
|
+
end
|
42
|
+
case @method
|
43
|
+
when 'parseOptions'
|
44
|
+
_test_parse_options()
|
45
|
+
when 'execute'
|
46
|
+
_test_execute()
|
47
|
+
when 'validation'
|
48
|
+
raise "*** #{@name}: schema is not defined." unless @schema
|
49
|
+
raise "*** #{@name}: valid is not defined." unless @valid
|
50
|
+
raise "*** #{@name}: invalid is not defined." unless @invalid
|
51
|
+
_test_validation()
|
52
|
+
when 'action'
|
53
|
+
_test_action()
|
54
|
+
else
|
55
|
+
raise "*** #{@method}: invalid method name."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
91
60
|
## validation test
|
92
61
|
def _test_validation()
|
93
62
|
return if $target && $target != @name
|
@@ -108,12 +77,12 @@ class MainTest < Test::Unit::TestCase
|
|
108
77
|
main = Kwalify::Main.new('kwalify')
|
109
78
|
args = [ "-lf", schema_filename, valid_filename ]
|
110
79
|
output = main.execute(args)
|
111
|
-
|
80
|
+
assert_text_equal(@valid_out, output)
|
112
81
|
#
|
113
82
|
main = Kwalify::Main.new('kwalify')
|
114
83
|
args = [ "-lf", schema_filename, invalid_filename ]
|
115
84
|
output = main.execute(args)
|
116
|
-
|
85
|
+
assert_text_equal(@invalid_out, output)
|
117
86
|
#
|
118
87
|
ensure
|
119
88
|
File.move(schema_filename, @@tmpdir)
|
@@ -122,31 +91,33 @@ class MainTest < Test::Unit::TestCase
|
|
122
91
|
end
|
123
92
|
end
|
124
93
|
|
94
|
+
|
125
95
|
## execute test
|
126
96
|
def _test_execute()
|
127
97
|
return if $target && $target != @name
|
128
|
-
raise "*** args is required
|
129
|
-
raise "*** expected is
|
98
|
+
raise "*** #{@name}: args is required." unless @args
|
99
|
+
raise "*** #{@name}: expected is require." unless @expected
|
130
100
|
#
|
131
101
|
File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
|
132
102
|
File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
|
133
103
|
#
|
134
104
|
begin
|
135
105
|
main = Kwalify::Main.new("kwalify")
|
136
|
-
if
|
137
|
-
|
138
|
-
assert_equal_with_diff(@expected, actual)
|
139
|
-
else
|
140
|
-
assert_raise(@exception) do
|
106
|
+
if @exception_class
|
107
|
+
assert_raise(@exception_class) do
|
141
108
|
main.execute(@args)
|
142
109
|
end
|
110
|
+
else
|
111
|
+
actual = main.execute(@args)
|
112
|
+
assert_text_equal(@expected, actual)
|
143
113
|
end
|
144
114
|
ensure
|
145
115
|
File.move("#{@name}.schema", @@tmpdir) if @schema
|
146
116
|
File.move("#{@name}.document", @@tmpdir) if @document
|
147
117
|
end
|
148
118
|
end
|
149
|
-
|
119
|
+
|
120
|
+
|
150
121
|
## command option test
|
151
122
|
def _test_parse_options()
|
152
123
|
return if $target && $target != @name
|
@@ -159,10 +130,10 @@ class MainTest < Test::Unit::TestCase
|
|
159
130
|
s << " - #{filename}\n"
|
160
131
|
end
|
161
132
|
actual = s
|
162
|
-
|
133
|
+
assert_text_equal(@expected, actual)
|
163
134
|
rescue => ex
|
164
135
|
#klass = @exception
|
165
|
-
if @
|
136
|
+
if @exception_class && ex.class == @exception_class
|
166
137
|
# OK
|
167
138
|
assert_equal(@error_symbol, ex.error_symbol) if ex.respond_to?(:error_symbol)
|
168
139
|
else
|
@@ -172,8 +143,36 @@ class MainTest < Test::Unit::TestCase
|
|
172
143
|
end
|
173
144
|
end
|
174
145
|
|
175
|
-
end
|
176
146
|
|
177
|
-
|
178
|
-
|
179
|
-
|
147
|
+
## execute test
|
148
|
+
def _test_action()
|
149
|
+
return if $target && $target != @name
|
150
|
+
raise "*** #{@name}: args is required." unless @args
|
151
|
+
raise "*** #{@name}: expected is require." unless @expected
|
152
|
+
#
|
153
|
+
File.open("#{@name}.schema", 'w') { |f| f.write(@schema) } if @schema
|
154
|
+
File.open("#{@name}.document", 'w') { |f| f.write(@document) } if @document
|
155
|
+
#
|
156
|
+
begin
|
157
|
+
main = Kwalify::Main.new("kwalify")
|
158
|
+
actual = main.execute(@args)
|
159
|
+
if @output_files
|
160
|
+
assert(actual.nil? || actual=='')
|
161
|
+
@output_files.each do |filename|
|
162
|
+
actual = File.read(filename)
|
163
|
+
assert_text_equal(@expected[filename], actual)
|
164
|
+
end
|
165
|
+
else
|
166
|
+
assert_text_equal(@expected, actual)
|
167
|
+
end
|
168
|
+
ensure
|
169
|
+
File.move("#{@name}.schema", @@tmpdir) if @schema
|
170
|
+
File.move("#{@name}.document", @@tmpdir) if @document
|
171
|
+
@output_files.each do |filename|
|
172
|
+
File.move(filename, @@tmpdir) if @document
|
173
|
+
end if @output_files
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
end
|