# HG changeset patch # User Artem Tikhomirov # Date 1295925282 -3600 # Node ID 7255c971dd66316c384b9f8c3020eaae1aaf4a49 # Parent 4222b04f34ee885bc1ad547c7ef330e18a51afc1 Promitive test for follow file history diff -r 4222b04f34ee -r 7255c971dd66 test/org/tmatesoft/hg/test/TestHistory.java --- a/test/org/tmatesoft/hg/test/TestHistory.java Tue Jan 25 03:54:32 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestHistory.java Tue Jan 25 04:14:42 2011 +0100 @@ -22,6 +22,10 @@ import org.tmatesoft.hg.core.Cset; import org.tmatesoft.hg.core.LogCommand; +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.HgRepository; import org.tmatesoft.hg.repo.Lookup; import org.tmatesoft.hg.test.LogOutputParser.Record; @@ -41,6 +45,7 @@ public static void main(String[] args) throws Exception { TestHistory th = new TestHistory(new Lookup().detectFromWorkingDir()); th.testCompleteLog(); + th.testFollowHistory(); } public TestHistory(HgRepository hgRepo) { @@ -52,12 +57,40 @@ changelogParser.reset(); eh.run("hg", "log", "--debug"); List r = new LogCommand(repo).execute(); - report("hg log", r); + report("hg log - COMPLETE REPO HISTORY", r, true); + } + + public void testFollowHistory() throws Exception { + final Path f = Path.create("cmdline/org/tmatesoft/hg/console/Remote.java"); + try { + if (repo.getFileNode(f).exists()) { // FIXME getFileNode shall not fail with IAE + changelogParser.reset(); + eh.run("hg", "log", "--debug", "--follow", f.toString()); + + class H extends CollectHandler implements FileHistoryHandler { + boolean copyReported = false; + boolean fromMatched = false; + public void copy(FileRevision from, FileRevision to) { + copyReported = true; + fromMatched = "src/com/tmate/hgkit/console/Remote.java".equals(from.getPath().toString()); + } + }; + H h = new H(); + new LogCommand(repo).file(f, true).execute(h); + System.out.print("hg log - FOLLOW FILE HISTORY"); + System.out.println("\tcopyReported:" + h.copyReported + ", and was " + (h.fromMatched ? "CORRECT" : "WRONG")); + report("hg log - FOLLOW FILE HISTORY", h.getChanges(), false); + } + } catch (IllegalArgumentException ex) { + System.out.println("Can't test file history with follow because need to query specific file with history"); + } } - private void report(String what, List r) { + private void report(String what, List r, boolean reverseConsoleResults) { final List consoleResult = changelogParser.getResult(); - Collections.reverse(consoleResult); + if (reverseConsoleResults) { + Collections.reverse(consoleResult); + } Iterator consoleResultItr = consoleResult.iterator(); boolean hasErrors = false; for (Cset cs : r) {