Mercurial > jhg
changeset 70:993f6f8e1314
Test for log command
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 03:28:52 +0100 |
parents | 5a69397f0f99 |
children | ce6d23673f2d |
files | .hgignore build.xml src/org/tmatesoft/hg/core/LogCommand.java test/org/tmatesoft/hg/test/LogOutputParser.java test/org/tmatesoft/hg/test/ManifestOutputParser.java test/org/tmatesoft/hg/test/TestHistory.java |
diffstat | 6 files changed, 238 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 @@ <?xml version="1.0" encoding="UTF-8"?> -<project name="hgkit" default="samples"> +<!-- + Copyright (c) 2010-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 +--> +<project name="jhg" default="samples"> <description> description </description> @@ -7,24 +23,49 @@ <target name="samples" depends="build"> <echo message="History of a specific file(s)"/> - <java classpath="hgkit.jar" classname="com.tmate.hgkit.console.Log"> + <java classpath="jhg.jar" classname="com.tmate.hgkit.console.Log"> <arg line="design.txt .classpath src/com/tmate/hgkit/ll/LocalHgRepo.java"/> </java> <echo message="Whole repo log"/> - <java classpath="hgkit.jar" classname="com.tmate.hgkit.console.Log"/> + <java classpath="jhg.jar" classname="com.tmate.hgkit.console.Log"/> <echo message="Content of a file"/> - <java classpath="hgkit.jar" classname="com.tmate.hgkit.console.Cat"> + <java classpath="jhg.jar" classname="com.tmate.hgkit.console.Cat"> <arg line="src/com/tmate/hgkit/ll/Revlog.java"/> </java> </target> + + <target name="tests" depends="build, build-tests"> + <java classpath="jhg.jar,jhg-tests.jar" classname="org.tmatesoft.hg.test.TestHistory"/> + <java classpath="jhg.jar,jhg-tests.jar" classname="org.tmatesoft.hg.test.TestManifest"/> + <java classpath="jhg.jar,jhg-tests.jar" classname="org.tmatesoft.hg.test.TestStatus"/> + </target> <target name="build"> <mkdir dir="bin"/> <javac srcdir="src" destdir="bin"/> - <jar destfile="hgkit.jar" basedir="bin"/> + <jar destfile="jhg.jar"> + <fileset dir="bin/"> + <include name="org/tmatesoft/hg/core/**" /> + <include name="org/tmatesoft/hg/util/**" /> + <include name="org/tmatesoft/hg/repo/**" /> + <include name="org/tmatesoft/hg/internal/**" /> + </fileset> + </jar> + </target> + + <target name="build-tests"> + <mkdir dir="bin"/> + <javac srcdir="test" destdir="bin"/> + <jar destfile="jhg-tests.jar" basedir="bin" includes="org/tmatesoft/hg/test/**/*"/> + </target> + + <target name="build-cmdline"> + <mkdir dir="bin"/> + <javac srcdir="cmdline" destdir="bin"/> + <jar destfile="jhg-cl.jar" basedir="bin" includes="org/tmatesoft/hg/console/**/*"/> </target> </project>
--- 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 @@ /** * <pre> - * new LogCommand().limit(20).branch("maintenance-2.1").user("me").execute(); + * new LogCommand().limit(20).branch("maintenance-2.1").user("me").execute(new MyHandler()); * </pre> * Not thread-safe (each thread has to use own {@link LogCommand} instance). *
--- /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<Record> result = new LinkedList<Record>(); + 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<Record> 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)); + } + } +}
--- 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<Path, Nodeid> result = new LinkedHashMap<Path, Nodeid>(); 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() {
--- /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<Cset> r = new LogCommand(repo).execute(); + report("hg log", r); + } + + private void report(String what, List<Cset> r) { + final List<Record> consoleResult = changelogParser.getResult(); + Collections.reverse(consoleResult); + Iterator<LogOutputParser.Record> 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")); + } +}