File: test_jruby_internals.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (51 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download | duplicates (7)
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
require 'test/unit'

class TestJRubyInternals < Test::Unit::TestCase
  def setup
    @dir = File.join(Dir.pwd, "dir with spaces")
    @file = File.join(@dir, "test_file")
    Dir.mkdir(@dir)
    File.open(@file, "w") {|f| f << "hello"}
  end

  def teardown
    File.unlink @file
    Dir.rmdir @dir
  end

  def test_smart_split_paths
    require 'jruby/path_helper'
    assert_equal %w(foo bar blah),
      JRuby::PathHelper.smart_split_command("foo bar blah")
    assert_equal [@file, *(%w{foo bar blah})],
      JRuby::PathHelper.smart_split_command("#@file foo bar blah")
  end

  def test_split_command_around_quotes
    assert_equal %w(foo bar baz quux),
      JRuby::PathHelper.quote_sensitive_split(%{foo bar baz quux})
    assert_equal ["foo", "bar baz", "quux"],
      JRuby::PathHelper.quote_sensitive_split(%{foo "bar baz" quux})
    assert_equal ["foo", "bar \" baz", "quux"],
      JRuby::PathHelper.quote_sensitive_split(%{foo "bar \\\" baz" quux})
    assert_equal ["foo", "bar baz", "quux"],
      JRuby::PathHelper.quote_sensitive_split(%{"foo" "bar baz" quux})
    assert_equal ["foo", "bar \" baz", "quux"],
      JRuby::PathHelper.quote_sensitive_split(%{"foo" 'bar " baz' quux})
  end

  def test_split_typical_ruby_command_line
    assert_equal ["ruby", "-e", "require 'java'; puts java.lang.System.getProperty('java.class.path')"],
      JRuby::PathHelper.quote_sensitive_split(
        "ruby -e   \"require 'java'; puts java.lang.System.getProperty('java.class.path')\""
      )
  end

  def test_unquoted_executable_with_quoted_args
    cmd = "#@file -Ilib;test \"C:/Projects/space name/jruby-1_0/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb\" \"test/functional/hello_controller_test.rb\""
    assert_equal [@file, "-Ilib;test",
      "C:/Projects/space name/jruby-1_0/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb",
      "test/functional/hello_controller_test.rb"],
      JRuby::PathHelper.smart_split_command(cmd)
  end
end