mercurial/HGCommandParserTests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 22 Mar 2013 09:09:49 +0000
changeset 276 8fcaf8f2e51b
parent 230 d202597d67a5
child 302 e078bdcef149
permissions -rw-r--r--
Bugfix: merge command output parsing.

"
 COPYRIGHT (c) 2012-2013 by Jan Vrany
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libscm/mercurial' }"

TestCase subclass:#HGCommandParserTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-Tests'
!

!HGCommandParserTests class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2012-2013 by Jan Vrany
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
! !

!HGCommandParserTests methodsFor:'tests - commands'!

test_cmd_branches_01

    | branches |

    branches := (HGCommandParser on: 'default                        5:f22945219f9be25a1fe436d81afece07b89330be
branch1                        4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a (inactive)
branch2                        3:32d32dee719fb422a69cfa6f7f8c1d8e299de2df (closed)
') parseCommandBranches.

    self assert: branches size == 3.

    self assert: branches first name = 'default'.
    self assert: branches first isActive.
    self assert: branches first isClosed not.

    self assert: branches second name = 'branch1'.
    self assert: branches second isActive not.
    self assert: branches second isClosed not.

    self assert: branches third name = 'branch2'.
    self assert: branches third isActive.
    self assert: branches third isClosed.

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

test_cmd_err_branches_01

    (HGCommandParser on: 'invalidating branch cache (tip differs)
') parseErrorBranches.

    "Created: / 06-02-2013 / 19:19:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_heads_01

    | heads |

    heads := (HGCommandParser on: '6:4e0568ffbf1a53f2d8980ba9844d2af6f0bac455
5:f22945219f9be25a1fe436d81afece07b89330be
4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a
') parseCommandHeads.

    self assert: heads size == 3.

    self assert: heads first  asString = '6:4e0568ffbf1a'.
    self assert: heads second asString = '5:f22945219f9b'.
    self assert: heads third  asString = '4:5bd21fb5eea8'.

    "Created: / 27-11-2012 / 21:22:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-11-2012 / 23:43:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_log_children_01

    | children |

    children := (HGCommandParser on: '1:4e0568ffbfaa
6:4e0568ffbf1a 5:f22945219f9b 4:5bd21fb5eea8
') 
                parseCommandLogChildren.

    self assert: children first second size == 3.

    self assert: children first second first  asString = '6:4e0568ffbf1a'.
    self assert: children first second second asString = '5:f22945219f9b'.
    self assert: children first second third  asString = '4:5bd21fb5eea8'.

    "Created: / 05-12-2012 / 23:35:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_log_file_01

    | heads |

    heads := (HGCommandParser on: '6:4e0568ffbf1a53f2d8980ba9844d2af6f0bac455
5:f22945219f9be25a1fe436d81afece07b89330be
4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a
') parseCommandLogFile.

    self assert: heads size == 3.

    self assert: heads first  asString = '6:4e0568ffbf1a'.
    self assert: heads second asString = '5:f22945219f9b'.
    self assert: heads third  asString = '4:5bd21fb5eea8'.

    "Created: / 05-12-2012 / 19:16:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_merge_01

    | nergeinfo |

    nergeinfo := (HGCommandParser on: 'merging Make.proto
merging Make.spec
merging MockHGP3Foo.st
merging abbrev.stc
merging bc.mak
merging libInit.cc
merging mocks_hg_p3.st
merging p3.rc
2 files updated, 3 files merged, 0 files removed, 5 files unresolved
use ''hg resolve'' to retry unresolved file merges or ''hg update -C .'' to abandon
') parseCommandMerge.

    self assert: nergeinfo numUpdated = 2.
    self assert: nergeinfo numMerged = 3.
    self assert: nergeinfo numRemoved = 0.
    self assert: nergeinfo numUnresolved = 5.

    "Created: / 14-01-2013 / 15:58:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_merge_02

    | nergeinfo |

    nergeinfo := (HGCommandParser on: 'remote changed CharacterEncoderImplementations__SJIS.st which local deleted
use (c)hanged version or leave (d)eleted? c
merging AbortAllOperationRequest.st
merging AbortAllOperationWantedQuery.st
merging AbstractClassInstantiationError.st
merging Make.proto
merging Make.spec
merging MockHGP3Foo.st
merging abbrev.stc
merging bc.mak
merging libInit.cc
merging mocks_hg_p3.st
merging p3.rc
2 files updated, 3 files merged, 0 files removed, 5 files unresolved
use ''hg resolve'' to retry unresolved file merges or ''hg update -C .'' to abandon
') parseCommandMerge.

    self assert: nergeinfo numUpdated = 2.
    self assert: nergeinfo numMerged = 3.
    self assert: nergeinfo numRemoved = 0.
    self assert: nergeinfo numUnresolved = 5.

    "Created: / 15-01-2013 / 09:28:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_merge_03

    | nergeinfo |

    nergeinfo := (HGCommandParser on:' local changed lcmake.bat which remote deleted
use (c)hanged version or (d)elete? c
merging ApplicationDefinition.st
merging Bag.st
merging CharacterEncoder.st
merging Class.st
merging Collection.st
merging Dictionary.st
merging Float.st
merging LibraryDefinition.st
merging LongFloat.st
merging Make.proto
merging Make.spec
merging Makefile
merging OrderedCollection.st
merging PeekableStream.st
merging ProjectDefinition.st
merging SequenceableCollection.st
merging Set.st
merging ShortFloat.st
merging Smalltalk.st
merging UnixOperatingSystem.st
merging UserPreferences.st
merging WeakIdentitySet.st
merging abbrev.stc
merging bc.mak
merging libInit.cc
merging libbasic.rc
merging mingwmake.bat
merging stx_libbasic.st
merging vcmake.bat
0 files updated, 22 files merged, 0 files removed, 7 files unresolved
use ''hg resolve'' to retry unresolved file merges or ''hg update -C .'' to abandon
'
) parseCommandMerge.

    self assert: nergeinfo numUpdated = 0.
    self assert: nergeinfo numMerged = 22.
    self assert: nergeinfo numRemoved = 0.
    self assert: nergeinfo numUnresolved = 7.

    "Created: / 22-03-2013 / 08:55:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_pull_01

    | info |

    info := (HGCommandParser on: 'pulling from /home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/stx/libjava
searching for changes
no changes found
') parseCommandPull.

    self assert: info numChangesets = 0.
    self assert: info numChanges = 0.
    self assert: info numFiles = 0.
    self assert: info numHeads = 0.

    "Created: / 14-02-2013 / 15:25:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_push_01

    | info |

    info := (HGCommandParser on: 'pushing to /home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/stx/libjava
searching for changes
no changes found
') parseCommandPush.

    self assert: info numChangesets = 0.
    self assert: info numChanges = 0.
    self assert: info numFiles = 0.
    self assert: info numHeads = 0.

    "Created: / 06-02-2013 / 18:44:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_push_01b

    | info |

    info := (HGCommandParser on: 'pushing to /home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/stx/libjava
no changes found
') parseCommandPush.

    self assert: info numChangesets = 0.
    self assert: info numChanges = 0.
    self assert: info numFiles = 0.
    self assert: info numHeads = 0.

    "Created: / 12-02-2013 / 23:48:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_push_02

    | info |

    info := (HGCommandParser on: 'pushing to /home/jv/Private/Projects/SmalltalkX/sources/branches/jv1/build/stx/libscm
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 3 changes to 3 files
'
) parseCommandPush.

    self assert: info numChangesets = 1.
    self assert: info numChanges = 3.
    self assert: info numFiles = 3.
    self assert: info numHeads = 0.

    "Created: / 06-02-2013 / 18:56:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_showconfig_01

    | section |

    section := (HGCommandParser on: 'foo.bar=qux
') parseCommandShowConfig.

    self assert: ((section get: 'foo') get: 'bar') = 'qux'

    "Created: / 06-12-2012 / 15:59:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-12-2012 / 19:39:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_showconfig_02

    | section |

    section := (HGCommandParser on: 'foo.bar=qux
foo.baz=qoor
') parseCommandShowConfig.

    self assert: ((section get: 'foo') get: 'bar') = 'qux'.
    self assert: ((section get: 'foo') get: 'baz') = 'qoor'.

    self should:[(section get: 'foo') get: 'zork'] raise: Error.
    self should:[(section get: 'zork') get: 'zork'] raise: Error.

    "Created: / 06-12-2012 / 16:18:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 06-12-2012 / 20:07:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_showconfig_03

    | section |

    section := (HGCommandParser on: 'foo.bar=qux
foo.baz=qoor
') parseCommandShowConfig.

    self assert: ((section get: 'foo') get: 'bar' default: 'urg') = 'qux'.
    self assert: ((section get: 'foo') get: 'zork' default: 'qoor') = 'qoor'.

    "Created: / 06-12-2012 / 20:19:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_showconfig_04

    | section |

    section := (HGCommandParser on: 'foo.bar=qux
') parseCommandShowConfig.

    self assert: (section get: #('foo' 'bar')) = 'qux'.
    self assert: (section get: #('foo' 'baz') default:'quark') = 'quark'.
    self assert: (section get: #('zork' 'baz') default:'quark') = 'quark'.

    "Created: / 06-12-2012 / 21:50:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_01

    | statuses |

    statuses := (HGCommandParser on: 'M HGRevisionInfo.st
? something.txt
') parseCommandStatus.

    self assert: statuses size == 2.
    self assert: statuses first first isModified.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    self assert: statuses second first isUntracked.
    self assert: statuses second second = 'something.txt'.

    "Created: / 21-11-2012 / 00:53:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_02

    | statuses |

    statuses := (HGCommandParser on: 'A HGRevisionInfo.st
  HGVersionInfo.st
') parseCommandStatus.

    self assert: statuses size == 1.
    self assert: statuses first first isCopied.
    self assert: statuses first first source = 'HGVersionInfo.st'.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    "Created: / 21-11-2012 / 01:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_03

    | statuses |

    statuses := (HGCommandParser on: 'A HGRevisionInfo.st
  HGVersionInfo.st
? something.txt
') parseCommandStatus.

    self assert: statuses size == 2.
    self assert: statuses first first isCopied.
    self assert: statuses first first source = 'HGVersionInfo.st'.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    self assert: statuses second first isUntracked.
    self assert: statuses second second = 'something.txt'.

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

test_cmd_update_01

    | nergeinfo |

    nergeinfo := (HGCommandParser on: '9 files updated, 0 files merged, 1 files removed, 0 files unresolved
') parseCommandUpdate.

    self assert: nergeinfo numUpdated = 9.
    self assert: nergeinfo numMerged = 0.
    self assert: nergeinfo numRemoved = 1.
    self assert: nergeinfo numUnresolved = 0.

    "Created: / 14-01-2013 / 15:46:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommandParserTests methodsFor:'tests - misc'!

test_misc_01

    | id |

    id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7') parseNodeId.
    self assert: ( id revno == 4 ).
    self assert: ( id hexPrintString = '6F88E1F44D9EB86E0B56CA15E30E5D786ACD83C7' ).

    id := (HGCommandParser on: '4:6f88e1f44d9e') parseNodeId.
    self assert: ( id revno == 4 ).
    self assert: ( id hexPrintString = '6F88E1F44D9E' ).

    id := (HGCommandParser on: '-1:0000000000000000000000000000000000000000') parseNodeId.
    self assert: id == HGChangesetId null.

    id := (HGCommandParser on: '-1:000000000000') parseNodeId.
    self assert: id == HGChangesetId null.


    "/ Too short id
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83') parseNodeId.]
        raise: Error.
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9') parseNodeId.]
        raise: Error.


    "/ Invalid char
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd8X') parseNodeId.]
        raise: Error.

        self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9X') parseNodeId.]
        raise: Error.

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

test_misc_03a

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 





Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
') parseLogEntry.

    self assert: rev id revno = 4.
    self assert: rev author = 'Jan Vrany <jan.vrany@fit.cvut.cz>'.
    self assert: rev timestamp hour = 13.
    self assert: rev message = 'Commit 4'.

    "Created: / 05-12-2012 / 17:37:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-12-2012 / 23:33:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_03b

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 





Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
Two lones
**EOE**
') parseLogEntry.

    self assert: rev message = 'Commit 4
Two lones'.

    "Created: / 21-11-2012 / 18:09:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-12-2012 / 23:33:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_03c

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 





Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
Two lones
**EOE**
') parseLogEntry.

    self assert: rev message = 'Commit 4
Two lones'.

    "Created: / 05-12-2012 / 17:39:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-12-2012 / 23:33:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_04

    | revs |

    revs := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 





Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2
default
2:db43a5baa9acaf2536d8b12c070b4f5e0363d45c -1:0000000000000000000000000000000000000000 





Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 3
**EOE**
') parseLog.

    self assert: revs size == 2

    "Created: / 13-11-2012 / 17:31:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-12-2012 / 23:34:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_05a

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 

b/f2.txt b/f3.txt f1.txt


README.txt
Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
') parseLogEntry.

    self assert: rev changes size == 4.

    "Created: / 05-12-2012 / 18:34:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_05b

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 

c/f3.txt
c/f3.txt (b/f3.txt)
b/f3.txt

Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
') parseLogEntry.

    self assert: rev changes size == 1.

    "Created: / 05-12-2012 / 18:45:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_06

    | list |

    list := (HGCommandParser on: 'examples/tomcat6/apache-tomcat-6.0.35-src/.classpath (examples/tomcat/apache-tomcat-6.0.35-src/.classpath)examples/tomcat6/apache-tomcat-6.0.35-src/.project (examples/tomcat/apache-tomcat-6.0.35-src/.project)')
                parsePathCopyList.

    self assert: list size == 2

    "Created: / 10-01-2013 / 23:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_06b

    | list |

    list := (HGCommandParser on: 'examples (examples)examples/tomcat6/ (examples/tomcat/)')
                parsePathCopyList.

    self assert: list size == 2

    "Created: / 10-01-2013 / 23:23:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_version_2_3_3

    | vsn |

    vsn := (HGCommandParser on: 'Mercurial Distributed SCM (version 2.3.2)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
') parseCommandVersion.

    self assert: vsn = #(2 3 2)

    "Created: / 19-11-2012 / 20:59:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_version_2_4

    | vsn |

    vsn := (HGCommandParser on: 'Mercurial Distributed SCM (version 2.4)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
') parseCommandVersion.

    self assert: vsn = #(2 4 nil)

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

!HGCommandParserTests class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id::                                                                                                                        §'
! !