1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
#
# License: Ruby's or LGPL
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require "gettext/tools/task"
class TestToolsTask < Test::Unit::TestCase
setup :before => :append
def setup_task
@task = GetText::Tools::Task.new
end
setup
def setup_application
@application = Rake::Application.new
@original_application = Rake.application
Rake.application = @application
end
teardown
def teardown
Rake.application = @original_application
end
setup
def setup_record_task_metadata
@original_record_task_metadata = Rake::TaskManager.record_task_metadata
Rake::TaskManager.record_task_metadata = true
end
teardown
def teardown_record_task_metadata
Rake::TaskManager.record_task_metadata = @original_record_task_metadata
end
class TestPackageName < self
def test_default
assert_nil(@task.package_name)
end
def test_accessor
package_name = "great application"
@task.package_name = package_name
assert_equal(package_name, @task.package_name)
end
def test_spec
spec = Gem::Specification.new
spec.name = "great-application"
@task.spec = spec
assert_equal(spec.name, @task.package_name)
end
end
class TestPackageVersion < self
def test_default
assert_nil(@task.package_version)
end
def test_accessor
package_version = "1.0"
@task.package_version = package_version
assert_equal(package_version, @task.package_version)
end
def test_spec
version = "1.0"
spec = Gem::Specification.new
spec.version = version
@task.spec = spec
assert_equal(version, @task.package_version)
end
end
class TestDomain < self
def test_default
assert_nil(@task.domain)
end
def test_accessor
domain = "hello"
@task.domain = domain
assert_equal(domain, @task.domain)
end
class TestSpec < self
def setup
@spec = Gem::Specification.new
@spec.name = "hello"
end
def test_not_set
@task.spec = @spec
assert_equal(@spec.name, @task.domain)
end
def test_already_set
domain = "#{@spec.name}-world"
@task.domain = domain
@task.spec = @spec
assert_equal(domain, @task.domain)
end
end
end
class TestFiles < self
def test_default
assert_equal([], @task.files)
end
def test_accessor
files = [
"lib/hellor.rb",
"lib/world.rb",
]
@task.files = files
assert_equal(files, @task.files)
end
class TestSpec < self
def setup
@spec = Gem::Specification.new
@spec.files = [
"lib/hellor.rb",
"lib/world.rb",
]
end
def test_not_set
@task.spec = @spec
assert_equal(@spec.files, @task.files)
end
def test_already_set
files = [
"lib/hello/world.rb",
]
@task.files = files
@task.spec = @spec
assert_equal(files + @spec.files, @task.files)
end
end
class TestTask < self
setup :before => :append
def setup_domain
@task.domain = "hello"
end
def test_empty
@task.files = []
error = assert_raise(GetText::Tools::Task::ValidationError) do
@task.define
end
assert_equal({"files" => "must set one or more files"},
error.reasons)
end
class TestPOT < self
def setup
@path = @task.send(:create_path)
end
def test_prerequisites
@task.files = [__FILE__]
@task.define
assert_equal([__FILE__],
Rake::Task[@path.pot_file.to_s].prerequisites)
end
end
class TestPO < self
def setup
@locale = "ja"
@task.locales = [@locale]
@path = @task.send(:create_path, @locale)
end
def test_prerequisites
@task.files = [__FILE__]
@task.define
assert_equal([@path.edit_po_file.to_s, @path.po_directory.to_s],
Rake::Task[@path.po_file.to_s].prerequisites)
end
end
class TestMO < self
def setup
@locale = "ja"
@task.locales = [@locale]
@path = @task.send(:create_path, @locale)
end
def test_prerequisites
@task.files = [__FILE__]
@task.define
assert_equal([@path.po_file.to_s, @path.mo_directory.to_s],
Rake::Task[@path.mo_file.to_s].prerequisites)
end
end
end
end
class TestEnableDescription < self
def test_default
assert_true(@task.enable_description?)
end
def test_accessor
@task.enable_description = false
assert_false(@task.enable_description?)
end
class TestTask < self
def setup
@task.domain = "hello"
@task.files = [__FILE__]
end
def test_true
@task.enable_description = true
@task.define
assert_not_nil(task.comment)
end
def test_false
@task.enable_description = false
@task.define
assert_nil(task.comment)
end
private
def task
Rake::Task["gettext:po:update"]
end
end
end
class TestEnablePO < self
def test_default
assert_true(@task.enable_po?)
end
def test_accessor
@task.enable_po = false
assert_false(@task.enable_po?)
end
class TestTask < self
def setup
@task.domain = "hello"
end
def test_true
@task.enable_po = true
error = assert_raise(GetText::Tools::Task::ValidationError) do
@task.define
end
assert_equal({"files" => "must set one or more files"},
error.reasons)
end
def test_false
@task.enable_po = false
@task.define
task_names = @application.tasks.collect(&:name)
assert_equal([], task_names.grep(/\Agettext:po/))
end
end
end
end
|