Mercurial > jhg
changeset 609:e4a71afd3c71
Test TODOs: test for ConfigFile (covering %include and %unset directives)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 08 May 2013 17:11:45 +0200 |
parents | e1b29756f901 |
children | 5c68567b3645 |
files | build.xml cmdline/org/tmatesoft/hg/console/Main.java test-data/included.rc test-data/sample.rc test/org/tmatesoft/hg/test/TestAuxUtilities.java test/org/tmatesoft/hg/test/TestConfigFiles.java test/org/tmatesoft/hg/test/TestDirstate.java |
diffstat | 7 files changed, 134 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/build.xml Tue May 07 21:27:51 2013 +0200 +++ b/build.xml Wed May 08 17:11:45 2013 +0200 @@ -90,6 +90,7 @@ <test name="org.tmatesoft.hg.test.TestStorePath" /> <test name="org.tmatesoft.hg.test.TestNewlineFilter" /> <test name="org.tmatesoft.hg.test.TestIgnore" /> + <test name="org.tmatesoft.hg.test.TestConfigFiles" /> <test name="org.tmatesoft.hg.test.TestDirstate" /> <test name="org.tmatesoft.hg.test.TestBranches" /> <test name="org.tmatesoft.hg.test.TestByteChannel" />
--- a/cmdline/org/tmatesoft/hg/console/Main.java Tue May 07 21:27:51 2013 +0200 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Wed May 08 17:11:45 2013 +0200 @@ -107,7 +107,6 @@ // m.testCheckout(); // m.tryExtensions(); // m.dumpBookmarks(); -// m.readConfigFile(); // m.dumpCommitLastMessage(); // m.buildFileLog(); // m.testConsoleLog(); @@ -210,19 +209,6 @@ } } - // TODO as test - private void readConfigFile() throws Exception { - ConfigFile configFile = new ConfigFile(hgRepo.getSessionContext()); - configFile.addLocation(new File(System.getProperty("user.home"), "test-cfg/aaa/config1")); - for (String s : configFile.getSectionNames()) { - System.out.printf("[%s]\n", s); - for (Map.Entry<String, String> e : configFile.getSection(s).entrySet()) { - System.out.printf("%s = %s\n", e.getKey(), e.getValue()); - } - } - - } - private void dumpCommitLastMessage() throws Exception { System.out.println(hgRepo.getCommitLastMessage()); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/included.rc Wed May 08 17:11:45 2013 +0200 @@ -0,0 +1,6 @@ +[section1] +key2 = alternative value 2 + + +[section2] +key1=value 1-2 # comment \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/sample.rc Wed May 08 17:11:45 2013 +0200 @@ -0,0 +1,15 @@ +[section1] +# comment +key1=value 1 +key2=value 2 +key3=value 3#comment + +%include ./included.rc + +[section3] +key1=value 1-3 + +[section1] +key4=value 4 +%unset key1 +
--- a/test/org/tmatesoft/hg/test/TestAuxUtilities.java Tue May 07 21:27:51 2013 +0200 +++ b/test/org/tmatesoft/hg/test/TestAuxUtilities.java Wed May 08 17:11:45 2013 +0200 @@ -25,7 +25,6 @@ import java.nio.ByteBuffer; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.tmatesoft.hg.core.HgCatCommand; @@ -41,15 +40,11 @@ import org.tmatesoft.hg.repo.HgDataFile; import org.tmatesoft.hg.repo.HgManifest; import org.tmatesoft.hg.repo.HgManifest.Flags; -import org.tmatesoft.hg.repo.HgRepoConfig; -import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; -import org.tmatesoft.hg.repo.HgRepoConfig.Section; import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.Adaptable; import org.tmatesoft.hg.util.ByteChannel; import org.tmatesoft.hg.util.CancelSupport; import org.tmatesoft.hg.util.CancelledException; -import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; import org.tmatesoft.hg.util.ProgressSupport; @@ -388,29 +383,6 @@ } } } - - - @Test - @Ignore("just a dump for now, to compare values visually") - public void testRepositoryConfig() throws Exception { - HgRepository repo = Configuration.get().own(); - final HgRepoConfig cfg = repo.getConfiguration(); - Assert.assertNotNull(cfg.getPaths()); - Assert.assertNotNull(cfg.getExtensions()); - final Section dne = cfg.getSection("does-not-exist"); - Assert.assertNotNull(dne); - Assert.assertFalse(dne.exists()); - for (Pair<String, String> p : cfg.getSection("ui")) { - System.out.printf("%s = %s\n", p.first(), p.second()); - } - final PathsSection p = cfg.getPaths(); - System.out.printf("Known paths: %d. default: %s(%s), default-push: %s(%s)\n", p.getKeys().size(), p.getDefault(), p.hasDefault(), p.getDefaultPush(), p.hasDefaultPush()); - for (String k : cfg.getPaths().getKeys()) { - System.out.println(k); - } - Assert.assertFalse(p.hasDefault() ^ p.getDefault() != null); - Assert.assertFalse(p.hasDefaultPush() ^ p.getDefaultPush() != null); - } @Test public void testChangelogExtrasDecode() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/org/tmatesoft/hg/test/TestConfigFiles.java Wed May 08 17:11:45 2013 +0200 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 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 + * 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 java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.tmatesoft.hg.internal.BasicSessionContext; +import org.tmatesoft.hg.internal.ConfigFile; +import org.tmatesoft.hg.repo.HgRepoConfig; +import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; +import org.tmatesoft.hg.repo.HgRepoConfig.Section; +import org.tmatesoft.hg.repo.HgRepository; +import org.tmatesoft.hg.util.Pair; + +/** + * + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +public class TestConfigFiles { + + @Rule + public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); + + @Test + public void testConfigFile() throws Exception { + ConfigFile configFile = new ConfigFile(new BasicSessionContext(null)); + configFile.addLocation(new File(Configuration.get().getTestDataDir(), "sample.rc")); + // section1 has key1 unset, key2 overridden from included, key4 from second occurence + HashMap<String, String> section1 = new HashMap<String, String>(); + section1.put("key2", "alternative value 2"); + section1.put("key3", "value 3"); + section1.put("key4", "value 4"); + // section2 comes from included config + HashMap<String, String> section2 = new HashMap<String, String>(); + section2.put("key1", "value 1-2"); + HashMap<String, String> section3 = new HashMap<String, String>(); + section3.put("key1", "value 1-3"); + HashMap<String, HashMap<String,String>> sections = new HashMap<String, HashMap<String,String>>(); + sections.put("section1", section1); + sections.put("section2", section2); + sections.put("section3", section3); + // + for (String s : configFile.getSectionNames()) { +// System.out.printf("[%s]\n", s); + final HashMap<String, String> m = sections.remove(s); + errorCollector.assertTrue(m != null); + for (Map.Entry<String, String> e : configFile.getSection(s).entrySet()) { +// System.out.printf("%s = %s\n", e.getKey(), e.getValue()); + if (m.containsKey(e.getKey())) { + errorCollector.assertEquals(m.remove(e.getKey()), e.getValue()); + } else { + errorCollector.fail("Unexpected key:" + e.getKey()); + } + } + } + errorCollector.assertEquals(0, sections.size()); + errorCollector.assertEquals(0, section1.size()); + errorCollector.assertEquals(0, section2.size()); + errorCollector.assertEquals(0, section3.size()); + } + + @Test + @Ignore("just a dump for now, to compare values visually") + public void testRepositoryConfig() throws Exception { + HgRepository repo = Configuration.get().own(); + final HgRepoConfig cfg = repo.getConfiguration(); + Assert.assertNotNull(cfg.getPaths()); + Assert.assertNotNull(cfg.getExtensions()); + final Section dne = cfg.getSection("does-not-exist"); + Assert.assertNotNull(dne); + Assert.assertFalse(dne.exists()); + for (Pair<String, String> p : cfg.getSection("ui")) { + System.out.printf("%s = %s\n", p.first(), p.second()); + } + final PathsSection p = cfg.getPaths(); + System.out.printf("Known paths: %d. default: %s(%s), default-push: %s(%s)\n", p.getKeys().size(), p.getDefault(), p.hasDefault(), p.getDefaultPush(), p.hasDefaultPush()); + for (String k : cfg.getPaths().getKeys()) { + System.out.println(k); + } + Assert.assertFalse(p.hasDefault() ^ p.getDefault() != null); + Assert.assertFalse(p.hasDefaultPush() ^ p.getDefaultPush() != null); + } +}
--- a/test/org/tmatesoft/hg/test/TestDirstate.java Tue May 07 21:27:51 2013 +0200 +++ b/test/org/tmatesoft/hg/test/TestDirstate.java Wed May 08 17:11:45 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 @@ -17,8 +17,7 @@ package org.tmatesoft.hg.test; import static java.lang.Character.*; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.TreeSet; @@ -46,10 +45,13 @@ public void testParents() throws Exception { repo = Configuration.get().find("log-branches"); final Pair<Nodeid, Nodeid> wcParents = repo.getWorkingCopyParents(); - Assert.assertEquals("5f24ef64e9dfb1540db524f88cb5c3d265e1a3b5", wcParents.first().toString()); - Assert.assertTrue(wcParents.second().isNull()); + assertEquals("5f24ef64e9dfb1540db524f88cb5c3d265e1a3b5", wcParents.first().toString()); + assertTrue(wcParents.second().isNull()); // - // TODO same static and non-static + HgDirstate ds = new HgInternals(repo).getDirstate(); + final Pair<Nodeid, Nodeid> wcParents2 = ds.parents(); + assertEquals(wcParents.first(), wcParents2.first()); + assertEquals(wcParents.second(), wcParents2.second()); } @Test