# HG changeset patch # User Artem Tikhomirov # Date 1368025905 -7200 # Node ID e4a71afd3c71a74f8c5d69517c251ccdc819c743 # Parent e1b29756f901ea2a9b111fd4c081343d9e9627e9 Test TODOs: test for ConfigFile (covering %include and %unset directives) diff -r e1b29756f901 -r e4a71afd3c71 build.xml --- 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 @@ + diff -r e1b29756f901 -r e4a71afd3c71 cmdline/org/tmatesoft/hg/console/Main.java --- 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 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()); } diff -r e1b29756f901 -r e4a71afd3c71 test-data/included.rc --- /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 diff -r e1b29756f901 -r e4a71afd3c71 test-data/sample.rc --- /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 + diff -r e1b29756f901 -r e4a71afd3c71 test/org/tmatesoft/hg/test/TestAuxUtilities.java --- 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 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() { diff -r e1b29756f901 -r e4a71afd3c71 test/org/tmatesoft/hg/test/TestConfigFiles.java --- /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 section1 = new HashMap(); + section1.put("key2", "alternative value 2"); + section1.put("key3", "value 3"); + section1.put("key4", "value 4"); + // section2 comes from included config + HashMap section2 = new HashMap(); + section2.put("key1", "value 1-2"); + HashMap section3 = new HashMap(); + section3.put("key1", "value 1-3"); + HashMap> sections = new HashMap>(); + 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 m = sections.remove(s); + errorCollector.assertTrue(m != null); + for (Map.Entry 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 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); + } +} diff -r e1b29756f901 -r e4a71afd3c71 test/org/tmatesoft/hg/test/TestDirstate.java --- 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 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 wcParents2 = ds.parents(); + assertEquals(wcParents.first(), wcParents2.first()); + assertEquals(wcParents.second(), wcParents2.second()); } @Test