aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-08-15 19:09:56 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-08-15 19:09:56 +0000
commit41c869740d22f8c6909821ae670f370a143bb7a7 (patch)
treeca9267b51f257cd2d77c067ff3dbf183eb6989af
parent401eb4bea383b9056733e192728cb5c58b69aab4 (diff)
downloadpaludis-41c869740d22f8c6909821ae670f370a143bb7a7.tar.gz
paludis-41c869740d22f8c6909821ae670f370a143bb7a7.tar.xz
Add kvcfo_ignore_export.
-rw-r--r--paludis/config_file.cc13
-rw-r--r--paludis/config_file.se1
-rw-r--r--paludis/config_file_TEST.cc42
3 files changed, 56 insertions, 0 deletions
diff --git a/paludis/config_file.cc b/paludis/config_file.cc
index f9c86f1..d5e3182 100644
--- a/paludis/config_file.cc
+++ b/paludis/config_file.cc
@@ -649,6 +649,19 @@ KeyValueConfigFile::_parse(const Source & ss, const KeyValueConfigFileOptions &
else
{
std::string key(grab_key(c, c_end));
+
+ if (key == "export" && opts[kvcfo_ignore_export])
+ {
+ if (c == c_end)
+ throw ConfigFileError(s.filename(), "Syntax error: trailing token '" + key + "' at end of input");
+ while (*c == '\t' || *c == ' ')
+ if (++c == c_end)
+ throw ConfigFileError(s.filename(), "Unknown command of broken variable '" +
+ key + "' at end of input");
+
+ key = grab_key(c, c_end);
+ }
+
if (key.empty())
throw ConfigFileError(s.filename(), "Syntax error: invalid identifier");
diff --git a/paludis/config_file.se b/paludis/config_file.se
index 3c31656..ba08870 100644
--- a/paludis/config_file.se
+++ b/paludis/config_file.se
@@ -35,6 +35,7 @@ make_enum_KeyValueConfigFileOption()
key kvcfo_disallow_variables "Do not allow variable expansions"
key kvcfo_disallow_source "Do not allow the source command"
key kvcfo_preserve_whitespace "Do not strip trailing whitespace from values"
+ key kvcfo_ignore_export "Accept and ignore the word export at the beginning of a line"
doxygen_comment << "END"
/**
diff --git a/paludis/config_file_TEST.cc b/paludis/config_file_TEST.cc
index aebc990..52a2632 100644
--- a/paludis/config_file_TEST.cc
+++ b/paludis/config_file_TEST.cc
@@ -300,6 +300,36 @@ namespace test_cases
} test_key_value_config_file_source;
/**
+ * \test Test KeyValueConfigFile ignore export.
+ *
+ */
+ struct KeyValueConfigFileIgnoreExportTest : TestCase
+ {
+ KeyValueConfigFileIgnoreExportTest() : TestCase("key value config file ignore export") { }
+
+ void run()
+ {
+ std::stringstream d_s;
+ d_s << "export \t foo = \"xyzzy\"" << std::endl;
+ d_s << "export bar='plugh'" << std::endl;
+ d_s << "baz = \"plover\"" << std::endl;
+ d_s << "exportfoo = \"exportxyzzy\"" << std::endl;
+ KeyValueConfigFile ff(d_s, KeyValueConfigFileOptions() += kvcfo_ignore_export);
+
+ TEST_CHECK_EQUAL(ff.get("foo"), "xyzzy");
+ TEST_CHECK_EQUAL(ff.get("bar"), "plugh");
+ TEST_CHECK_EQUAL(ff.get("baz"), "plover");
+ TEST_CHECK_EQUAL(ff.get("exportfoo"), "exportxyzzy");
+
+ std::stringstream d_s2;
+ d_s2 << "export = 42" << std::endl;
+ KeyValueConfigFile ff2(d_s2, KeyValueConfigFileOptions());
+
+ TEST_CHECK_EQUAL(ff2.get("export"), "42");
+ }
+ } test_key_value_config_file_ignore_export;
+
+ /**
* \test Test KeyValueConfigFile errors.
*
*/
@@ -344,6 +374,18 @@ namespace test_cases
std::stringstream s9;
s9 << "x='blah" << std::endl << "blah" << std::endl;
TEST_CHECK_THROWS(KeyValueConfigFile ff(s9, KeyValueConfigFileOptions()), ConfigurationError);
+
+ std::stringstream s10;
+ s10 << "export x=blah" << std::endl;
+ TEST_CHECK_THROWS(KeyValueConfigFile ff(s10, KeyValueConfigFileOptions()), ConfigurationError);
+
+ std::stringstream s11;
+ s11 << "export x = blah" << std::endl;
+ TEST_CHECK_THROWS(KeyValueConfigFile ff(s11, (KeyValueConfigFileOptions() += kvcfo_ignore_export) += kvcfo_disallow_space_around_equals), ConfigurationError);
+
+ std::stringstream s12;
+ s12 << "export=blah" << std::endl;
+ TEST_CHECK_THROWS(KeyValueConfigFile ff(s12, KeyValueConfigFileOptions() += kvcfo_ignore_export), ConfigurationError);
}
} test_key_value_config_file_errors;
}