| 1 |
require File.dirname(__FILE__) + '/helper' |
| 2 |
|
| 3 |
class TestGit < Test::Unit::TestCase |
| 4 |
def setup |
| 5 |
base = File.join(File.dirname(__FILE__), "..") |
| 6 |
@git = Git.new(base) |
| 7 |
@git_bin_base = "#{Git.git_binary} --git-dir='#{base}'" |
| 8 |
end |
| 9 |
|
| 10 |
def test_method_missing_calls_execute |
| 11 |
@git.expects(:execute).with("#{@git_bin_base} version ").returns("") |
| 12 |
@git.version |
| 13 |
end |
| 14 |
|
| 15 |
def test_execute |
| 16 |
assert_match(/^git version [\d\.]*$/, @git.execute("#{Git.git_binary} version")) |
| 17 |
end |
| 18 |
|
| 19 |
def test_it_escapes_single_quotes_with_shell_escape |
| 20 |
assert_equal "\\'foo", @git.shell_escape("'foo") |
| 21 |
assert_equal "\\'foo\\'", @git.e("'foo'") |
| 22 |
end |
| 23 |
|
| 24 |
def test_method_missing |
| 25 |
assert_match(/^git version [\w\.]*$/, @git.version) |
| 26 |
end |
| 27 |
|
| 28 |
def test_transform_options |
| 29 |
assert_equal ["-s"], @git.transform_options({:s => true}) |
| 30 |
assert_equal ["-s '5'"], @git.transform_options({:s => 5}) |
| 31 |
|
| 32 |
assert_equal ["--max-count"], @git.transform_options({:max_count => true}) |
| 33 |
assert_equal ["--max-count='5'"], @git.transform_options({:max_count => 5}) |
| 34 |
|
| 35 |
assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort |
| 36 |
end |
| 37 |
|
| 38 |
def test_transform_options_shell_escapes_arguments |
| 39 |
assert_equal ["--foo='bazz\\'er'"], @git.transform_options({:foo => "bazz'er"}) |
| 40 |
assert_equal ["-x 'bazz\\'er'"], @git.transform_options({:x => "bazz'er"}) |
| 41 |
end |
| 42 |
|
| 43 |
def test_it_really_shell_escapes_arguments_to_the_git_shell |
| 44 |
@git.expects(:execute).with("#{@git_bin_base} foo --bar='bazz\\'er'") |
| 45 |
@git.foo(:bar => "bazz'er") |
| 46 |
@git.expects(:execute).with("#{@git_bin_base} bar -x 'quu\\'x'") |
| 47 |
@git.bar(:x => "quu'x") |
| 48 |
end |
| 49 |
|
| 50 |
def test_it_shell_escapes_the_standalone_argument |
| 51 |
@git.expects(:execute).with("#{@git_bin_base} foo 'bar\\'s'") |
| 52 |
@git.foo({}, "bar's") |
| 53 |
end |
| 54 |
end |