705378546da2

Add tests for {update}.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 30 Nov 2009 20:18:53 -0500
parents a85dc0c43f86
children f6008f722974
branches/tags (none)
files tests/test_update.py tests/util.py

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_update.py	Mon Nov 30 20:18:53 2009 -0500
@@ -0,0 +1,132 @@
+'''Test output of {update}.'''
+
+from nose import *
+from util import *
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_empty_repo():
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    output = prompt(fs='{ need to update? {update}}')
+    assert output == ''
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_single_branch():
+    hg_commit()
+    
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    output = prompt(fs='{ need to update? {update}}')
+    assert output == ''
+    
+    hg_commit()
+    
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    output = prompt(fs='{ need to update? {update}}')
+    assert output == ''
+    
+    hg_update(0)
+    
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    output = prompt(fs='{ need to update? {update}}')
+    assert output == ' need to update? ^'
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_multiple_branches():
+    hg_commit()
+    hg_commit()
+    hg_commit()
+    
+    hg_update(0)
+    hg_commit('two.txt')
+    hg_commit('two.txt')
+    
+    #  @    4
+    #  |
+    #  o    3 
+    #  |
+    #  | o  2
+    #  | |
+    #  | o  1
+    #  |/
+    #  |
+    #  o    0
+    
+    hg_log()
+    
+    hg_update(4)
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    hg_update(3)
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    # This test case matches the behavior of Mercurial, but it seems a bit
+    # unintuitive to me.
+    hg_update(2)
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    hg_update(1)
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    hg_update(0)
+    output = prompt(fs='{update}')
+    assert output == '^'
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_multiple_named_branches():
+    hg_commit()
+    hg_commit()
+    hg_commit()
+    
+    hg_update(0)
+    hg_branch('test')
+    hg_commit('two.txt')
+    hg_commit('two.txt')
+    
+    #  @    4 (test)
+    #  |
+    #  o    3 (test)
+    #  |
+    #  | o  2 (default)
+    #  | |
+    #  | o  1 (default)
+    #  |/
+    #  |
+    #  o    0 (default)
+    
+    hg_log()
+    
+    hg_update(4)
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    hg_update(3)
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    hg_update(2)
+    output = prompt(fs='{update}')
+    assert output == ''
+    
+    hg_update(1)
+    output = prompt(fs='{update}')
+    assert output == '^'
+    
+    hg_update(0)
+    output = prompt(fs='{update}')
+    assert output == '^'
+
--- a/tests/util.py	Mon Nov 30 19:44:52 2009 -0500
+++ b/tests/util.py	Mon Nov 30 20:18:53 2009 -0500
@@ -42,7 +42,7 @@
     commands.branch(_ui, get_sandbox_repo(), branch)
 
 def hg_update(rev):
-    opts = { 'rev': str(rev) }
+    opts = { 'rev': str(rev), }
     commands.update(_ui, get_sandbox_repo(), **opts)
 
 def hg_merge(rev):
@@ -56,3 +56,13 @@
     opts = { 'addremove': True, 'date': None, 'user': 'Prompt Tester',
              'logfile': None, 'message': "Sandbox commit." }
     commands.commit(get_sandbox_ui(), get_sandbox_repo(), **opts)
+
+def hg_log():
+    opts = { 'template': '{rev} {desc}\n', 'rev': None, 'date': None, 'user': None }
+    
+    _ui.pushbuffer()
+    commands.log(_ui, get_sandbox_repo(), **opts)
+    output = _ui.popbuffer()
+    
+    return output
+