# HG changeset patch # User Artem Tikhomirov # Date 1295749732 -3600 # Node ID 993f6f8e13145907c7e87bd8a9028e51f5662f9c # Parent 5a69397f0f9992e881248d6a23e54f900f819148 Test for log command diff -r 5a69397f0f99 -r 993f6f8e1314 .hgignore --- a/.hgignore Sat Jan 22 22:53:57 2011 +0100 +++ b/.hgignore Sun Jan 23 03:28:52 2011 +0100 @@ -1,4 +1,5 @@ syntax:glob bin src/Extras.java -hgkit.jar +jhg.jar +jhg-tests.jar diff -r 5a69397f0f99 -r 993f6f8e1314 build.xml --- a/build.xml Sat Jan 22 22:53:57 2011 +0100 +++ b/build.xml Sun Jan 23 03:28:52 2011 +0100 @@ -1,5 +1,21 @@ - + + description @@ -7,24 +23,49 @@ - + - + - + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff -r 5a69397f0f99 -r 993f6f8e1314 src/org/tmatesoft/hg/core/LogCommand.java --- a/src/org/tmatesoft/hg/core/LogCommand.java Sat Jan 22 22:53:57 2011 +0100 +++ b/src/org/tmatesoft/hg/core/LogCommand.java Sun Jan 23 03:28:52 2011 +0100 @@ -35,7 +35,7 @@ /** *
- *   new LogCommand().limit(20).branch("maintenance-2.1").user("me").execute();
+ *   new LogCommand().limit(20).branch("maintenance-2.1").user("me").execute(new MyHandler());
  * 
* Not thread-safe (each thread has to use own {@link LogCommand} instance). * diff -r 5a69397f0f99 -r 993f6f8e1314 test/org/tmatesoft/hg/test/LogOutputParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/LogOutputParser.java Sun Jan 23 03:28:52 2011 +0100 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.test; + +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.tmate.hgkit.ll.HgRepository; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class LogOutputParser implements OutputParser { + private final List result = new LinkedList(); + private Pattern pattern1; + private Pattern pattern2; + private Pattern pattern3; + private Pattern pattern4; + + public LogOutputParser(boolean outputWithDebug) { + String p; + if (outputWithDebug) { + pattern1 = Pattern.compile("^changeset:\\s+(\\d+):([a-f0-9]{40})\n(^tag:(.+)$)?", Pattern.MULTILINE); + pattern2 = Pattern.compile("^parent:\\s+(-?\\d+):([a-f0-9]{40})\n", Pattern.MULTILINE); + pattern3 = Pattern.compile("^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:\\s+(\\S.+)\ndate:\\s+(\\S.+)\n", Pattern.MULTILINE); + pattern4 = Pattern.compile("^description:\n^(.+)\n\n", Pattern.MULTILINE); + //p = "^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:(.+)$"; + } else { + throw HgRepository.notImplemented(); + } + } + + public void reset() { + result.clear(); + } + + public List getResult() { + return result; + } + + public void parse(CharSequence seq) { + Matcher m = pattern1.matcher(seq); + while (m.find()) { + Record r = new Record(); + r.changesetIndex = Integer.parseInt(m.group(1)); + r.changesetNodeid = m.group(2); + //tags = m.group(4); + m.usePattern(pattern2); + if (m.find()) { + r.parent1Index = Integer.parseInt(m.group(1)); + r.parent1Nodeid = m.group(2); + } + if (m.find()) { + r.parent2Index = Integer.parseInt(m.group(1)); + r.parent2Nodeid = m.group(2); + } + m.usePattern(pattern3); + if (m.find()) { + r.user = m.group(3); + r.date = m.group(4); + } + m.usePattern(pattern4); + if (m.find()) { + r.description = m.group(1); + } + result.add(r); + m.usePattern(pattern1); + } + } + + public static class Record { + public int changesetIndex; + public String changesetNodeid; + public int parent1Index; + public int parent2Index; + public String parent1Nodeid; + public String parent2Nodeid; + public String user; + public String date; + public String description; + } + + private static void a(Matcher m) { + for (int i = 1; i <= m.groupCount(); i++) { + System.out.println("" + i + ":" + m.group(i)); + } + } +} diff -r 5a69397f0f99 -r 993f6f8e1314 test/org/tmatesoft/hg/test/ManifestOutputParser.java --- a/test/org/tmatesoft/hg/test/ManifestOutputParser.java Sat Jan 22 22:53:57 2011 +0100 +++ b/test/org/tmatesoft/hg/test/ManifestOutputParser.java Sun Jan 23 03:28:52 2011 +0100 @@ -36,7 +36,7 @@ private final LinkedHashMap result = new LinkedHashMap(); public ManifestOutputParser() { - pattern = Pattern.compile("^([a-z0-9]{40}) (\\d{3}) (.+)$", Pattern.MULTILINE); + pattern = Pattern.compile("^([a-f0-9]{40}) (\\d{3}) (.+)$", Pattern.MULTILINE); } public void reset() { diff -r 5a69397f0f99 -r 993f6f8e1314 test/org/tmatesoft/hg/test/TestHistory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Sun Jan 23 03:28:52 2011 +0100 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2011 TMate Software Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@svnkit.com + */ +package org.tmatesoft.hg.test; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.tmatesoft.hg.core.Cset; +import org.tmatesoft.hg.core.LogCommand; +import org.tmatesoft.hg.test.LogOutputParser.Record; + +import com.tmate.hgkit.fs.RepositoryLookup; +import com.tmate.hgkit.ll.HgRepository; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class TestHistory { + + private final HgRepository repo; + private ExecHelper eh; + private LogOutputParser changelogParser; + + public static void main(String[] args) throws Exception { + TestHistory th = new TestHistory(new RepositoryLookup().detectFromWorkingDir()); + th.testCompleteLog(); + } + + public TestHistory(HgRepository hgRepo) { + repo = hgRepo; + eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); + } + + public void testCompleteLog() throws Exception { + changelogParser.reset(); + eh.run("hg", "log", "--debug"); + List r = new LogCommand(repo).execute(); + report("hg log", r); + } + + private void report(String what, List r) { + final List consoleResult = changelogParser.getResult(); + Collections.reverse(consoleResult); + Iterator consoleResultItr = consoleResult.iterator(); + boolean hasErrors = false; + for (Cset cs : r) { + LogOutputParser.Record cr = consoleResultItr.next(); + int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0; + x |= cs.getDate().equals(cr.date) ? 0x2 : 0; + x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0; + x |= cs.getUser().equals(cr.user) ? 0x8 : 0; + x |= cs.getComment().equals(cr.description) ? 0x10 : 0; + if (x != 0x1f) { + System.err.printf("Error in %d (%d):0%o\n", cs.getRevision(), cr.changesetIndex, x); + hasErrors = true; + } + consoleResultItr.remove(); + } + if (consoleResultItr.hasNext()) { + System.out.println("Insufficient results from Java"); + hasErrors = true; + } + System.out.println(what + (hasErrors ? " FAIL" : " OK")); + } +}