Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestBlame.java @ 625:b4948b159ab1
Refactor internals of blame support, tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 21 May 2013 17:24:22 +0200 |
parents | 507602cb4fb3 |
children | 6526d8adbc0f |
comparison
equal
deleted
inserted
replaced
624:507602cb4fb3 | 625:b4948b159ab1 |
---|---|
43 import org.tmatesoft.hg.core.HgAnnotateCommand; | 43 import org.tmatesoft.hg.core.HgAnnotateCommand; |
44 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo; | 44 import org.tmatesoft.hg.core.HgAnnotateCommand.LineInfo; |
45 import org.tmatesoft.hg.core.HgCallbackTargetException; | 45 import org.tmatesoft.hg.core.HgCallbackTargetException; |
46 import org.tmatesoft.hg.core.HgIterateDirection; | 46 import org.tmatesoft.hg.core.HgIterateDirection; |
47 import org.tmatesoft.hg.core.HgRepoFacade; | 47 import org.tmatesoft.hg.core.HgRepoFacade; |
48 import org.tmatesoft.hg.core.Nodeid; | |
48 import org.tmatesoft.hg.internal.FileAnnotation; | 49 import org.tmatesoft.hg.internal.FileAnnotation; |
49 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor; | 50 import org.tmatesoft.hg.internal.FileAnnotation.LineDescriptor; |
50 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; | 51 import org.tmatesoft.hg.internal.FileAnnotation.LineInspector; |
51 import org.tmatesoft.hg.internal.IntVector; | 52 import org.tmatesoft.hg.internal.IntVector; |
52 import org.tmatesoft.hg.repo.HgBlameInspector; | 53 import org.tmatesoft.hg.repo.HgBlameInspector; |
53 import org.tmatesoft.hg.repo.HgBlameInspector.BlockData; | 54 import org.tmatesoft.hg.repo.HgBlameInspector.BlockData; |
55 import org.tmatesoft.hg.repo.HgChangelog; | |
54 import org.tmatesoft.hg.repo.HgDataFile; | 56 import org.tmatesoft.hg.repo.HgDataFile; |
55 import org.tmatesoft.hg.repo.HgLookup; | 57 import org.tmatesoft.hg.repo.HgLookup; |
56 import org.tmatesoft.hg.repo.HgRepository; | 58 import org.tmatesoft.hg.repo.HgRepository; |
57 import org.tmatesoft.hg.util.Path; | 59 import org.tmatesoft.hg.util.Path; |
58 | 60 |
69 | 71 |
70 @Test | 72 @Test |
71 public void testSingleParentBlame() throws Exception { | 73 public void testSingleParentBlame() throws Exception { |
72 HgRepository repo = new HgLookup().detectFromWorkingDir(); | 74 HgRepository repo = new HgLookup().detectFromWorkingDir(); |
73 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | 75 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; |
74 final int checkChangeset = 539; | 76 final int checkChangeset = repo.getChangelog().getRevisionIndex(Nodeid.fromAscii("946b131962521f9199e1fedbdc2487d3aaef5e46")); // 539 |
75 HgDataFile df = repo.getFileNode(fname); | 77 HgDataFile df = repo.getFileNode(fname); |
76 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | 78 ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
77 df.annotateSingleRevision(checkChangeset, new DiffOutInspector(new PrintStream(bos))); | 79 df.annotateSingleRevision(checkChangeset, new DiffOutInspector(new PrintStream(bos))); |
78 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); | 80 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); |
79 ExecHelper eh = new ExecHelper(gp, null); | 81 ExecHelper eh = new ExecHelper(gp, null); |
89 HgRepository repo = new HgLookup().detectFromWorkingDir(); | 91 HgRepository repo = new HgLookup().detectFromWorkingDir(); |
90 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | 92 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; |
91 HgDataFile df = repo.getFileNode(fname); | 93 HgDataFile df = repo.getFileNode(fname); |
92 AnnotateRunner ar = new AnnotateRunner(df.getPath(), null); | 94 AnnotateRunner ar = new AnnotateRunner(df.getPath(), null); |
93 | 95 |
94 for (int cs : new int[] { 539, 541 /*, TIP */}) { | 96 final HgChangelog clog = repo.getChangelog(); |
97 final int[] toTest = new int[] { | |
98 clog.getRevisionIndex(Nodeid.fromAscii("946b131962521f9199e1fedbdc2487d3aaef5e46")), // 539 | |
99 clog.getRevisionIndex(Nodeid.fromAscii("1e95f48d9886abe79b9711ab371bc877ca5e773e")), // 541 | |
100 /*, TIP */}; | |
101 for (int cs : toTest) { | |
95 ar.run(cs, false); | 102 ar.run(cs, false); |
96 FileAnnotateInspector fa = new FileAnnotateInspector(); | 103 FileAnnotateInspector fa = new FileAnnotateInspector(); |
97 FileAnnotation.annotate(df, cs, fa); | 104 FileAnnotation.annotate(df, cs, fa); |
98 doAnnotateLineCheck(cs, ar.getLines(), Arrays.asList(fa.lineRevisions), Arrays.asList(fa.lines)); | 105 doAnnotateLineCheck(cs, ar.getLines(), Arrays.asList(fa.lineRevisions), Arrays.asList(fa.lines)); |
99 } | 106 } |
252 String hgAnnotateLine = hgAnnotateLines[i].substring(hgAnnotateLines[i].indexOf(':') + 1); | 259 String hgAnnotateLine = hgAnnotateLines[i].substring(hgAnnotateLines[i].indexOf(':') + 1); |
253 String apiLine = cmdLines.get(i).trim(); | 260 String apiLine = cmdLines.get(i).trim(); |
254 errorCollector.assertEquals(hgAnnotateLine.trim(), apiLine); | 261 errorCollector.assertEquals(hgAnnotateLine.trim(), apiLine); |
255 } | 262 } |
256 } | 263 } |
264 | |
265 | |
266 @Test | |
267 public void testDiffTwoRevisions() throws Exception { | |
268 HgRepository repo = Configuration.get().find("test-annotate"); | |
269 HgDataFile df = repo.getFileNode("file1"); | |
270 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); | |
271 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir()); | |
272 int[] toTest = { 3, 4, 5 }; // p1 ancestry line, p2 ancestry line, not in ancestry line | |
273 for (int cs : toTest) { | |
274 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
275 df.diff(cs, 8, new DiffOutInspector(new PrintStream(bos))); | |
276 eh.run("hg", "diff", "-r", String.valueOf(cs), "-r", "8", "-U", "0", df.getPath().toString()); | |
277 // | |
278 String[] apiResult = splitLines(bos.toString()); | |
279 String[] expected = splitLines(gp.result()); | |
280 Assert.assertArrayEquals(expected, apiResult); | |
281 gp.reset(); | |
282 } | |
283 } | |
284 | |
285 /** | |
286 * Make sure boundary values are ok (down to BlameHelper#prepare and FileHistory) | |
287 */ | |
288 @Test | |
289 public void testAnnotateFirstFileRev() throws Exception { | |
290 HgRepository repo = Configuration.get().find("test-annotate"); | |
291 HgDataFile df = repo.getFileNode("file1"); | |
292 LineGrepOutputParser gp = new LineGrepOutputParser("^@@.+"); | |
293 ExecHelper eh = new ExecHelper(gp, repo.getWorkingDir()); | |
294 eh.run("hg", "diff", "-c", "0", "-U", "0", df.getPath().toString()); | |
295 // | |
296 ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
297 df.annotateSingleRevision(0, new DiffOutInspector(new PrintStream(bos))); | |
298 // | |
299 String[] apiResult = splitLines(bos.toString()); | |
300 String[] expected = splitLines(gp.result()); | |
301 Assert.assertArrayEquals(expected, apiResult); | |
302 } | |
257 | 303 |
258 // TODO HgWorkingCopyStatusCollector (and HgStatusCollector), with their ancestors (rev 59/69) have examples | 304 // TODO HgWorkingCopyStatusCollector (and HgStatusCollector), with their ancestors (rev 59/69) have examples |
259 // of *incorrect* assignment of common lines (like "}") - our impl doesn't process common lines in any special way | 305 // of *incorrect* assignment of common lines (like "}") - our impl doesn't process common lines in any special way |
260 // while original diff lib does. Would be nice to behave as close to original, as possible. | 306 // while original diff lib does. Would be nice to behave as close to original, as possible. |
261 | 307 |
282 } while (lineStart < seq.length()); | 328 } while (lineStart < seq.length()); |
283 assert ix == lineCount; | 329 assert ix == lineCount; |
284 return rv; | 330 return rv; |
285 } | 331 } |
286 | 332 |
287 | |
288 private void aaa() throws Exception { | |
289 HgRepository repo = new HgLookup().detectFromWorkingDir(); | |
290 final String fname = "src/org/tmatesoft/hg/internal/PatchGenerator.java"; | |
291 final int checkChangeset = 539; | |
292 HgDataFile df = repo.getFileNode(fname); | |
293 DiffOutInspector dump = new DiffOutInspector(System.out); | |
294 System.out.println("541 -> 543"); | |
295 df.annotateSingleRevision(543, dump); | |
296 System.out.println("539 -> 541"); | |
297 df.annotateSingleRevision(541, dump); | |
298 System.out.println("536 -> 539"); | |
299 df.annotateSingleRevision(checkChangeset, dump); | |
300 System.out.println("531 -> 536"); | |
301 df.annotateSingleRevision(536, dump); | |
302 System.out.println(" -1 -> 531"); | |
303 df.annotateSingleRevision(531, dump); | |
304 | |
305 FileAnnotateInspector fai = new FileAnnotateInspector(); | |
306 FileAnnotation.annotate(df, 541, fai); | |
307 for (int i = 0; i < fai.lineRevisions.length; i++) { | |
308 System.out.printf("%3d: LINE %d\n", fai.lineRevisions[i], i+1); | |
309 } | |
310 } | |
311 | |
312 private void bbb() throws Exception { | |
313 HgRepository repo = new HgLookup().detectFromWorkingDir(); | |
314 final String fname = "src/org/tmatesoft/hg/repo/HgManifest.java"; | |
315 final int checkChangeset = 415; | |
316 HgDataFile df = repo.getFileNode(fname); | |
317 DiffOutInspector dump = new DiffOutInspector(System.out); | |
318 // System.out.println("413 -> 415"); | |
319 // af.diff(df, 413, 415, dump); | |
320 // System.out.println("408 -> 415"); | |
321 // af.diff(df, 408, 415, dump); | |
322 // System.out.println("Combined (with merge):"); | |
323 // dump.needRevisions(true); | |
324 // af.annotateChange(df, checkChangeset, dump); | |
325 dump.needRevisions(true); | |
326 df.annotate(checkChangeset, dump, HgIterateDirection.OldToNew); | |
327 } | |
328 | 333 |
329 private void ccc() throws Throwable { | 334 private void ccc() throws Throwable { |
330 HgRepository repo = new HgLookup().detect("/home/artem/hg/hgtest-annotate-merge/"); | 335 HgRepository repo = new HgLookup().detect("/home/artem/hg/hgtest-annotate-merge/"); |
331 HgDataFile df = repo.getFileNode("file.txt"); | 336 HgDataFile df = repo.getFileNode("file.txt"); |
332 DiffOutInspector dump = new DiffOutInspector(System.out); | 337 DiffOutInspector dump = new DiffOutInspector(System.out); |
352 System.out.printf("%d: %s", fa.lineRevisions[i], fa.line(i) == null ? "null\n" : fa.line(i)); | 357 System.out.printf("%d: %s", fa.lineRevisions[i], fa.line(i) == null ? "null\n" : fa.line(i)); |
353 } | 358 } |
354 } | 359 } |
355 | 360 |
356 public static void main(String[] args) throws Throwable { | 361 public static void main(String[] args) throws Throwable { |
357 // System.out.println(Arrays.equals(new String[0], splitLines(""))); | |
358 // System.out.println(Arrays.equals(new String[] { "abc" }, splitLines("abc"))); | |
359 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc"))); | |
360 // System.out.println(Arrays.equals(new String[] { "a", "bc" }, splitLines("a\nbc\n"))); | |
361 TestBlame tt = new TestBlame(); | 362 TestBlame tt = new TestBlame(); |
362 tt.ccc(); | 363 tt.ccc(); |
363 } | 364 } |
364 | 365 |
365 private static class DiffOutInspector implements HgBlameInspector { | 366 private static class DiffOutInspector implements HgBlameInspector { |