changeset 147:a05145db4d0c

Bring test repos along with us to recreate testbench
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Feb 2011 15:49:26 +0100
parents 8c9f729f4dfa
children 1a7a9a20e1f9
files build.xml test-repos.jar test/org/tmatesoft/hg/test/Configuration.java test/org/tmatesoft/hg/test/TestHistory.java test/org/tmatesoft/hg/test/TestStatus.java
diffstat 5 files changed, 163 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/build.xml	Fri Feb 18 05:20:18 2011 +0100
+++ b/build.xml	Tue Feb 22 15:49:26 2011 +0100
@@ -64,20 +64,19 @@
 	</target>
 
 	<target name="tests" depends="build-tests">
+		<property name="test-repos-root" value="${java.io.tmpdir}/hg4j-tests/"/>
+		<delete dir="${test-repos-root}" quiet="yes"/>
+		<unjar src="test-repos.jar" dest="${test-repos-root}"/>
 		<junit>
 			<classpath path="${hg4j.jar};${hg4j-tests.jar};${junit.jar}" />
 			<formatter type="xml" />
 			<formatter type="plain" usefile="no" />
+			<sysproperty key="hg4j.tests.repos" value="${test-repos-root}"/>
 			<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">
@@ -90,19 +89,26 @@
 				<include name="org/tmatesoft/hg/repo/**" />
 				<include name="org/tmatesoft/hg/internal/**" />
 			</fileset>
+			<fileset file="COPYING"/>
 		</jar>
 	</target>
 
 	<target name="build-tests" depends="build">
 		<mkdir dir="bin" />
 		<javac srcdir="test" destdir="bin" />
-		<jar destfile="${hg4j-tests.jar}" basedir="bin" includes="org/tmatesoft/hg/test/**" />
+		<jar destfile="${hg4j-tests.jar}">
+			<fileset dir="bin" includes="org/tmatesoft/hg/test/**"/>
+			<fileset file="COPYING"/>
+		</jar>
 	</target>
 
 	<target name="build-cmdline" depends="build">
 		<mkdir dir="bin" />
 		<javac srcdir="cmdline" destdir="bin" />
-		<jar destfile="${hg4j-console.jar}" basedir="bin" includes="org/tmatesoft/hg/console/**" />
+		<jar destfile="${hg4j-console.jar}">
+			<fileset dir="bin/" includes="org/tmatesoft/hg/console/**"/>
+			<fileset file="COPYING"/>
+		</jar>
 	</target>
 
 </project>
Binary file test-repos.jar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/org/tmatesoft/hg/test/Configuration.java	Tue Feb 22 15:49:26 2011 +0100
@@ -0,0 +1,64 @@
+/*
+ * 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 static org.junit.Assert.*;
+
+import java.io.File;
+
+import org.tmatesoft.hg.repo.HgLookup;
+import org.tmatesoft.hg.repo.HgRepository;
+
+/**
+ *
+ * @author Artem Tikhomirov
+ * @author TMate Software Ltd.
+ */
+public class Configuration {
+	
+	private static Configuration inst;
+	private final File root;
+	private final HgLookup lookup;
+	
+	private Configuration(File reposRoot) {
+		root = reposRoot;
+		lookup = new HgLookup();
+	}
+	
+	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);
+		}
+		return inst;
+	}
+	
+	public HgRepository own() throws Exception {
+		return lookup.detectFromWorkingDir();
+	}
+
+	// fails if repo not found
+	public HgRepository find(String key) throws Exception {
+		HgRepository rv = lookup.detect(new File(root, key));
+		assertNotNull(rv);
+		assertFalse(rv.isInvalid());
+		return rv;
+	}
+}
--- a/test/org/tmatesoft/hg/test/TestHistory.java	Fri Feb 18 05:20:18 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestHistory.java	Tue Feb 22 15:49:26 2011 +0100
@@ -18,6 +18,7 @@
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Collections;
 import java.util.Comparator;
@@ -25,7 +26,6 @@
 import java.util.LinkedList;
 import java.util.List;
 
-import org.hamcrest.CoreMatchers;
 import org.junit.Rule;
 import org.junit.Test;
 import org.tmatesoft.hg.core.HgChangeset;
@@ -49,8 +49,8 @@
 	@Rule
 	public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
 
-	private final HgRepository repo;
-	private ExecHelper eh;
+	private HgRepository repo;
+	private final ExecHelper eh;
 	private LogOutputParser changelogParser;
 	
 	public static void main(String[] args) throws Throwable {
@@ -58,7 +58,12 @@
 		th.testCompleteLog();
 		th.testFollowHistory();
 		th.errorCollector.verify();
-		th.testPerformance();
+//		th.testPerformance();
+		th.testOriginalTestLogRepo();
+		th.testUsernames();
+		th.testBranches();
+		//
+		th.errorCollector.verify();
 	}
 	
 	public TestHistory() throws Exception {
@@ -68,6 +73,7 @@
 	private TestHistory(HgRepository hgRepo) {
 		repo = hgRepo;
 		eh = new ExecHelper(changelogParser = new LogOutputParser(true), null);
+		
 	}
 
 	@Test
@@ -121,15 +127,15 @@
 		if (reverseConsoleResults) {
 			Collections.reverse(consoleResult);
 		}
-		Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator();
+		Iterator<Record> consoleResultItr = consoleResult.iterator();
 		for (HgChangeset cs : r) {
-			LogOutputParser.Record cr = consoleResultItr.next();
+			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;
-			errorCollector.checkThat(String.format(what + ". Error in %d:%d. ", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f));
+			errorCollector.checkThat(String.format(what + ". Error in %d hg4j rev comparing to %d cmdline's.", cs.getRevision(), cr.changesetIndex), x, equalTo(0x1f));
 			consoleResultItr.remove();
 		}
 		errorCollector.checkThat(what + ". Insufficient results from Java ", consoleResultItr.hasNext(), equalTo(false));
@@ -149,4 +155,73 @@
 		final long end = System.currentTimeMillis();
 		System.out.printf("'hg log --debug', %d runs: Native client total %d (%d per run), Java client %d (%d)\n", runs, start2-start1, (start2-start1)/runs, end-start2, (end-start2)/runs);
 	}
+
+	@Test
+	public void testOriginalTestLogRepo() throws Exception {
+		repo = Configuration.get().find("log-1");
+		HgLogCommand cmd = new HgLogCommand(repo);
+		// funny enough, but hg log -vf a -R c:\temp\hg\test-log\a doesn't work, while --cwd <same> works fine
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "a", "--cwd", repo.getLocation());
+		report("log a", cmd.file("a", false).execute(), true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-f", "a", "--cwd", repo.getLocation());
+		List<HgChangeset> r = cmd.file("a", true).execute();
+		report("log -f a", r, true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-f", "e", "--cwd", repo.getLocation());
+		report("log -f e", cmd.file("e", true).execute(), false /*#1, below*/);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "dir/b", "--cwd", repo.getLocation());
+		report("log dir/b", cmd.file("dir/b", false).execute(), true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-f", "dir/b", "--cwd", repo.getLocation());
+		report("log -f dir/b", cmd.file("dir/b", true).execute(), false /*#1, below*/);
+		/*
+		 * #1: false works because presently commands dispatches history of the queried file, and then history
+		 * of it's origin. With history comprising of renames only, this effectively gives reversed (newest to oldest) 
+		 * order of revisions. 
+		 */
+	}
+
+	@Test
+	public void testUsernames() throws Exception {
+		repo = Configuration.get().find("log-users");
+		final String user1 = "User One <user1@example.org>";
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-u", user1, "--cwd", repo.getLocation());
+		report("log -u " + user1, new HgLogCommand(repo).user(user1).execute(), true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-u", "user1", "-u", "user2", "--cwd", repo.getLocation());
+		report("log -u user1 -u user2", new HgLogCommand(repo).user("user1").user("user2").execute(), true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-u", "user3", "--cwd", repo.getLocation());
+		report("log -u user3", new HgLogCommand(repo).user("user3").execute(), true);
+	}
+
+	@Test
+	public void testBranches() throws Exception {
+		repo = Configuration.get().find("log-branches");
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-b", "default", "--cwd", repo.getLocation());
+		report("log -b default" , new HgLogCommand(repo).branch("default").execute(), true);
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-b", "test", "--cwd", repo.getLocation());
+		report("log -b test" , new HgLogCommand(repo).branch("test").execute(), true);
+		//
+		assertTrue("log -b dummy shall yeild empty result", new HgLogCommand(repo).branch("dummy").execute().isEmpty());
+		//
+		changelogParser.reset();
+		eh.run("hg", "log", "--debug", "-b", "default", "-b", "test", "--cwd", repo.getLocation());
+		report("log -b default -b test" , new HgLogCommand(repo).branch("default").branch("test").execute(), true);
+	}
 }
--- a/test/org/tmatesoft/hg/test/TestStatus.java	Fri Feb 18 05:20:18 2011 +0100
+++ b/test/org/tmatesoft/hg/test/TestStatus.java	Tue Feb 22 15:49:26 2011 +0100
@@ -159,6 +159,10 @@
 	 * 'hg status -A': Native client total 953 (95 per run), Java client 94 (9)
 	 * 'hg status -A --rev 3:80': Native client total 1828 (182 per run), Java client 235 (23)
 	 * 'hg log --debug', 10 runs: Native client total 1766 (176 per run), Java client 78 (7)
+	 * 
+	 * 18.02.2011
+	 * 'hg status -A --rev 3:80', 10 runs:  Native client total 2000 (200 per run), Java client 250 (25)
+	 * 'hg log --debug', 10 runs: Native client total 2297 (229 per run), Java client 125 (12)
 	 */
 	public void testPerformance() throws Exception {
 		final int runs = 10;