Browse files

Merge pull request #237 from arthurschreiber/windows-fixes

Windows fixes
  • Loading branch information...
2 parents 831e42d + 524cc5a commit 098ddbc0bf440105007794aefbfe5f778e841bf6 @arthurschreiber arthurschreiber committed Jul 31, 2013
Showing with 123 additions and 45 deletions.
  1. +2 −0 .gitattributes
  2. +1 −1 Rakefile
  3. +25 −23 test/blob_test.rb
  4. +22 −6 test/index_test.rb
  5. +9 −1 test/remote_test.rb
  6. +62 −14 test/repo_test.rb
  7. +2 −0 test/test_helper.rb
View
2 .gitattributes
@@ -0,0 +1,2 @@
+test/fixtures/*.git/packed-refs text eol=lf
+test/fixtures/*.git/logs/**/* text eol=lf
View
2 Rakefile
@@ -43,7 +43,7 @@ task :cover do
end
Rake::TestTask.new do |t|
- t.libs << 'lib:test'
+ t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
t.warning = true
View
48 test/blob_test.rb
@@ -78,7 +78,7 @@ def test_blob_text_with_negative_lines
def test_blob_text_default_encoding
oid = "7771329dfa3002caf8c61a0ceb62a31d09023f37"
blob = @repo.lookup(oid)
- assert_equal Encoding::UTF_8, blob.text.encoding
+ assert_equal Encoding.default_external, blob.text.encoding
end
def test_blob_text_set_encoding
@@ -137,14 +137,22 @@ def test_blob_is_binary
end
class BlobDiffTest < Rugged::SandboxedTestCase
- def test_diff_blob
- repo = sandbox_init("diff")
+ def setup
+ super
+ @repo = sandbox_init("diff")
+ end
+
+ def teardown
+ @repo.close
+ super
+ end
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ def test_diff_blob
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid])
patch = blob.diff(other)
@@ -184,13 +192,11 @@ def test_diff_blob
end
def test_diff_string
- repo = sandbox_init("diff")
-
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid]).content
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid]).content
patch = blob.diff(other)
@@ -230,11 +236,9 @@ def test_diff_string
end
def test_diff_nil
- repo = sandbox_init("diff")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
-
- blob = repo.lookup(a.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
patch = blob.diff(nil)
@@ -261,13 +265,11 @@ def test_diff_nil
end
def test_diff_with_paths
- repo = sandbox_init("diff")
-
- a = repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
- b = repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
+ a = @repo.lookup("d70d245ed97ed2aa596dd1af6536e4bfdb047b69")
+ b = @repo.lookup("7a9e0b02e63179929fed24f0a3e0f19168114d10")
- blob = repo.lookup(a.tree["readme.txt"][:oid])
- other = repo.lookup(b.tree["readme.txt"][:oid])
+ blob = @repo.lookup(a.tree["readme.txt"][:oid])
+ other = @repo.lookup(b.tree["readme.txt"][:oid])
patch = blob.diff(other, :old_path => "old_readme.txt", :new_path => "new_readme.txt")
assert_equal "old_readme.txt", patch.delta.old_file[:path]
View
28 test/index_test.rb
@@ -118,13 +118,16 @@ def test_add_new_entries
class IndexWriteTest < Rugged::TestCase
def setup
path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
- @tmppath = Tempfile.new('index').path
- FileUtils.copy(path, @tmppath)
- @index = Rugged::Index.new(@tmppath)
+
+ @tmpfile = Tempfile.new('index', Dir.tmpdir, encoding: "binary")
+ @tmpfile.write(File.binread(path))
+ @tmpfile.close
+
+ @index = Rugged::Index.new(@tmpfile.path)
end
def teardown
- File.delete(@tmppath)
+ @tmpfile.unlink
end
def test_raises_when_writing_invalid_entries
@@ -142,7 +145,7 @@ def test_can_write_index
@index.write
- index2 = Rugged::Index.new(@tmppath)
+ index2 = Rugged::Index.new(@tmpfile.path)
itr_test = index2.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
assert_equal "README:else.txt:new_path:new.txt", itr_test
@@ -157,7 +160,8 @@ def setup
@index = @repo.index
end
- def teardown
+ def teardown
+ @repo.close
FileUtils.remove_entry_secure(@tmppath)
end
@@ -202,6 +206,12 @@ def setup
@repo = sandbox_init("mergedrepo")
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_conflicts
assert @repo.index.conflicts?
end
@@ -251,6 +261,12 @@ def setup
end
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_add_all_lifecycle
Dir.chdir(@repo.workdir) do
@repo.index.add_all("file.*")
View
10 test/remote_test.rb
@@ -164,6 +164,13 @@ def setup
@remote = Rugged::Remote.lookup(@repo, 'origin')
end
+ def teardown
+ @repo.close
+ @remote_repo.close
+
+ super
+ end
+
def test_push_single_ref
result = @remote.push(["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
assert_equal({}, result)
@@ -255,10 +262,11 @@ def setup
@path = Dir.mktmpdir 'dir'
@repo = Rugged::Repository.init_at(@path, false)
repo_dir = File.join(TEST_DIR, (File.join('fixtures', 'testrepo.git', '.')))
- @remote = Rugged::Remote.add(@repo, 'origin', "file://#{repo_dir}")
+ @remote = Rugged::Remote.add(@repo, 'origin', repo_dir)
end
def teardown
+ @repo.close
FileUtils.remove_entry_secure(@path)
end
View
76 test/repo_test.rb
@@ -8,6 +8,12 @@ def setup
@repo = sandbox_init "testrepo.git"
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_last_commit
assert @repo.respond_to? :last_commit
assert "36060c58702ed4c2a40832c51758d5344201d89a", @repo.last_commit.oid
@@ -19,7 +25,7 @@ def test_fails_to_open_unexisting_repos
end
assert_raises Rugged::RepositoryError do
- Rugged::Repository.new("/home/")
+ Rugged::Repository.new("test")
end
end
@@ -149,8 +155,12 @@ def test_enumerate_all_objects
def test_loading_alternates
alt_path = File.dirname(__FILE__) + '/fixtures/alternate/objects'
repo = Rugged::Repository.new(@repo.path, :alternates => [alt_path])
- assert_equal 40, repo.each_id.to_a.length
- assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
+ begin
+ assert_equal 40, repo.each_id.to_a.length
+ assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
+ ensure
+ repo.close
+ end
end
def test_alternates_with_invalid_path_type
@@ -243,22 +253,38 @@ def teardown
def test_init_bare_false
repo = Rugged::Repository.init_at(@tmppath, false)
- refute repo.bare?
+ begin
+ refute repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_bare_true
repo = Rugged::Repository.init_at(@tmppath, true)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_bare_truthy
repo = Rugged::Repository.init_at(@tmppath, :bare)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_init_non_bare_default
repo = Rugged::Repository.init_at(@tmppath)
- refute repo.bare?
+ begin
+ refute repo.bare?
+ ensure
+ repo.close
+ end
end
end
@@ -274,23 +300,32 @@ def teardown
def test_clone
repo = Rugged::Repository.clone_at(@source_path, @tmppath)
- assert_equal "hey", File.read(File.join(@tmppath, "README")).chomp
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.head.target
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/heads/master").target
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target
- assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target
+ begin
+ assert_equal "hey", File.read(File.join(@tmppath, "README")).chomp
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.head.target
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/heads/master").target
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", repo.ref("refs/remotes/origin/master").target
+ assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", repo.ref("refs/remotes/origin/packed").target
+ ensure
+ repo.close
+ end
end
def test_clone_bare
repo = Rugged::Repository.clone_at(@source_path, @tmppath, :bare => true)
- assert repo.bare?
+ begin
+ assert repo.bare?
+ ensure
+ repo.close
+ end
end
def test_clone_with_progress
total_objects = indexed_objects = received_objects = received_bytes = nil
callsback = 0
- Rugged::Repository.clone_at(@source_path, @tmppath,
+ repo = Rugged::Repository.clone_at(@source_path, @tmppath,
:progress => lambda { |*args| callsback += 1 ; total_objects, indexed_objects, received_objects, received_bytes = args })
+ repo.close
assert_equal 22, callsback
assert_equal 19, total_objects
assert_equal 19, indexed_objects
@@ -326,6 +361,12 @@ def setup
@repo = sandbox_init("testrepo.git")
end
+ def teardown
+ @repo.close
+
+ super
+ end
+
def test_no_namespace
assert_nil @repo.namespace
end
@@ -363,6 +404,13 @@ def setup
"8496071c1b46c854b31185ea97743be6a8774479")
end
+ def teardown
+ @repo.close
+ @remote_repo.close
+
+ super
+ end
+
def test_push_single_ref
result = @repo.push("origin", ["refs/heads/master", "refs/heads/master:refs/heads/foobar", "refs/heads/unit_test"])
assert_equal({}, result)
View
2 test/test_helper.rb
@@ -74,6 +74,8 @@ def setup
end
def teardown
+ @repo.close
+ GC.start
destroy_temp_repo(@path)
end

0 comments on commit 098ddbc

Please sign in to comment.