Mercurial > jhg
changeset 203:66fd2c73c56f
Basic test for HgOutgoingCommand. Handle cases with no outgoing changes in RepositoryComparator
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 26 Apr 2011 15:52:33 +0200 |
parents | 706bcc7cfee4 |
children | 883f1efbcf27 |
files | src/org/tmatesoft/hg/internal/RepositoryComparator.java src/org/tmatesoft/hg/repo/HgRemoteRepository.java test/org/tmatesoft/hg/test/Configuration.java test/org/tmatesoft/hg/test/ExecHelper.java test/org/tmatesoft/hg/test/OutputParser.java test/org/tmatesoft/hg/test/TestIncoming.java test/org/tmatesoft/hg/test/TestOutgoing.java |
diffstat | 7 files changed, 147 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/RepositoryComparator.java Tue Apr 26 02:50:06 2011 +0200 +++ b/src/org/tmatesoft/hg/internal/RepositoryComparator.java Tue Apr 26 15:52:33 2011 +0200 @@ -112,6 +112,13 @@ earliestRevision = lr; } } + if (earliestRevision == Integer.MAX_VALUE) { + // either there are no common nodes (known locally and at remote) + // or no local children found (local is up to date). In former case, perhaps I shall bit return silently, + // but check for possible wrong repo comparison (hs says 'repository is unrelated' if I try to + // check in/out for a repo that has no common nodes. + return; + } if (earliestRevision < 0 || earliestRevision >= changelog.getLastRevision()) { throw new HgBadStateException(String.format("Invalid index of common known revision: %d in total of %d", earliestRevision, 1+changelog.getLastRevision())); }
--- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Tue Apr 26 02:50:06 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Tue Apr 26 15:52:33 2011 +0200 @@ -349,6 +349,11 @@ } } + @Override + public String toString() { + return getClass().getSimpleName() + '[' + getLocation() + ']'; + } + private HgLookup getLookupHelper() { if (lookupHelper == null) { lookupHelper = new HgLookup();
--- a/test/org/tmatesoft/hg/test/Configuration.java Tue Apr 26 02:50:06 2011 +0200 +++ b/test/org/tmatesoft/hg/test/Configuration.java Tue Apr 26 15:52:33 2011 +0200 @@ -36,23 +36,28 @@ public class Configuration { private static Configuration inst; - private final File root; + private File root; private final HgLookup lookup; private File tempDir; private List<String> remoteServers; - private Configuration(File reposRoot) { - root = reposRoot; + private Configuration() { lookup = new HgLookup(); } + private File getRoot() { + if (root == null) { + String repo2 = System.getProperty("hg4j.tests.repos"); + assertNotNull("System property hg4j.tests.repos is undefined", repo2); + root = new File(repo2); + assertTrue(root.exists()); + } + return root; + } + public static Configuration get() { if (inst == null) { - String repo2 = System.getProperty("hg4j.tests.repos"); - assertNotNull(repo2); - File rr = new File(repo2); - assertTrue(rr.exists()); - inst = new Configuration(rr); + inst = new Configuration(); } return inst; } @@ -63,7 +68,7 @@ // fails if repo not found public HgRepository find(String key) throws Exception { - HgRepository rv = lookup.detect(new File(root, key)); + HgRepository rv = lookup.detect(new File(getRoot(), key)); assertNotNull(rv); assertFalse(rv.isInvalid()); return rv;
--- a/test/org/tmatesoft/hg/test/ExecHelper.java Tue Apr 26 02:50:06 2011 +0200 +++ b/test/org/tmatesoft/hg/test/ExecHelper.java Tue Apr 26 15:52:33 2011 +0200 @@ -33,7 +33,7 @@ public class ExecHelper { private final OutputParser parser; - private final File dir; + private File dir; private int exitValue; public ExecHelper(OutputParser outParser, File workingDir) { @@ -94,4 +94,8 @@ public int getExitValue() { return exitValue; } + + public void cwd(File wd) { + dir = wd; + } }
--- a/test/org/tmatesoft/hg/test/OutputParser.java Tue Apr 26 02:50:06 2011 +0200 +++ b/test/org/tmatesoft/hg/test/OutputParser.java Tue Apr 26 15:52:33 2011 +0200 @@ -26,8 +26,18 @@ public void parse(CharSequence seq); public class Stub implements OutputParser { + private boolean shallDump; + public Stub() { + this(false); + } + public Stub(boolean dump) { + shallDump = dump; + } public void parse(CharSequence seq) { - // no-op + if (shallDump) { + System.out.println(seq); + } + // else no-op } } }
--- a/test/org/tmatesoft/hg/test/TestIncoming.java Tue Apr 26 02:50:06 2011 +0200 +++ b/test/org/tmatesoft/hg/test/TestIncoming.java Tue Apr 26 15:52:33 2011 +0200 @@ -93,12 +93,12 @@ cmd.executeFull(collector); eh.run("hg", "incoming", "--debug", hgRemote.getLocation()); List<Nodeid> liteResult = cmd.executeLite(null); - report(collector, outParser, liteResult); + report(collector, outParser, liteResult, errorCollector); return liteResult; } - private void report(HgLogCommand.CollectHandler collector, LogOutputParser outParser, List<Nodeid> liteResult) { - TestHistory.report("hg in - against blank repo", collector.getChanges(), outParser.getResult(), false, errorCollector); + static void report(HgLogCommand.CollectHandler collector, LogOutputParser outParser, List<Nodeid> liteResult, ErrorCollectorExt errorCollector) { + TestHistory.report("hg vs execFull", collector.getChanges(), outParser.getResult(), false, errorCollector); // ArrayList<Nodeid> expected = new ArrayList<Nodeid>(outParser.getResult().size()); for (LogOutputParser.Record r : outParser.getResult()) { @@ -122,13 +122,18 @@ } errorCollector.checkThat(what + " Superfluous cset reported by HgIncomingCommand.execLite", set.isEmpty(), equalTo(true)); } - - static File initEmptyTempRepo(String dirName) throws IOException { + + static File createEmptyDir(String dirName) throws IOException { File dest = new File(Configuration.get().getTempDir(), dirName); if (dest.exists()) { TestClone.rmdir(dest); } dest.mkdirs(); + return dest; + } + + static File initEmptyTempRepo(String dirName) throws IOException { + File dest = createEmptyDir(dirName); Internals implHelper = new Internals(); implHelper.setStorageConfig(1, STORE | FNCACHE | DOTENCODE); implHelper.initEmptyRepository(new File(dest, ".hg"));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/TestOutgoing.java Tue Apr 26 15:52:33 2011 +0200 @@ -0,0 +1,95 @@ +/* + * 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@hg4j.com + */ +package org.tmatesoft.hg.test; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.tmatesoft.hg.core.HgLogCommand; +import org.tmatesoft.hg.core.HgOutgoingCommand; +import org.tmatesoft.hg.core.Nodeid; +import org.tmatesoft.hg.repo.HgLookup; +import org.tmatesoft.hg.repo.HgRemoteRepository; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class TestOutgoing { + + @Rule + public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); + + public static void main(String[] args) throws Throwable { + Configuration.get().remoteServers("http://localhost:8000/"); + TestOutgoing t = new TestOutgoing(); + t.testSimple(); + t.errorCollector.verify(); + } + + public TestOutgoing() { + Configuration.get().remoteServers("http://localhost:8000/"); + } + + @Test + public void testSimple() throws Exception { + int x = 0; + HgLookup lookup = new HgLookup(); + for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { + File dest = TestIncoming.createEmptyDir("test-outgoing-" + x++); + ExecHelper eh0 = new ExecHelper(new OutputParser.Stub(false), null); + eh0.run("hg", "clone", hgRemote.getLocation(), dest.toString()); + eh0.cwd(dest); + Assert.assertEquals("initial clone failed", 0, eh0.getExitValue()); + HgOutgoingCommand cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); + LogOutputParser outParser = new LogOutputParser(true); + ExecHelper eh = new ExecHelper(outParser, dest); + HgLogCommand.CollectHandler collector = new HgLogCommand.CollectHandler(); + // + cmd.executeFull(collector); + List<Nodeid> liteResult = cmd.executeLite(null); + eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); + TestIncoming.report(collector, outParser, liteResult, errorCollector); + // + File f = new File(dest, "Test.txt"); + append(f, "1"); + eh0.run("hg", "add"); + eh0.run("hg", "commit", "-m", "1"); + append(f, "2"); + eh0.run("hg", "commit", "-m", "2"); + // + cmd = new HgOutgoingCommand(lookup.detect(dest)).against(hgRemote); + cmd.executeFull(collector = new HgLogCommand.CollectHandler()); + liteResult = cmd.executeLite(null); + outParser.reset(); + eh.run("hg", "outgoing", "--debug", hgRemote.getLocation()); + TestIncoming.report(collector, outParser, liteResult, errorCollector); + } + } + + static void append(File f, String s) throws IOException { + FileWriter fw = new FileWriter(f); + fw.append(s); + fw.close(); + } +}