Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/RepoUtils.java @ 536:2813a26b8999
Tests: refactor various utility methods to a single location
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 05 Feb 2013 16:36:58 +0100 |
parents | |
children | 6ca3d0c5b4bc |
comparison
equal
deleted
inserted
replaced
535:d9c07e1432c4 | 536:2813a26b8999 |
---|---|
1 /* | |
2 * Copyright (c) 2013 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@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.test; | |
18 | |
19 import static org.junit.Assert.assertEquals; | |
20 import static org.junit.Assert.assertTrue; | |
21 import static org.tmatesoft.hg.internal.RequiresFile.*; | |
22 | |
23 import java.io.File; | |
24 import java.io.FileOutputStream; | |
25 import java.io.IOException; | |
26 import java.util.ArrayList; | |
27 | |
28 import org.tmatesoft.hg.internal.RepoInitializer; | |
29 import org.tmatesoft.hg.repo.HgRepository; | |
30 | |
31 /** | |
32 * | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public class RepoUtils { | |
37 | |
38 static File initEmptyTempRepo(String dirName) throws IOException { | |
39 File dest = createEmptyDir(dirName); | |
40 RepoInitializer ri = new RepoInitializer(); | |
41 ri.setRequires(STORE | FNCACHE | DOTENCODE); | |
42 ri.initEmptyRepository(new File(dest, ".hg")); | |
43 return dest; | |
44 } | |
45 | |
46 static File createEmptyDir(String dirName) throws IOException { | |
47 File dest = new File(Configuration.get().getTempDir(), dirName); | |
48 if (dest.exists()) { | |
49 TestClone.rmdir(dest); | |
50 } | |
51 dest.mkdirs(); | |
52 return dest; | |
53 } | |
54 | |
55 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws Exception, InterruptedException { | |
56 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate); | |
57 } | |
58 | |
59 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException { | |
60 File testRepoLoc = createEmptyDir(name); | |
61 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile()); | |
62 ArrayList<String> cmd = new ArrayList<String>(); | |
63 cmd.add("hg"); cmd.add("clone"); | |
64 if (noupdate) { | |
65 cmd.add("--noupdate"); | |
66 } | |
67 cmd.add(repo.getWorkingDir().toString()); | |
68 cmd.add(testRepoLoc.getName()); | |
69 eh.run(cmd.toArray(new String[cmd.size()])); | |
70 assertEquals("[sanity]", 0, eh.getExitValue()); | |
71 return testRepoLoc; | |
72 } | |
73 | |
74 static void modifyFileAppend(File f) throws IOException { | |
75 assertTrue(f.isFile()); | |
76 FileOutputStream fos = new FileOutputStream(f, true); | |
77 fos.write("XXX".getBytes()); | |
78 fos.close(); | |
79 } | |
80 | |
81 } |