Mercurial > jhg
changeset 101:777ab7034c1b
Switch to JUnit for tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 28 Jan 2011 03:07:25 +0100 |
parents | b71b3f7d24d4 |
children | a3a2e5deb320 |
files | .classpath .hgignore build.xml lib/junit-4.8.2.jar test/org/tmatesoft/hg/test/ErrorCollectorExt.java test/org/tmatesoft/hg/test/TestHistory.java test/org/tmatesoft/hg/test/TestManifest.java test/org/tmatesoft/hg/test/TestStatus.java test/org/tmatesoft/hg/test/TestStorePath.java |
diffstat | 9 files changed, 108 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Fri Jan 28 02:15:12 2011 +0100 +++ b/.classpath Fri Jan 28 03:07:25 2011 +0100 @@ -4,5 +4,6 @@ <classpathentry kind="src" path="test"/> <classpathentry kind="src" path="cmdline"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="lib" path="lib/junit-4.8.2.jar" sourcepath="C:/eclipse-3.7/plugins/org.junit.source_4.8.1.v4_8_1_v20100427-1100.jar"/> <classpathentry kind="output" path="bin"/> </classpath>
--- a/.hgignore Fri Jan 28 02:15:12 2011 +0100 +++ b/.hgignore Fri Jan 28 03:07:25 2011 +0100 @@ -1,6 +1,6 @@ syntax:glob bin src/Extras.java -jhg.jar -jhg-tests.jar -jhg-cl.jar +hg4j.jar +hg4j-tests.jar +hg4j-console.jar
--- a/build.xml Fri Jan 28 02:15:12 2011 +0100 +++ b/build.xml Fri Jan 28 03:07:25 2011 +0100 @@ -15,38 +15,49 @@ the terms of a license other than GNU General Public License contact TMate Software at support@svnkit.com --> -<project name="jhg" default="samples"> +<project name="hg4j" default="samples"> <description> - description + Build, test and showcase hg4j </description> + + <property name="junit.jar" value="lib/junit-4.8.2.jar"/> <target name="samples" depends="build-cmdline"> <echo message="History of a specific file(s)"/> - <java classpath="jhg.jar;jhg-cl.jar" classname="org.tmatesoft.hg.console.Log"> + <java classpath="hg4j.jar;hg4j-console.jar" classname="org.tmatesoft.hg.console.Log"> <arg line="design.txt .classpath src/com/tmate/hgkit/ll/LocalHgRepo.java"/> </java> <echo message="Whole repo log"/> - <java classpath="jhg.jar;jhg-cl.jar" classname="org.tmatesoft.hg.console.Log"/> + <java classpath="hg4j.jar;hg4j-console.jar" classname="org.tmatesoft.hg.console.Log"/> <echo message="Content of a file"/> - <java classpath="jhg.jar;jhg-cl.jar" classname="org.tmatesoft.hg.console.Cat"> + <java classpath="hg4j.jar;hg4j-console.jar" classname="org.tmatesoft.hg.console.Cat"> <arg line="src/com/tmate/hgkit/ll/Revlog.java"/> </java> </target> <target name="tests" depends="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"/> + <junit printsummary="on"> + <classpath path="hg4j.jar;hg4j-tests.jar;${junit.jar}"/> + <test name="org.tmatesoft.hg.test.TestHistory"/> + <test name="org.tmatesoft.hg.test.TestManifest"/> + <test name="org.tmatesoft.hg.test.TestStatus"/> + <test name="org.tmatesoft.hg.test.TestStorePath"/> + </junit> + <!-- + <java classpath="hg4j.jar;hg4j-tests.jar" classname="org.tmatesoft.hg.test.TestHistory"/> + <java classpath="hg4j.jar;hg4j-tests.jar" classname="org.tmatesoft.hg.test.TestManifest"/> + <java classpath="hg4j.jar;hg4j-tests.jar" classname="org.tmatesoft.hg.test.TestStatus"/> + --> </target> <target name="build"> <mkdir dir="bin"/> <javac srcdir="src" destdir="bin"/> - <jar destfile="jhg.jar"> + <jar destfile="hg4j.jar"> <fileset dir="bin/"> <include name="org/tmatesoft/hg/core/**" /> <include name="org/tmatesoft/hg/util/**" /> @@ -59,13 +70,13 @@ <target name="build-tests" depends="build"> <mkdir dir="bin"/> <javac srcdir="test" destdir="bin"/> - <jar destfile="jhg-tests.jar" basedir="bin" includes="org/tmatesoft/hg/test/**"/> + <jar destfile="hg4j-tests.jar" basedir="bin" includes="org/tmatesoft/hg/test/**"/> </target> <target name="build-cmdline" depends="build"> <mkdir dir="bin"/> <javac srcdir="cmdline" destdir="bin"/> - <jar destfile="jhg-cl.jar" basedir="bin" includes="org/tmatesoft/hg/console/**"/> + <jar destfile="hg4j-console.jar" basedir="bin" includes="org/tmatesoft/hg/console/**"/> </target> </project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/ErrorCollectorExt.java Fri Jan 28 03:07:25 2011 +0100 @@ -0,0 +1,31 @@ +/* + * 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 org.junit.rules.ErrorCollector; + +/** + * Expose verify method for allow not-junit runs to check test outcome + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +final class ErrorCollectorExt extends ErrorCollector { + public void verify() throws Throwable { + super.verify(); + } +} \ No newline at end of file
--- a/test/org/tmatesoft/hg/test/TestHistory.java Fri Jan 28 02:15:12 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Fri Jan 28 03:07:25 2011 +0100 @@ -20,16 +20,15 @@ import java.util.Iterator; import java.util.List; +import org.junit.Test; import org.tmatesoft.hg.core.Cset; import org.tmatesoft.hg.core.LogCommand; -import org.tmatesoft.hg.core.StatusCommand; import org.tmatesoft.hg.core.LogCommand.CollectHandler; import org.tmatesoft.hg.core.LogCommand.FileHistoryHandler; import org.tmatesoft.hg.core.LogCommand.FileRevision; import org.tmatesoft.hg.core.Path; +import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.HgLookup; -import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.test.LogOutputParser.Record; @@ -45,17 +44,22 @@ private LogOutputParser changelogParser; public static void main(String[] args) throws Exception { - TestHistory th = new TestHistory(new HgLookup().detectFromWorkingDir()); + TestHistory th = new TestHistory(); th.testCompleteLog(); th.testFollowHistory(); th.testPerformance(); } + + public TestHistory() throws Exception { + this(new HgLookup().detectFromWorkingDir()); + } - public TestHistory(HgRepository hgRepo) { + private TestHistory(HgRepository hgRepo) { repo = hgRepo; eh = new ExecHelper(changelogParser = new LogOutputParser(true), null); } + @Test public void testCompleteLog() throws Exception { changelogParser.reset(); eh.run("hg", "log", "--debug"); @@ -63,6 +67,7 @@ report("hg log - COMPLETE REPO HISTORY", r, true); } + @Test public void testFollowHistory() throws Exception { final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); try {
--- a/test/org/tmatesoft/hg/test/TestManifest.java Fri Jan 28 02:15:12 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestManifest.java Fri Jan 28 03:07:25 2011 +0100 @@ -22,6 +22,8 @@ import java.util.LinkedList; import java.util.Map; +import org.junit.Assume; +import org.junit.Test; import org.tmatesoft.hg.core.LogCommand.FileRevision; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.core.Path; @@ -53,26 +55,33 @@ }; public static void main(String[] args) throws Exception { - HgRepository repo = new HgLookup().detectFromWorkingDir(); - TestManifest tm = new TestManifest(repo); + TestManifest tm = new TestManifest(); tm.testTip(); tm.testFirstRevision(); tm.testRevisionInTheMiddle(); } + + public TestManifest() throws Exception { + this(new HgLookup().detectFromWorkingDir()); + } - public TestManifest(HgRepository hgRepo) { + private TestManifest(HgRepository hgRepo) { repo = hgRepo; + Assume.assumeTrue(repo.isInvalid()); eh = new ExecHelper(manifestParser = new ManifestOutputParser(), null); } - + + @Test public void testTip() throws Exception { testRevision(TIP); } + @Test public void testFirstRevision() throws Exception { testRevision(0); } + @Test public void testRevisionInTheMiddle() throws Exception { int rev = repo.getManifest().getRevisionCount() / 2; if (rev == 0) {
--- a/test/org/tmatesoft/hg/test/TestStatus.java Fri Jan 28 02:15:12 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestStatus.java Fri Jan 28 03:07:25 2011 +0100 @@ -23,10 +23,12 @@ import java.util.LinkedList; import java.util.List; +import org.junit.Assume; +import org.junit.Test; import org.tmatesoft.hg.core.Path; import org.tmatesoft.hg.core.StatusCommand; +import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; -import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgStatusCollector; import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; @@ -43,19 +45,24 @@ private ExecHelper eh; public static void main(String[] args) throws Exception { - HgRepository repo = new HgLookup().detectFromWorkingDir(); - TestStatus test = new TestStatus(repo); + TestStatus test = new TestStatus(); test.testLowLevel(); test.testStatusCommand(); test.testPerformance(); } - public TestStatus(HgRepository hgRepo) { + public TestStatus() throws Exception { + this(new HgLookup().detectFromWorkingDir()); + } + + private TestStatus(HgRepository hgRepo) { repo = hgRepo; + Assume.assumeTrue(!repo.isInvalid()); statusParser = new StatusOutputParser(); eh = new ExecHelper(statusParser, null); } + @Test public void testLowLevel() throws Exception { final HgWorkingCopyStatusCollector wcc = new HgWorkingCopyStatusCollector(repo); statusParser.reset(); @@ -83,6 +90,7 @@ report("Status -A -rev " + range, r, statusParser); } + @Test public void testStatusCommand() throws Exception { final StatusCommand sc = new StatusCommand(repo).all(); HgStatusCollector.Record r;
--- a/test/org/tmatesoft/hg/test/TestStorePath.java Fri Jan 28 02:15:12 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestStorePath.java Fri Jan 28 03:07:25 2011 +0100 @@ -16,6 +16,11 @@ */ package org.tmatesoft.hg.test; +import static org.hamcrest.CoreMatchers.equalTo; +import junit.framework.Assert; + +import org.junit.Rule; +import org.junit.Test; import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.util.PathRewrite; @@ -26,12 +31,16 @@ */ public class TestStorePath { + @Rule + public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); + private PathRewrite storePathHelper; - public static void main(String[] args) { + public static void main(String[] args) throws Throwable { final TestStorePath test = new TestStorePath(); test.testWindowsFilenames(); test.testHashLongPath(); + test.errorCollector.verify(); } public TestStorePath() { @@ -40,13 +49,15 @@ storePathHelper = i.buildDataFilesHelper(); } + @Test public void testWindowsFilenames() { // see http://mercurial.selenic.com/wiki/fncacheRepoFormat#Encoding_of_Windows_reserved_names String n1 = "aux.bla/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c"; String r1 = "store/data/au~78.bla/bla.aux/pr~6e/_p_r_n/lpt/co~6d3/nu~6c/coma/foo._n_u_l/normal.c.i"; - report("Windows filenames are ", n1, r1); + Assert.assertEquals("Windows filenames are ", r1, storePathHelper.rewrite(n1)); } + @Test public void testHashLongPath() { String n1 = "AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT"; String r1 = "store/dh/au~78/second/x.prn/fourth/fi~3afth/sixth/seventh/eighth/nineth/tenth/loremia20419e358ddff1bf8751e38288aff1d7c32ec05.i"; @@ -55,18 +66,8 @@ String n3 = "AUX.THE-QUICK-BROWN-FOX-JU:MPS-OVER-THE-LAZY-DOG-THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG.TXT"; String r3 = "store/dh/au~78.the-quick-brown-fox-ju~3amps-over-the-lazy-dog-the-quick-brown-fox-jud4dcadd033000ab2b26eb66bae1906bcb15d4a70.i"; // TODO segment[8] == [. ], segment[8] in the middle of windows reserved name or character (to see if ~xx is broken) - report("1", n1, r1); - report("2", n2, r2); - report("3", n3, r3); - } - - private void report(String msg, String name, String expected) { - String res = check(name, expected); - System.out.println(msg + (res == null ? "OK" : "WRONG:" + res)); - } - - private String check(String name, String expected) { - String result = storePathHelper.rewrite(name); - return expected.equals(result) ? null : result; + errorCollector.checkThat(storePathHelper.rewrite(n1), equalTo(r1)); + errorCollector.checkThat(storePathHelper.rewrite(n2), equalTo(r2)); + errorCollector.checkThat(storePathHelper.rewrite(n3), equalTo(r3)); } }