summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-10 12:43:33 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-10 12:43:33 -0800
commitfde3263abc5c7866aa7dce7aef28eacaa33d7664 (patch)
treec9911ac92e9770c7bfea3e79269f8e7dcf7f6982 /tests
parent9d59d2965184964ab6662282ef5f9ceac2c58552 (diff)
downloadthird_party-ruby-git-fde3263abc5c7866aa7dce7aef28eacaa33d7664.zip
third_party-ruby-git-fde3263abc5c7866aa7dce7aef28eacaa33d7664.tar.gz
third_party-ruby-git-fde3263abc5c7866aa7dce7aef28eacaa33d7664.tar.xz
few hours work - diff is done
Diffstat (limited to 'tests')
m---------tests/files/working0
-rw-r--r--tests/test_helper.rb4
-rw-r--r--tests/units/test_config.rb26
-rw-r--r--tests/units/test_diff.rb67
-rw-r--r--tests/units/test_init.rb31
5 files changed, 121 insertions, 7 deletions
diff --git a/tests/files/working b/tests/files/working
-Subproject 935badc874edd62a8629aaf103418092c73f0a5
+Subproject 5e53019b3238362144c2766f02a2c00d91fcc02
diff --git a/tests/test_helper.rb b/tests/test_helper.rb
index fe8c34d..03b5f8a 100644
--- a/tests/test_helper.rb
+++ b/tests/test_helper.rb
@@ -19,14 +19,14 @@ class Test::Unit::TestCase
@index = File.join(@test_dir, 'index')
end
- def in_temp_dir
+ def in_temp_dir(remove_after = true)
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s
tmp_path = File.join("/tmp/", filename)
FileUtils.mkdir(tmp_path)
Dir.chdir tmp_path do
yield tmp_path
end
- FileUtils.rm_r(tmp_path)
+ FileUtils.rm_r(tmp_path) if remove_after
end
end \ No newline at end of file
diff --git a/tests/units/test_config.rb b/tests/units/test_config.rb
new file mode 100644
index 0000000..5adb391
--- /dev/null
+++ b/tests/units/test_config.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TestBranch < Test::Unit::TestCase
+ def setup
+ set_file_paths
+ @git = Git.open(@wdir)
+ end
+
+ def test_config
+ c = @git.config
+ assert_equal('scott Chacon', c['user.name'])
+ assert_equal('false', c['core.bare'])
+ end
+
+ def test_read_config
+ assert_equal('scott Chacon', @git.config('user.name'))
+ assert_equal('false', @git.config('core.bare'))
+ end
+
+ def test_set_config
+ # !! TODO !!
+ end
+
+end \ No newline at end of file
diff --git a/tests/units/test_diff.rb b/tests/units/test_diff.rb
index b8ed6b8..b989c8a 100644
--- a/tests/units/test_diff.rb
+++ b/tests/units/test_diff.rb
@@ -6,24 +6,81 @@ class TestDiff < Test::Unit::TestCase
def setup
set_file_paths
@git = Git.open(@wdir)
+ @diff = @git.diff('gitsearch1', 'v2.5')
end
- def test_diff
+ #def test_diff
+ # g.diff
+ # assert(1, d.size)
+ #end
+
+ def test_diff_tags
+ d = @git.diff('gitsearch1', 'v2.5')
+ assert_equal(3, d.size)
+ assert_equal(74, d.lines)
+ assert_equal(10, d.deletions)
+ assert_equal(64, d.insertions)
+ end
+
+ def test_diff_path
+ d = @git.diff('gitsearch1', 'v2.5').path('scott/')
+ assert_equal(2, d.size)
+ assert_equal(9, d.lines)
+ assert_equal(9, d.deletions)
+ assert_equal(0, d.insertions)
end
- def test_diff_summary
+ def test_diff_objects
+ d = @git.diff('gitsearch1', @git.tree('v2.5'))
+ assert(3, d.size)
end
- def test_diff_stat
+ def test_object_diff
+ d = @git.tree('v2.5').diff('gitsearch1')
+ assert_equal(3, d.size)
+ assert_equal(74, d.lines)
+ assert_equal(10, d.insertions)
+ assert_equal(64, d.deletions)
+
+ d = @git.tree('v2.6').diff(@git.tree('gitsearch1'))
+ assert_equal(2, d.size)
+ assert_equal(9, d.lines)
end
- def test_diff_shortstat
+ def test_diff_stats
+ s = @diff.stats
+ assert_equal(3, s[:total][:files])
+ assert_equal(74, s[:total][:lines])
+ assert_equal(10, s[:total][:deletions])
+ assert_equal(64, s[:total][:insertions])
+
+ # per file
+ assert_equal(1, s[:files]["scott/newfile"][:deletions])
+ end
+
+ def test_diff_hashkey
+ assert_equal('5d46068', @diff["scott/newfile"].src)
+ assert_nil(@diff["scott/newfile"].blob(:dst))
+ assert(@diff["scott/newfile"].blob(:src).is_a?(Git::Object::Blob))
end
def test_patch
+ p = @git.diff('v2.8^', 'v2.8').patch
+ diff = "diff --git a/example.txt b/example.txt\nindex 1f09f2e..8dc79ae 100644\n--- a/example.txt\n+++ b/example.txt\n@@ -1 +1 @@\n-replace with new text\n+replace with new text - diff test"
+ assert_equal(diff, p)
end
- def test_unified
+ def test_diff_each
+ files = {}
+ @diff.each do |d|
+ files[d.path] = d
+ end
+
+ assert(files['example.txt'])
+ assert_equal('100644', files['scott/newfile'].mode)
+ assert_equal('deleted', files['scott/newfile'].type)
+ assert_equal(160, files['scott/newfile'].patch.size)
end
+
end \ No newline at end of file
diff --git a/tests/units/test_init.rb b/tests/units/test_init.rb
index 56d2a18..f1a8ba4 100644
--- a/tests/units/test_init.rb
+++ b/tests/units/test_init.rb
@@ -24,6 +24,37 @@ class TestInit < Test::Unit::TestCase
g = Git.repo @wbare
assert_equal(g.repo.path, @wbare)
end
+
+ #g = Git.init
+ # Git.init('project')
+ # Git.init('/home/schacon/proj',
+ # { :git_dir => '/opt/git/proj.git',
+ # :index_file => '/tmp/index'} )
+ def test_git_init
+ in_temp_dir do |path|
+ Git.init
+ assert(File.directory?(File.join(path, '.git')))
+ assert(File.exists?(File.join(path, '.git', 'config')))
+ end
+ end
+
+ def test_git_init_remote_git
+ in_temp_dir do |dir|
+ assert(!File.exists?(File.join(dir, 'config')))
+
+ in_temp_dir do |path|
+ Git.init(path, :repository => dir)
+ assert(File.exists?(File.join(dir, 'config')))
+ end
+ end
+ end
+
+ def test_git_clone
+ in_temp_dir do |path|
+ Git.clone(uri, :repository => dir)
+ assert(File.exists?(File.join(dir, 'config')))
+ end
+ end
# trying to open a git project using a bare repo - rather than using Git.repo
def test_git_open_error