tikhomirov@61: /* tikhomirov@61: * Copyright (c) 2011 Artem Tikhomirov tikhomirov@61: */ tikhomirov@61: package com.tmate.hgkit; tikhomirov@61: tikhomirov@61: import java.io.File; tikhomirov@61: import java.util.Collection; tikhomirov@61: import java.util.LinkedList; tikhomirov@61: import java.util.List; tikhomirov@61: tikhomirov@61: import com.tmate.hgkit.fs.FileWalker; tikhomirov@61: import com.tmate.hgkit.fs.RepositoryLookup; tikhomirov@61: import com.tmate.hgkit.ll.HgRepository; tikhomirov@61: import com.tmate.hgkit.ll.StatusCollector; tikhomirov@61: import com.tmate.hgkit.ll.WorkingCopyStatusCollector; tikhomirov@61: tikhomirov@61: /** tikhomirov@61: * tikhomirov@61: * @author artem tikhomirov@61: */ tikhomirov@61: public class TestStatus { tikhomirov@61: tikhomirov@61: public static void main(String[] args) throws Exception { tikhomirov@61: final StatusOutputParser statusParser = new StatusOutputParser(); tikhomirov@61: ExecHelper eh = new ExecHelper(statusParser, null); tikhomirov@61: eh.run("hg", "status", "-A"); tikhomirov@61: // run java equivalent tikhomirov@61: HgRepository repo = new RepositoryLookup().detectFromWorkingDir(); tikhomirov@61: final WorkingCopyStatusCollector wcc = new WorkingCopyStatusCollector(repo, new FileWalker(new File(System.getProperty("user.dir")))); tikhomirov@61: StatusCollector.Record r = wcc.status(HgRepository.TIP); tikhomirov@61: // compare result tikhomirov@61: reportNotEqual("MODIFIED", r.getModified(), statusParser.getModified()); tikhomirov@61: reportNotEqual("ADDED", r.getAdded(), statusParser.getAdded()); tikhomirov@61: reportNotEqual("REMOVED", r.getRemoved(), statusParser.getRemoved()); tikhomirov@61: reportNotEqual("CLEAN", r.getClean(), statusParser.getClean()); tikhomirov@61: reportNotEqual("IGNORED", r.getIgnored(), statusParser.getIgnored()); tikhomirov@61: reportNotEqual("MISSING", r.getMissing(), statusParser.getMissing()); tikhomirov@61: reportNotEqual("UNKNOWN", r.getUnknown(), statusParser.getUnknown()); tikhomirov@61: // TODO compare equals tikhomirov@61: } tikhomirov@61: tikhomirov@61: private static void reportNotEqual(String what, Collection l1, Collection l2) { tikhomirov@61: List diff = difference(l1, l2); tikhomirov@61: System.out.print(what); tikhomirov@61: if (!diff.isEmpty()) { tikhomirov@61: System.out.print(" are NOT the same: "); tikhomirov@61: for (T t : diff) { tikhomirov@61: System.out.print(t); tikhomirov@61: System.out.print(", "); tikhomirov@61: } tikhomirov@61: System.out.println(); tikhomirov@61: } else { tikhomirov@61: System.out.println(" are the same"); tikhomirov@61: } tikhomirov@61: } tikhomirov@61: tikhomirov@61: private static List difference(Collection l1, Collection l2) { tikhomirov@61: LinkedList result = new LinkedList(l2); tikhomirov@61: for (T t : l1) { tikhomirov@61: if (l2.contains(t)) { tikhomirov@61: result.remove(t); tikhomirov@61: } else { tikhomirov@61: result.add(t); tikhomirov@61: } tikhomirov@61: } tikhomirov@61: return result; tikhomirov@61: } tikhomirov@61: }