# HG changeset patch # User Artem Tikhomirov # Date 1296180445 -3600 # Node ID 777ab7034c1bb644c22f4d4c0809316760306713 # Parent b71b3f7d24d40607d99ce7528dd31d8d0cee61f3 Switch to JUnit for tests diff -r b71b3f7d24d4 -r 777ab7034c1b .classpath --- a/.classpath Fri Jan 28 02:15:12 2011 +0100 +++ b/.classpath Fri Jan 28 03:07:25 2011 +0100 @@ -4,5 +4,6 @@ + diff -r b71b3f7d24d4 -r 777ab7034c1b .hgignore --- 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 diff -r b71b3f7d24d4 -r 777ab7034c1b build.xml --- 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 --> - + - description + Build, test and showcase hg4j + + - + - + - + - - - + + + + + + + + - + @@ -59,13 +70,13 @@ - + - + diff -r b71b3f7d24d4 -r 777ab7034c1b lib/junit-4.8.2.jar Binary file lib/junit-4.8.2.jar has changed diff -r b71b3f7d24d4 -r 777ab7034c1b test/org/tmatesoft/hg/test/ErrorCollectorExt.java --- /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 diff -r b71b3f7d24d4 -r 777ab7034c1b test/org/tmatesoft/hg/test/TestHistory.java --- 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 { diff -r b71b3f7d24d4 -r 777ab7034c1b test/org/tmatesoft/hg/test/TestManifest.java --- 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) { diff -r b71b3f7d24d4 -r 777ab7034c1b test/org/tmatesoft/hg/test/TestStatus.java --- 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; diff -r b71b3f7d24d4 -r 777ab7034c1b test/org/tmatesoft/hg/test/TestStorePath.java --- 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)); } }