Mercurial > jhg
changeset 623:fedc54356091
Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 20 May 2013 18:35:13 +0200 |
parents | 4e6179bde4fc |
children | 507602cb4fb3 |
files | src/org/tmatesoft/hg/util/Path.java test/org/tmatesoft/hg/test/Configuration.java test/org/tmatesoft/hg/test/RepoUtils.java test/org/tmatesoft/hg/test/TestCheckout.java test/org/tmatesoft/hg/test/TestCommit.java test/org/tmatesoft/hg/test/TestPhases.java |
diffstat | 6 files changed, 81 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/Path.java Mon May 20 16:56:40 2013 +0200 +++ b/src/org/tmatesoft/hg/util/Path.java Mon May 20 18:35:13 2013 +0200 @@ -159,7 +159,7 @@ } String p = path.toString(); if (p.indexOf('\\') != -1) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(String.format("Path '%s' contains illegal char at %d", p, p.indexOf('\\'))); } Path rv = new Path(p); return rv;
--- a/test/org/tmatesoft/hg/test/Configuration.java Mon May 20 16:56:40 2013 +0200 +++ b/test/org/tmatesoft/hg/test/Configuration.java Mon May 20 18:35:13 2013 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2012 TMate Software Ltd + * Copyright (c) 2011-2013 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 @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.List; +import org.tmatesoft.hg.core.HgException; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRemoteRepository; import org.tmatesoft.hg.repo.HgRepository; @@ -67,7 +68,7 @@ } // fails if repo not found - public HgRepository find(String key) throws Exception { + public HgRepository find(String key) throws HgException { HgRepository rv = lookup.detect(new File(getRoot(), key)); assertNotNull(rv); assertFalse(rv.isInvalid());
--- a/test/org/tmatesoft/hg/test/RepoUtils.java Mon May 20 16:56:40 2013 +0200 +++ b/test/org/tmatesoft/hg/test/RepoUtils.java Mon May 20 18:35:13 2013 +0200 @@ -19,15 +19,22 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.tmatesoft.hg.internal.RequiresFile.*; +import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import org.tmatesoft.hg.core.HgException; import org.tmatesoft.hg.core.HgIOException; +import org.tmatesoft.hg.internal.FileUtils; import org.tmatesoft.hg.internal.RepoInitializer; +import org.tmatesoft.hg.internal.StreamLogFacility; import org.tmatesoft.hg.repo.HgRepository; /** @@ -54,7 +61,7 @@ return dest; } - static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws Exception, InterruptedException { + static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws HgException, IOException, InterruptedException { return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate); } @@ -73,6 +80,45 @@ assertEquals("[sanity]", 0, eh.getExitValue()); return testRepoLoc; } + + static File copyRepoToTempLocation(String configRepoName, String newRepoName) throws HgException, IOException { + File testRepoLoc = createEmptyDir(newRepoName); + final File srcDir = Configuration.get().find(configRepoName).getWorkingDir(); + Iterator<File> it = new Iterator<File>() { + private final LinkedList<File> queue = new LinkedList<File>(); + { + queue.addAll(Arrays.asList(srcDir.listFiles())); + } + public boolean hasNext() { + return !queue.isEmpty(); + } + public File next() { + File n = queue.removeFirst(); + if (n.isDirectory()) { + queue.addAll(Arrays.asList(n.listFiles())); + } + return n; + } + public void remove() { + throw new UnsupportedOperationException(); + } + }; + FileUtils fu = new FileUtils(new StreamLogFacility(Debug, true, System.err)); + String srcPrefix = srcDir.getAbsolutePath(); + while (it.hasNext()) { + File next = it.next(); + assert next.getAbsolutePath().startsWith(srcPrefix); + String relPath = next.getAbsolutePath().substring(srcPrefix.length()); + File dest = new File(testRepoLoc, relPath); + if (next.isDirectory()) { + dest.mkdir(); + } else { + fu.copy(next, dest); + dest.setLastModified(next.lastModified()); + } + } + return testRepoLoc; + } static void modifyFileAppend(File f, Object content) throws IOException { assertTrue(f.isFile());
--- a/test/org/tmatesoft/hg/test/TestCheckout.java Mon May 20 16:56:40 2013 +0200 +++ b/test/org/tmatesoft/hg/test/TestCheckout.java Mon May 20 18:35:13 2013 +0200 @@ -28,12 +28,15 @@ import org.junit.Test; import org.tmatesoft.hg.core.HgCheckoutCommand; import org.tmatesoft.hg.core.Nodeid; +import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.internal.RelativePathRewrite; import org.tmatesoft.hg.repo.HgLookup; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.FileInfo; import org.tmatesoft.hg.util.FileWalker; import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; +import org.tmatesoft.hg.util.PathRewrite; /** * @@ -123,8 +126,9 @@ File testRepoLoc = cloneRepoToTempLocation("test-flags", "test-checkout-flags", true); repo = new HgLookup().detect(testRepoLoc); new HgCheckoutCommand(repo).clean(true).changeset(0).execute(); - - FileWalker fw = new FileWalker(repo, testRepoLoc, new Path.SimpleSource(), null); + + Path.Source pathSrc = new Path.SimpleSource(new PathRewrite.Composite(new RelativePathRewrite(testRepoLoc), repo.getToRepoPathHelper())); + FileWalker fw = new FileWalker(repo, testRepoLoc, pathSrc, null); int execFound, linkFound, regularFound; execFound = linkFound = regularFound = 0; while(fw.hasNext()) { @@ -142,10 +146,16 @@ regularFound++; } } - // TODO alter expected values to pass on Windows - errorCollector.assertEquals("Executable files", 1, execFound); - errorCollector.assertEquals("Symlink files", 1, linkFound); - errorCollector.assertEquals("Regular files", 1, regularFound); + final int expectedExec, expectedLink, expectedRegular; + if (Internals.runningOnWindows()) { + expectedExec = expectedLink = 0; + expectedRegular = 2; + } else { + expectedExec = expectedLink = expectedRegular = 1; + } + errorCollector.assertEquals("Executable files", expectedExec, execFound); + errorCollector.assertEquals("Symlink files", expectedLink, linkFound); + errorCollector.assertEquals("Regular files", expectedRegular, regularFound); } private static final class FilesOnlyFilter implements FileFilter {
--- a/test/org/tmatesoft/hg/test/TestCommit.java Mon May 20 16:56:40 2013 +0200 +++ b/test/org/tmatesoft/hg/test/TestCommit.java Mon May 20 18:35:13 2013 +0200 @@ -380,7 +380,19 @@ @Test public void testRollback() throws Exception { - File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-rollback", false); + // Important: copy, not a clone of a repo to ensure old timestamps + // on repository files. Otherwise, there're chances transacition.rollback() + // would happen the very second (when fs timestamp granularity is second) + // repository got cloned, and RevlogChangeMonitor won't notice the file change + // (timestamp is the same, file size increased (CommitFacility) and decreased + // on rollback back to memorized value), and subsequent hgRepo access would fail + // trying to read more (due to Revlog#revisionAdded) revisions than there are in + // the store file. + // With copy and original timestamps we pretend commit happens to an existing repository + // in a regular manner (it's unlikely to have commits within the same second in a real life) + // XXX Note, once we have more robust method to detect file changes (e.g. Java7), this + // approach shall be abandoned. + File repoLoc = RepoUtils.copyRepoToTempLocation("log-1", "test-commit-rollback"); final Path newFilePath = Path.create("xx"); final File newFile = new File(repoLoc, newFilePath.toString()); RepoUtils.createFile(newFile, "xyz"); @@ -411,11 +423,6 @@ cf.branch("another-branch"); Transaction tr = newTransaction(hgRepo); Nodeid commitRev = cf.commit("Commit to fail", tr); - // with 1 second timestamp granularity, HgChangelog doesn't - // recognize the fact the underlying file got changed twice within - // a second, doesn't discard new revision obtained via revisionAdded, - // and eventually fails trying to read more revisions than there're in the file - Thread.sleep(1000); // FIXME this is a hack to make test pass tr.rollback(); // errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());
--- a/test/org/tmatesoft/hg/test/TestPhases.java Mon May 20 16:56:40 2013 +0200 +++ b/test/org/tmatesoft/hg/test/TestPhases.java Mon May 20 18:35:13 2013 +0200 @@ -85,6 +85,7 @@ OutputParser.Stub output = new OutputParser.Stub(); ExecHelper eh = new ExecHelper(output, repo.getWorkingDir()); eh.run("hg", "phase", "-r", "0:-1"); + assertEquals("Perhaps, older Mercurial version, with no hg phase command support?", 0, eh.getExitValue()); Matcher m = Pattern.compile("(\\d+): (\\w+)$", Pattern.MULTILINE).matcher(output.result()); int i = 0; while (m.find()) {