Skip to content
Browse files

Merge pull request #13 from kares/master

test updates
  • Loading branch information...
2 parents 3e4d763 + 03b5721 commit 8315c199ce24956a939fd11d1b4c1e969db9b04e @jashkenas jashkenas committed Jul 29, 2011
Showing with 31 additions and 16 deletions.
  1. +8 −9 Rakefile
  2. +5 −0 test/test_helper.rb
  3. +18 −7 test/unit/{test_closure_compiler.rb → closure_compiler_test.rb}
View
17 Rakefile
@@ -1,12 +1,9 @@
-desc 'Run all tests'
+require "rake/testtask"
-task :default => :test
-task :test do
- $LOAD_PATH.unshift(File.expand_path('lib'))
- $LOAD_PATH.unshift(File.expand_path('test'))
- require 'redgreen' if Gem.available?('redgreen') and RUBY_VERSION < "1.9"
- require 'test/unit'
- Dir['test/**/test_*.rb'].each {|test| require test }
+Rake::TestTask.new do |t|
+ t.libs += ["lib", "test"]
+ t.test_files = FileList["test/**/*_test.rb"]
+ t.verbose = true
end
namespace :gem do
@@ -22,4 +19,6 @@ namespace :gem do
sh "sudo gem uninstall -x closure-compiler"
end
-end
+end
+
+task :default => :test
View
5 test/test_helper.rb
@@ -1,3 +1,8 @@
+if defined?(Gem) and Gem.available?('redgreen')
+ require 'redgreen' if RUBY_VERSION < "1.9"
+end
+require 'test/unit'
+
require 'closure-compiler'
class Test::Unit::TestCase
View
25 test/unit/test_closure_compiler.rb → test/unit/closure_compiler_test.rb
@@ -32,19 +32,25 @@ def test_block_syntax
end
assert result == COMPILED_ADVANCED
end
-
+
def test_jar_and_java_specifiation
jar = Dir['vendor/closure-compiler-*.jar'].first
- java = `which java`.strip
- compiler = Compiler.new(:java => java, :jar_file => jar)
- assert compiler.compress(ORIGINAL) == COMPILED_SIMPLE
+ unless java = ( `which java` rescue nil )
+ java = `where java` rescue nil # works on newer windows
+ end
+ if java
+ compiler = Compiler.new(:java => java.strip, :jar_file => jar)
+ assert compiler.compress(ORIGINAL) == COMPILED_SIMPLE
+ else
+ puts "could not `which/where java` skipping test"
+ end
end
def test_exceptions
- assert_raises(Closure::Error) do
+ assert_raise(Closure::Error) do
Compiler.new.compile('1++')
end
- assert_raises(Closure::Error) do
+ assert_raise(Closure::Error) do
Compiler.new.compile('obj = [1 2, 3]')
end
end
@@ -59,7 +65,12 @@ def test_permissions
end
def test_serialize_options
- assert_equal ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"], Closure::Compiler.new.send(:serialize_options, 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS")
+ options = { 'externs' => 'library1.js', "compilation_level" => "ADVANCED_OPTIMIZATIONS" }
+ # ["--externs", "library1.js", "--compilation_level", "ADVANCED_OPTIMIZATIONS"]
+ # although Hash in 1.8 might change the order to :
+ # ["--compilation_level", "ADVANCED_OPTIMIZATIONS", "--externs", "library1.js"]
+ expected_options = options.to_a.map { |arr| [ "--#{arr[0]}", arr[1] ] }.flatten
+ assert_equal expected_options, Closure::Compiler.new.send(:serialize_options, options)
end
def test_serialize_options_for_arrays

0 comments on commit 8315c19

Please sign in to comment.
Something went wrong with that request. Please try again.