mercurial/HGTests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 27 Nov 2012 18:02:09 +0000
changeset 103 04731ef44417
parent 93 2579830f6b61
child 105 25e8ff9d2a31
permissions -rw-r--r--
HGNodeId renamed to HGChangesetId

"{ Package: 'stx:libscm/mercurial' }"

HGTestCase subclass:#HGTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-Tests'
!

!HGTests class methodsFor:'documentation'!

documentation
"
    Tests for core Mercurial code - no Smalltalk/X specific code.
    Commiting, cloning, walking history and so on...

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!HGTests methodsFor:'tests - basic workflow'!

test_basic_01a
    "Test modification of working copy and commit back"
    
    | repo  wc  f1_txt  oldcs  currentcs |

    repo := self repositoryNamed:'test_repo_01'.
     "
     UserPreferences fileBrowserClass openOn: repo directory.
    "
    wc := repo workingCopy.
    oldcs := wc changeset.
    self assert:oldcs id revno == 4.
     "Modify some file"
    f1_txt := wc / 'f1.txt'.
    self assert:f1_txt isModified not.
    f1_txt writingFileDo:[:s | s nextPutAll:'modified from test_01a'. ].
    self assert:f1_txt isModified.
    wc commit:'test_01a commit 1'.
    currentcs := wc changeset.
    self assert:f1_txt isModified not.
    self assert:currentcs id revno == 5.
    self assert:currentcs parent1 = oldcs.
    self assert:currentcs author = 'test_basic_01a <test_basic_01a@HGTests>'

    "Created: / 19-09-2012 / 23:06:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 22-11-2012 / 11:42:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGTests methodsFor:'tests - changesets'!

test_changeset_01
    "
    Test accessing changesets
    "

    | repo cs |

    repo := self repositoryNamed:'test_repo_01'.

    cs := repo @ 4.
    self assert: cs id printString = '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.

    cs := repo @ '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.
    self assert: cs id printString = '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.

    cs := repo @ '4:6f88e1f44d9e'.
    self assert: cs id printString = '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.

    "Created: / 16-11-2012 / 21:03:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 16-11-2012 / 22:10:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_changeset_02
    "
    Tests identity if changesets (cacheing)
    "    

    | repo cs1 cs2 |

    repo := self repositoryNamed:'test_repo_01'.

    cs1 := repo @ 4.
    cs2 := repo @ 4.
    self assert: cs1 == cs2.

    cs2 := repo @ '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.
    self assert: cs1 == cs2.

    cs2 := repo @ '4:6f88e1f44d9e'.
    self assert: cs1 == cs2.

    "Created: / 16-11-2012 / 22:10:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_changeset_03
    "
    Test walking history though parents
    "

    | repo cs0 cs1 cs2 cs3 |

    repo := self repositoryNamed:'test_repo_01'.

    cs0 := repo @ 0.
    cs1 := repo @ 1.
    cs2 := repo @ 2.
    cs3 := repo @ 3.

    self assert: cs3 parent1 == cs2.
    self assert: cs3 parent2 isNil.
    self assert: cs2 parent1 == cs1.
    self assert: cs2 parent2 isNil.
    self assert: cs1 parent1 == cs0.
    self assert: cs1 parent2 isNil.
    self assert: cs0 parent1 isNil.
    self assert: cs0 parent2 isNil.

    "Created: / 16-11-2012 / 22:14:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_changeset_04
    "
    Test access to changeset contents
    "

    | repo cs |

    repo := self repositoryNamed:'test_repo_01'.

    cs := repo @ 1.

    self assert: cs root children size == 2.
    self assert: (cs root / 'b') children size == 2.
    self assert: (cs root / 'b') parent == cs root.
    self assert: (cs root / 'f1.txt') children size == 0.

    self should: [cs root / 'abraka'] raise: HGError.
    self should: [cs root / 'c' / 'abraka'] raise: HGError.

    "Created: / 16-11-2012 / 22:38:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2012 / 00:23:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_changeset_05
    "
    Test access to changeset contents
    "

    | repo |

    repo := self repositoryNamed:'test_repo_01'.

    self assert: (repo @ 0 / 'f1.txt') contents asString = 'f1-C0
'.

    self assert: (repo @ 1 / 'f1.txt') contents asString = 'f1-C0
f1-C1
'

    "Created: / 17-11-2012 / 00:19:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGTests methodsFor:'tests - node id'!

test_nodeid_01
    "
    Tests parsing node id
    "

    | id |

    id := HGChangesetId fromString:'4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.
    self assert: id revno = 4.
    self assert: id asByteArray = #[111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199].

    id := HGChangesetId fromString:'4:6f88e1f44d9e'.
    self assert: id revno = 4.
    self assert: id asByteArray = #[111 136 225 244 77 158].


    ^self. "/following is not yet suppoted"

    "/Only revno
    id := HGChangesetId fromString:'1234'.
    self assert: id revno = 1234.
    self assert: id asByteArray = #[].

    "/Only hash
    id := HGChangesetId fromString:'6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7'.
    self assert: id revno = -2. "/meaning - unknown.
    self assert: id asByteArray = #[111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199].

    "/Only short hash
    id := HGChangesetId fromString:'6f88e1f44d9e'.
    self assert: id revno = -2. "/meaning - unknown.
    self assert: id asByteArray = #[111 136 225 244 77 158]

    "Created: / 16-11-2012 / 21:27:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2012 / 10:59:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_nodeid_02
    "
    Tests conversions
    "

    | id |

    id := '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7' asHGChangesetId.
    self assert: id revno = 4.
    self assert: id asByteArray = #[111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199].

    id := 1234 asHGChangesetId.
    self assert: id revno = 1234.
    self assert: id asByteArray = #[].

    id := #[ 111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199 ] 
    asHGChangesetId.
    self assert: id revno = -2.
    self assert: id asByteArray = #[111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199].

    "Created: / 16-11-2012 / 21:32:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-11-2012 / 17:50:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_nodeid_03
    "
    Tests comparison
    "

    | id1 id2 |

    id1 := HGChangesetId new revno: 4.
    id2 := HGChangesetId new revno: 4.

    self assert: id1 = id2.



    "/ #[111 136 225 244 77 158 184 110 11 86 202 21 227 14 93 120 106 205 131 199].

    "Created: / 16-11-2012 / 21:41:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGTests class methodsFor:'documentation'!

version_HG
    "Never, ever change this method. Ask JV or CG why"
    ^thisContext method mclass theNonMetaclass instVarNamed: #revision
!

version_SVN
    ^ '§Id::                                                                                                                        §'
! !