Mercurial > hg4j
changeset 477:9c9d09111aee
Tests for file flags(exec, link, regular)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 12 Jul 2012 18:07:51 +0200 |
parents | c02b5710d9ac |
children | e74580e24feb |
files | build.xml cmdline/org/tmatesoft/hg/console/Main.java test-data/test-repos.jar test/org/tmatesoft/hg/test/ErrorCollectorExt.java test/org/tmatesoft/hg/test/TestFileFlags.java test/org/tmatesoft/hg/test/TestPhases.java |
diffstat | 6 files changed, 138 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/build.xml Thu Jul 12 18:07:12 2012 +0200 +++ b/build.xml Thu Jul 12 18:07:51 2012 +0200 @@ -97,6 +97,8 @@ <test name="org.tmatesoft.hg.test.TestIncoming" /> <test name="org.tmatesoft.hg.test.TestOutgoing" /> <test name="org.tmatesoft.hg.test.TestPhases" /> + <test name="org.tmatesoft.hg.test.TestMqExtension" /> + <test name="org.tmatesoft.hg.test.TestFileFlags" /> </junit> </target>
--- a/cmdline/org/tmatesoft/hg/console/Main.java Thu Jul 12 18:07:12 2012 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Thu Jul 12 18:07:51 2012 +0200 @@ -107,7 +107,6 @@ Main m = new Main(args); // m.checkWalkFileRevisions(); // m.checkSubProgress(); -// m.checkFileFlags(); // m.buildFileLog(); // m.testConsoleLog(); // m.testTreeTraversal(); @@ -172,20 +171,6 @@ s2.done(); } - private void checkFileFlags() throws Exception { - // ~/hg/test-flags repo - // TODO transform to a test once I keep test-flags in test-repos.jar - // JAR can't keep symlinks. Perhaps, a solution would be to keep repo without WC and - // perform an `hg up` before use - HgDataFile link = hgRepo.getFileNode("file-link"); - HgDataFile exec = hgRepo.getFileNode("file-exec"); - HgDataFile file = hgRepo.getFileNode("regular-file"); - System.out.println("Link: " + link.getFlags(TIP)); - System.out.println("Exec: " + exec.getFlags(TIP)); - System.out.println("File: " + file.getFlags(TIP)); - } - - private void buildFileLog() throws Exception { final long start = System.nanoTime(); HgLogCommand cmd = new HgLogCommand(hgRepo);
--- a/test/org/tmatesoft/hg/test/ErrorCollectorExt.java Thu Jul 12 18:07:12 2012 +0200 +++ b/test/org/tmatesoft/hg/test/ErrorCollectorExt.java Thu Jul 12 18:07:51 2012 +0200 @@ -52,6 +52,10 @@ }); } + public void assertFalse(final boolean value) { + assertTrue(!value); + } + public void assertTrue(final boolean value) { assertTrue(null, value); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/TestFileFlags.java Thu Jul 12 18:07:51 2012 +0200 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2012 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 static org.tmatesoft.hg.repo.HgRepository.TIP; + +import java.io.File; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.RelativePathRewrite; +import org.tmatesoft.hg.repo.HgDataFile; +import org.tmatesoft.hg.repo.HgInternals; +import org.tmatesoft.hg.repo.HgManifest.Flags; +import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.FileInfo; +import org.tmatesoft.hg.util.FileWalker; +import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.PathRewrite; + +/** + * {junit-test-repos}/test-flags/ + * + * <p>Node, JAR can't keep symlinks. Solution would be to keep + * repo without WC and perform an `hg co -C` before use if we + * need files from working copy. + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class TestFileFlags { + @Rule + public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); + + private HgRepository repo; + + @Test + public void testFlagsInManifest() { + HgDataFile link = repo.getFileNode("file-link"); + HgDataFile exec = repo.getFileNode("file-exec"); + HgDataFile file = repo.getFileNode("regular-file"); + assertEquals(Flags.Link, link.getFlags(TIP)); + assertEquals(Flags.Exec, exec.getFlags(TIP)); + assertEquals(Flags.RegularFile, file.getFlags(TIP)); + } + + @Test + public void testFlagsInWorkingCopy() throws Exception { + File repoRoot = repo.getWorkingDir(); + Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(repoRoot), repo.getToRepoPathHelper())); + FileWalker fw = new FileWalker(HgInternals.getContext(repo), repoRoot, pathSrc); + + if (Internals.runningOnWindows()) { + System.out.println("Executing tests on Windows, no actual file flags in working area are checked"); + assertFalse(fw.supportsExecFlag()); + assertFalse(fw.supportsLinkFlag()); + return; + } else { + assertTrue(fw.supportsExecFlag()); + assertTrue(fw.supportsLinkFlag()); + } + ExecHelper eh = new ExecHelper(new OutputParser.Stub(true), repo.getWorkingDir()); + eh.run("hg", "checkout", "-C"); + + boolean exec, link, file; + exec = link = file = false; + while (fw.hasNext()) { + fw.next(); + FileInfo fi = fw.file(); + String fn = fw.name().toString(); + if (fn.equals("file-link")) { + link = true; + errorCollector.assertTrue("Symlink shall exist despite the fact it points to nowhere", fi.exists()); + errorCollector.assertFalse(fi.isExecutable()); + errorCollector.assertTrue(fi.isSymlink()); + } else if (fn.equals("file-exec")) { + exec = true; + errorCollector.assertTrue(fi.isExecutable()); + errorCollector.assertFalse(fi.isSymlink()); + } else if (fn.equals("regular-file")) { + file = true; + errorCollector.assertFalse(fi.isExecutable()); + errorCollector.assertFalse(fi.isSymlink()); + } + } + errorCollector.assertTrue("Missing executable file in WC", exec); + errorCollector.assertTrue("Missing symlink in WC", link); + errorCollector.assertTrue("Missing regular file in WC", file); + } + + @Before + public void assignRepo() throws Exception { + repo = Configuration.get().find("test-flags"); + } + + @After + public void cleanFiles() { + File link = new File(repo.getWorkingDir(), "file-link"); + File exec = new File(repo.getWorkingDir(), "file-exec"); + File file = new File(repo.getWorkingDir(), "regular-file"); + if (link.exists()) { + link.deleteOnExit(); + } + if (exec.exists()) { + exec.deleteOnExit(); + } + if (file.exists()) { + file.deleteOnExit(); + } + } +}
--- a/test/org/tmatesoft/hg/test/TestPhases.java Thu Jul 12 18:07:12 2012 +0200 +++ b/test/org/tmatesoft/hg/test/TestPhases.java Thu Jul 12 18:07:51 2012 +0200 @@ -48,7 +48,8 @@ PhasesHelper ph = new PhasesHelper(repo, null); initAndCheck(ph, expected); final long end = System.nanoTime(); - System.out.printf("Without ParentWalker (simulates log command for single file): %d ms\n", (end - start)/1000); + // μ == \u03bc + System.out.printf("Without ParentWalker (simulates log command for single file): %,d μs\n", (end - start)/1000); } @Test @@ -62,7 +63,7 @@ PhasesHelper ph = new PhasesHelper(repo, pw); initAndCheck(ph, expected); final long end = System.nanoTime(); - System.out.printf("With ParentWalker(simulates log command for whole repo): %d ms (pw init: %,d ns)\n", (end - start1)/1000, start2 - start1); + System.out.printf("With ParentWalker(simulates log command for whole repo): %,d μs (pw init: %,d ns)\n", (end - start1)/1000, start2 - start1); } private HgPhase[] initAndCheck(PhasesHelper ph, HgPhase[] expected) {