comparison test/org/tmatesoft/hg/test/TestHistory.java @ 70:993f6f8e1314

Test for log command
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 23 Jan 2011 03:28:52 +0100
parents
children 6f1b88693d48
comparison
equal deleted inserted replaced
69:5a69397f0f99 70:993f6f8e1314
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@svnkit.com
16 */
17 package org.tmatesoft.hg.test;
18
19 import java.util.Collections;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.tmatesoft.hg.core.Cset;
24 import org.tmatesoft.hg.core.LogCommand;
25 import org.tmatesoft.hg.test.LogOutputParser.Record;
26
27 import com.tmate.hgkit.fs.RepositoryLookup;
28 import com.tmate.hgkit.ll.HgRepository;
29
30 /**
31 *
32 * @author Artem Tikhomirov
33 * @author TMate Software Ltd.
34 */
35 public class TestHistory {
36
37 private final HgRepository repo;
38 private ExecHelper eh;
39 private LogOutputParser changelogParser;
40
41 public static void main(String[] args) throws Exception {
42 TestHistory th = new TestHistory(new RepositoryLookup().detectFromWorkingDir());
43 th.testCompleteLog();
44 }
45
46 public TestHistory(HgRepository hgRepo) {
47 repo = hgRepo;
48 eh = new ExecHelper(changelogParser = new LogOutputParser(true), null);
49 }
50
51 public void testCompleteLog() throws Exception {
52 changelogParser.reset();
53 eh.run("hg", "log", "--debug");
54 List<Cset> r = new LogCommand(repo).execute();
55 report("hg log", r);
56 }
57
58 private void report(String what, List<Cset> r) {
59 final List<Record> consoleResult = changelogParser.getResult();
60 Collections.reverse(consoleResult);
61 Iterator<LogOutputParser.Record> consoleResultItr = consoleResult.iterator();
62 boolean hasErrors = false;
63 for (Cset cs : r) {
64 LogOutputParser.Record cr = consoleResultItr.next();
65 int x = cs.getRevision() == cr.changesetIndex ? 0x1 : 0;
66 x |= cs.getDate().equals(cr.date) ? 0x2 : 0;
67 x |= cs.getNodeid().toString().equals(cr.changesetNodeid) ? 0x4 : 0;
68 x |= cs.getUser().equals(cr.user) ? 0x8 : 0;
69 x |= cs.getComment().equals(cr.description) ? 0x10 : 0;
70 if (x != 0x1f) {
71 System.err.printf("Error in %d (%d):0%o\n", cs.getRevision(), cr.changesetIndex, x);
72 hasErrors = true;
73 }
74 consoleResultItr.remove();
75 }
76 if (consoleResultItr.hasNext()) {
77 System.out.println("Insufficient results from Java");
78 hasErrors = true;
79 }
80 System.out.println(what + (hasErrors ? " FAIL" : " OK"));
81 }
82 }