comparison test/org/tmatesoft/hg/test/TestClone.java @ 202:706bcc7cfee4

Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 26 Apr 2011 02:50:06 +0200
parents a736f42ed75b
children 883f1efbcf27
comparison
equal deleted inserted replaced
201:a736f42ed75b 202:706bcc7cfee4
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.Arrays; 21 import java.util.Arrays;
22 import java.util.LinkedList; 22 import java.util.LinkedList;
23 import java.util.List; 23 import java.util.List;
24 24
25 import junit.framework.Assert; 25 import org.hamcrest.CoreMatchers;
26
27 import org.junit.Rule; 26 import org.junit.Rule;
28 import org.tmatesoft.hg.core.HgCloneCommand; 27 import org.tmatesoft.hg.core.HgCloneCommand;
29 import org.tmatesoft.hg.repo.HgRemoteRepository; 28 import org.tmatesoft.hg.repo.HgRemoteRepository;
30 29
31 /** 30 /**
36 public class TestClone { 35 public class TestClone {
37 36
38 @Rule 37 @Rule
39 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); 38 public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
40 39
41 public static void main(String[] args) throws Exception { 40 public static void main(String[] args) throws Throwable {
42 TestClone t = new TestClone(); 41 TestClone t = new TestClone();
43 t.testSimpleClone(); 42 t.testSimpleClone();
43 t.errorCollector.verify();
44 } 44 }
45 45
46 public TestClone() { 46 public TestClone() {
47 } 47 }
48 48
49 public void testSimpleClone() throws Exception { 49 public void testSimpleClone() throws Exception {
50 int x = 0; 50 int x = 0;
51 final File tempDir = new File(System.getProperty("java.io.tmpdir")); 51 final File tempDir = Configuration.get().getTempDir();
52 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) { 52 for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) {
53 HgCloneCommand cmd = new HgCloneCommand(); 53 HgCloneCommand cmd = new HgCloneCommand();
54 cmd.source(hgRemote); 54 cmd.source(hgRemote);
55 File dest = new File(tempDir, "test-clone-" + x++); 55 File dest = new File(tempDir, "test-clone-" + x++);
56 if (dest.exists()) { 56 if (dest.exists()) {
61 verify(hgRemote, dest); 61 verify(hgRemote, dest);
62 } 62 }
63 } 63 }
64 64
65 private void verify(HgRemoteRepository hgRemote, File dest) throws Exception { 65 private void verify(HgRemoteRepository hgRemote, File dest) throws Exception {
66 OutputParser noop = new OutputParser() { 66 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), dest);
67 public void parse(CharSequence seq) {
68 // no-op
69 }
70 };
71 ExecHelper eh = new ExecHelper(noop, dest);
72 eh.run("hg", "verify"); 67 eh.run("hg", "verify");
73 Assert.assertEquals(0, eh.getExitValue()); 68 errorCollector.checkThat("Verify", eh.getExitValue(), CoreMatchers.equalTo(0));
74 eh.run("hg", "out", hgRemote.getLocation()); 69 eh.run("hg", "out", hgRemote.getLocation());
75 Assert.assertEquals(1, eh.getExitValue()); 70 errorCollector.checkThat("Outgoing", eh.getExitValue(), CoreMatchers.equalTo(1));
76 eh.run("hg", "in", hgRemote.getLocation()); 71 eh.run("hg", "in", hgRemote.getLocation());
77 Assert.assertEquals(1, eh.getExitValue()); 72 errorCollector.checkThat("Incoming", eh.getExitValue(), CoreMatchers.equalTo(1));
78 } 73 }
79 74
80 private static void rmdir(File dest) throws IOException { 75 static void rmdir(File dest) throws IOException {
81 LinkedList<File> queue = new LinkedList<File>(); 76 LinkedList<File> queue = new LinkedList<File>();
82 queue.addAll(Arrays.asList(dest.listFiles())); 77 queue.addAll(Arrays.asList(dest.listFiles()));
83 while (!queue.isEmpty()) { 78 while (!queue.isEmpty()) {
84 File next = queue.removeFirst(); 79 File next = queue.removeFirst();
85 if (next.isDirectory()) { 80 if (next.isDirectory()) {