grntest 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -0
- data/README.md +208 -0
- data/Rakefile +43 -0
- data/bin/grntest +20 -0
- data/doc/text/gpl-3.0.txt +674 -0
- data/doc/text/news.md +5 -0
- data/grntest.gemspec +53 -0
- data/lib/grntest/tester.rb +2073 -0
- data/lib/grntest/version.rb +18 -0
- data/test/run-test.rb +29 -0
- data/test/test-executor.rb +193 -0
- metadata +176 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Grntest
|
17
|
+
VERSION = "1.0.0"
|
18
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
$VERBOSE = true
|
19
|
+
|
20
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
21
|
+
lib_dir = File.join(base_dir, "lib")
|
22
|
+
test_dir = File.join(base_dir, "test")
|
23
|
+
|
24
|
+
$LOAD_PATH.unshift(lib_dir)
|
25
|
+
|
26
|
+
require 'test-unit'
|
27
|
+
require 'test/unit/rr'
|
28
|
+
|
29
|
+
exit(Test::Unit::AutoRunner.run(true))
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "stringio"
|
17
|
+
require "cgi/util"
|
18
|
+
require "grntest/tester"
|
19
|
+
|
20
|
+
class TestExecutor < Test::Unit::TestCase
|
21
|
+
def setup
|
22
|
+
input = StringIO.new
|
23
|
+
output = StringIO.new
|
24
|
+
@executor = Grntest::Tester::StandardIOExecutor.new(input, output)
|
25
|
+
@context = @executor.context
|
26
|
+
@script = Tempfile.new("test-executor")
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def execute(command)
|
31
|
+
@script.print(command)
|
32
|
+
@script.close
|
33
|
+
@executor.execute(Pathname(@script.path))
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestComment < self
|
37
|
+
def test_disable_logging
|
38
|
+
assert_predicate(@context, :logging?)
|
39
|
+
execute("# disable-logging")
|
40
|
+
assert_not_predicate(@context, :logging?)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_enable_logging
|
44
|
+
@context.logging = false
|
45
|
+
assert_not_predicate(@context, :logging?)
|
46
|
+
execute("# enable-logging")
|
47
|
+
assert_predicate(@context, :logging?)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_suggest_create_dataset
|
51
|
+
mock(@executor).execute_suggest_create_dataset("shop")
|
52
|
+
execute("# suggest-create-dataset shop")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class TestCommandFormatConveter < self
|
57
|
+
def test_without_argument_name
|
58
|
+
command = "table_create Site TABLE_HASH_KEY ShortText"
|
59
|
+
arguments = {
|
60
|
+
"name" => "Site",
|
61
|
+
"flags" => "TABLE_HASH_KEY",
|
62
|
+
"key_type" => "ShortText",
|
63
|
+
}
|
64
|
+
actual_url = convert(command)
|
65
|
+
expected_url = build_url("table_create", arguments)
|
66
|
+
|
67
|
+
assert_equal(expected_url, actual_url)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_with_argument_name
|
71
|
+
command = "select --table Sites"
|
72
|
+
actual_url = convert(command)
|
73
|
+
expected_url = build_url("select", "table" => "Sites")
|
74
|
+
|
75
|
+
assert_equal(expected_url, actual_url)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_non_named_argument_after_named_arguement
|
79
|
+
command = "table_create --flags TABLE_HASH_KEY --key_type ShortText Site"
|
80
|
+
arguments = {
|
81
|
+
"flags" => "TABLE_HASH_KEY",
|
82
|
+
"key_type" => "ShortText",
|
83
|
+
"name" => "Site",
|
84
|
+
}
|
85
|
+
actual_url = convert(command)
|
86
|
+
expected_url = build_url("table_create", arguments)
|
87
|
+
|
88
|
+
assert_equal(expected_url, actual_url)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_without_arguments
|
92
|
+
command = "dump"
|
93
|
+
actual_url = convert(command)
|
94
|
+
expected_url = build_url(command, {})
|
95
|
+
|
96
|
+
assert_equal(expected_url, actual_url)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_load_json_array
|
100
|
+
load_command = "load --table Sites"
|
101
|
+
load_values = <<EOF
|
102
|
+
[
|
103
|
+
["_key","uri"],
|
104
|
+
["groonga","http://groonga.org/"],
|
105
|
+
["razil","http://razil.jp/"]
|
106
|
+
]
|
107
|
+
EOF
|
108
|
+
command = "#{load_command}\n#{load_values}"
|
109
|
+
actual_url = convert(command)
|
110
|
+
arguments = {
|
111
|
+
"table" => "Sites",
|
112
|
+
"values" => load_values
|
113
|
+
}
|
114
|
+
expected_url = build_url("load", arguments)
|
115
|
+
|
116
|
+
assert_equal(expected_url, actual_url)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_load_json_object
|
120
|
+
load_command = "load --table Sites"
|
121
|
+
load_values = <<EOF
|
122
|
+
[
|
123
|
+
{"_key": "ruby", "uri": "http://ruby-lang.org/"}
|
124
|
+
]
|
125
|
+
EOF
|
126
|
+
command = "#{load_command}\n#{load_values}"
|
127
|
+
actual_url = convert(command)
|
128
|
+
|
129
|
+
arguments = {
|
130
|
+
"table" => "Sites",
|
131
|
+
"values" => load_values
|
132
|
+
}
|
133
|
+
expected_url = build_url("load", arguments)
|
134
|
+
|
135
|
+
assert_equal(expected_url, actual_url)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_value_single_quote
|
139
|
+
command = "select Sites --output_columns '_key, uri'"
|
140
|
+
arguments = {
|
141
|
+
"table" => "Sites",
|
142
|
+
"output_columns" => "_key, uri",
|
143
|
+
}
|
144
|
+
actual_url = convert(command)
|
145
|
+
expected_url = build_url("select", arguments)
|
146
|
+
|
147
|
+
assert_equal(expected_url, actual_url)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_value_double_quote_in_single_quote
|
151
|
+
command = "select Sites --filter 'uri @ \"ruby\"'"
|
152
|
+
arguments = {
|
153
|
+
"table" => "Sites",
|
154
|
+
"filter" => "uri @ \"ruby\"",
|
155
|
+
}
|
156
|
+
actual_url = convert(command)
|
157
|
+
expected_url = build_url("select", arguments)
|
158
|
+
|
159
|
+
assert_equal(expected_url, actual_url)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_value_double_quote
|
163
|
+
command = "select Sites --output_columns \"_key, uri\""
|
164
|
+
arguments = {
|
165
|
+
"table" => "Sites",
|
166
|
+
"output_columns" => "_key, uri",
|
167
|
+
}
|
168
|
+
actual_url = convert(command)
|
169
|
+
expected_url = build_url("select", arguments)
|
170
|
+
|
171
|
+
assert_equal(expected_url, actual_url)
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
def convert(command)
|
176
|
+
converter = Grntest::Tester::CommandFormatConverter.new(command)
|
177
|
+
converter.to_url
|
178
|
+
end
|
179
|
+
|
180
|
+
def build_url(command, named_arguments)
|
181
|
+
url = "/d/#{command}"
|
182
|
+
query_parameters = []
|
183
|
+
named_arguments.each do |name, argument|
|
184
|
+
query_parameters << "#{CGI.escape(name)}=#{CGI.escape(argument)}"
|
185
|
+
end
|
186
|
+
unless query_parameters.empty?
|
187
|
+
url << "?"
|
188
|
+
url << query_parameters.join("&")
|
189
|
+
end
|
190
|
+
url
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grntest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kouhei Sutou
|
9
|
+
- Haruka Yoshihara
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: msgpack
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rake
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: test-unit
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: packnga
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redcarpet
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: ''
|
128
|
+
email:
|
129
|
+
- kou@clear-code.com
|
130
|
+
- yoshihara@clear-code.com
|
131
|
+
executables:
|
132
|
+
- grntest
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- Gemfile
|
139
|
+
- grntest.gemspec
|
140
|
+
- lib/grntest/tester.rb
|
141
|
+
- lib/grntest/version.rb
|
142
|
+
- doc/text/news.md
|
143
|
+
- doc/text/gpl-3.0.txt
|
144
|
+
- test/run-test.rb
|
145
|
+
- test/test-executor.rb
|
146
|
+
- bin/grntest
|
147
|
+
homepage: https://github.com/groonga/grntest
|
148
|
+
licenses:
|
149
|
+
- GPLv3 or later
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 1.8.23
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: Grntest is a testing framework for groonga. You can write a test for groonga
|
172
|
+
by writing groonga commands and expected result.
|
173
|
+
test_files:
|
174
|
+
- test/run-test.rb
|
175
|
+
- test/test-executor.rb
|
176
|
+
has_rdoc:
|