Skip to content

Commit 8315c19

Browse files
committed
Merge pull request #13 from kares/master
test updates
2 parents 3e4d763 + 03b5721 commit 8315c19

3 files changed

Lines changed: 31 additions & 16 deletions

File tree

Rakefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
desc 'Run all tests'
1+
require "rake/testtask"
22

3-
task :default => :test
4-
task :test do
5-
$LOAD_PATH.unshift(File.expand_path('lib'))
6-
$LOAD_PATH.unshift(File.expand_path('test'))
7-
require 'redgreen' if Gem.available?('redgreen') and RUBY_VERSION < "1.9"
8-
require 'test/unit'
9-
Dir['test/**/test_*.rb'].each {|test| require test }
3+
Rake::TestTask.new do |t|
4+
t.libs += ["lib", "test"]
5+
t.test_files = FileList["test/**/*_test.rb"]
6+
t.verbose = true
107
end
118

129
namespace :gem do
@@ -22,4 +19,6 @@ namespace :gem do
2219
sh "sudo gem uninstall -x closure-compiler"
2320
end
2421

25-
end
22+
end
23+
24+
task :default => :test

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if defined?(Gem) and Gem.available?('redgreen')
2+
require 'redgreen' if RUBY_VERSION < "1.9"
3+
end
4+
require 'test/unit'
5+
16
require 'closure-compiler'
27

38
class Test::Unit::TestCase
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ def test_block_syntax
3232
end
3333
assert result == COMPILED_ADVANCED
3434
end
35-
35+
3636
def test_jar_and_java_specifiation
3737
jar = Dir['vendor/closure-compiler-*.jar'].first
38-
java = `which java`.strip
39-
compiler = Compiler.new(:java => java, :jar_file => jar)
40-
assert compiler.compress(ORIGINAL) == COMPILED_SIMPLE
38+
unless java = ( `which java` rescue nil )
39+
java = `where java` rescue nil # works on newer windows
40+
end
41+
if java
42+
compiler = Compiler.new(:java => java.strip, :jar_file => jar)
43+
assert compiler.compress(ORIGINAL) == COMPILED_SIMPLE
44+
else
45+
puts "could not `which/where java` skipping test"
46+
end
4147
end
4248

4349
def test_exceptions
44-
assert_raises(Closure::Error) do
50+
assert_raise(Closure::Error) do
4551
Compiler.new.compile('1++')
4652
end
47-
assert_raises(Closure::Error) do
53+
assert_raise(Closure::Error) do
4854
Compiler.new.compile('obj = [1 2, 3]')
4955
end
5056
end
@@ -59,7 +65,12 @@ def test_permissions
5965
end
6066

6167
def test_serialize_options
62-
assert_equal ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"], Closure::Compiler.new.send(:serialize_options, 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS")
68+
options = { 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS" }
69+
# ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"]
70+
# although Hash in 1.8 might change the order to :
71+
# ["--compilation_level", "ADVANCED_OPTIMIZATIONS", "--externs", "library1.js"]
72+
expected_options = options.to_a.map { |arr| [ "--#{arr[0]}", arr[1] ] }.flatten
73+
assert_equal expected_options, Closure::Compiler.new.send(:serialize_options, options)
6374
end
6475

6576
def test_serialize_options_for_arrays

0 commit comments

Comments
 (0)