mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 15:30:18 +00:00
test/index: add more tests
This commit is contained in:
+70
-17
@@ -4,30 +4,39 @@ require 'framework.rb'
|
||||
require 'test/unit'
|
||||
require 'tmpdir'
|
||||
|
||||
|
||||
# Setup a temporary directory
|
||||
TMP_DIR = File.join(TEST_TMP_DIR, "index_test")
|
||||
|
||||
`rm -rf #{TMP_DIR}`
|
||||
FileUtils.mkdir_p(TMP_DIR)
|
||||
|
||||
def do_git(cmd)
|
||||
puts "Running: #{cmd}"
|
||||
`cd #{TMP_DIR} && #{cmd}`
|
||||
end
|
||||
|
||||
do_git('git init && touch a && touch b && git add a b && git commit -m"First Commit"')
|
||||
def setup_git_repository
|
||||
`rm -rf #{TMP_DIR}`
|
||||
FileUtils.mkdir_p(TMP_DIR)
|
||||
do_git('git init && touch a && touch b && git add a b && git commit -m"First Commit"')
|
||||
end
|
||||
|
||||
class IndexTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@finished = false
|
||||
path = NSURL.alloc.initFileURLWithPath(TMP_DIR)
|
||||
@repo = PBGitRepository.alloc.initWithURL(path)
|
||||
setup_git_repository
|
||||
|
||||
@path = NSURL.alloc.initFileURLWithPath(TMP_DIR)
|
||||
@repo = PBGitRepository.alloc.initWithURL(@path)
|
||||
assert(@repo, "Repository creation failed")
|
||||
@controller = PBGitIndex.alloc.initWithRepository(@repo, workingDirectory:path)
|
||||
@controller = PBGitIndex.alloc.initWithRepository(@repo, workingDirectory:@path)
|
||||
assert(@controller, "Controller creation failed")
|
||||
|
||||
# Setup escape from run loop
|
||||
NSNotificationCenter.defaultCenter.addObserver(self,
|
||||
selector:"stopRunLoop:",
|
||||
name:"PBGitIndexFinishedIndexRefresh",
|
||||
object:@controller);
|
||||
end
|
||||
|
||||
# Run the default run loop, for up to 2 seconds
|
||||
def run_loop
|
||||
@finished = false
|
||||
runloop = NSRunLoop.currentRunLoop
|
||||
@@ -41,8 +50,8 @@ class IndexTest < Test::Unit::TestCase
|
||||
return true
|
||||
end
|
||||
|
||||
def refreshFinished(notification)
|
||||
puts "Refresh finished!"
|
||||
# Callback method to stop run loop
|
||||
def stopRunLoop(notification)
|
||||
@finished = true
|
||||
end
|
||||
|
||||
@@ -51,17 +60,18 @@ class IndexTest < Test::Unit::TestCase
|
||||
assert(run_loop, "Refresh finishes in 2 seconds")
|
||||
end
|
||||
|
||||
def test_a
|
||||
NSNotificationCenter.defaultCenter.addObserver(self,
|
||||
selector:"refreshFinished:",
|
||||
name:"PBGitIndexFinishedIndexRefresh",
|
||||
object:@controller);
|
||||
|
||||
|
||||
|
||||
|
||||
def test_refresh
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.empty?, "No changes")
|
||||
|
||||
do_git('rm a')
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.count == 1, "One change")
|
||||
|
||||
do_git('touch a')
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.empty?, "No changes anymore")
|
||||
@@ -77,7 +87,9 @@ class IndexTest < Test::Unit::TestCase
|
||||
# 2 == DELETED, see PBChangedFile.h
|
||||
assert_equal(@controller.indexChanges[0].status, 2, "File status has changed")
|
||||
do_git('git checkout a')
|
||||
end
|
||||
|
||||
def test_refresh_new_file
|
||||
do_git('touch c')
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.count == 1)
|
||||
@@ -86,9 +98,50 @@ class IndexTest < Test::Unit::TestCase
|
||||
|
||||
do_git('git add c')
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.count == 1)
|
||||
assert_equal(1, @controller.indexChanges.count, "Just one file changed")
|
||||
assert_equal(file, @controller.indexChanges[0], "Still the same file")
|
||||
assert_equal(file.status, 0, "Still new")
|
||||
|
||||
do_git('git rm --cached c')
|
||||
wait_for_refresh
|
||||
assert_equal(1, @controller.indexChanges.count, "Shouldn't be tracked anymore, but still in other list")
|
||||
assert_equal(file, @controller.indexChanges[0], "Still the same file")
|
||||
assert_equal(file.status, 0, "Still new (but only local)")
|
||||
|
||||
# FIXME: The things below should actually be true / false, but macruby return 0 / 1
|
||||
assert(file.hasUnstagedChanges == 1, "Has unstaged changes")
|
||||
assert(@controller.indexChanges[0].hasStagedChanges == 0, "But no staged changes")
|
||||
|
||||
do_git('rm c')
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.empty?, "All files should be gone")
|
||||
|
||||
# Test an add -> git rm deletion
|
||||
do_git("touch d && git add d")
|
||||
wait_for_refresh
|
||||
assert_equal(1, @controller.indexChanges.count, "Just one changed file")
|
||||
|
||||
do_git("git rm -f d")
|
||||
wait_for_refresh
|
||||
assert(@controller.indexChanges.empty?, "Should be gone again")
|
||||
end
|
||||
|
||||
def test_remove_existing_file
|
||||
wait_for_refresh
|
||||
do_git("rm a")
|
||||
wait_for_refresh
|
||||
assert_equal(1, @controller.indexChanges.count, "Change was noticed")
|
||||
file = @controller.indexChanges[0]
|
||||
assert_equal(2, file.status, "File was DELETED")
|
||||
assert(file.hasUnstagedChanges == 1)
|
||||
assert(file.hasStagedChanges == 0)
|
||||
|
||||
do_git("git rm a")
|
||||
wait_for_refresh
|
||||
assert_equal(1, @controller.indexChanges.count, "File was removed")
|
||||
assert_equal(file, @controller.indexChanges[0], "Still the same")
|
||||
assert(file.hasUnstagedChanges == 0)
|
||||
assert(file.hasStagedChanges == 1)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user