aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-01 06:42:19 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-01 06:42:25 +0100
commit0db3a23b21fe2856f64c5007b27e46a8140f10c0 (patch)
tree381affd095f2dbe54f168f04dbf7e5291f94aae2
parent9723d823bba90862df6de9ae8cec90cbda9e064c (diff)
Fail build if project.conf contains invalid object or field
-rw-r--r--include/Conf.hpp1
-rw-r--r--src/Conf.cpp37
-rw-r--r--tests/src/confTest/confTest.cpp18
-rw-r--r--tests/src/confTest/invalidField.conf10
-rw-r--r--tests/src/confTest/invalidObject.conf12
-rw-r--r--tests/src/confTest/validProject.conf (renamed from tests/src/confTest/project.conf)0
6 files changed, 76 insertions, 2 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp
index f5fb382..75076fa 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -228,6 +228,7 @@ namespace sibs
virtual void processObject(StringView name) override;
virtual void processField(StringView name, const ConfigValue &value) override;
virtual void finished() override;
+ void failInvalidFieldUnderObject(const StringView &fieldName) const;
private:
void validatePackageName() const;
protected:
diff --git a/src/Conf.cpp b/src/Conf.cpp
index c487e28..27713d8 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -494,6 +494,14 @@ namespace sibs
validatePackageName();
}
+ else if(name.equals("version"))
+ {
+ // TODO: Use version for info output when building
+ }
+ else if(name.equals("authors"))
+ {
+ // TODO: Use authors for something?
+ }
else if(name.equals("type"))
{
if (value.isSingle())
@@ -618,6 +626,8 @@ namespace sibs
else
throw ParserException("Expected package.ignore_dirs to be a list, was a single value");
}
+ else
+ failInvalidFieldUnderObject(name);
}
else if(currentObject.equals("config"))
{
@@ -638,6 +648,8 @@ namespace sibs
throw ParserException(errMsg);
}
}
+ else
+ failInvalidFieldUnderObject(name);
}
else if (currentObject.equals(CONFIG_SYSTEM_PLATFORM))
{
@@ -658,6 +670,8 @@ namespace sibs
throw ParserException(errMsg);
}
}
+ else
+ failInvalidFieldUnderObject(name);
}
else if (currentObject.equals(CONFIG_STATIC_DEBUG_PLATFORM))
{
@@ -678,6 +692,8 @@ namespace sibs
throw ParserException(errMsg);
}
}
+ else
+ failInvalidFieldUnderObject(name);
}
else if (currentObject.equals(CONFIG_STATIC_RELEASE_PLATFORM))
{
@@ -698,6 +714,8 @@ namespace sibs
throw ParserException(errMsg);
}
}
+ else
+ failInvalidFieldUnderObject(name);
}
else if(currentObject.equals("dependencies"))
{
@@ -712,6 +730,13 @@ namespace sibs
else
throw ParserException("Expected field under dependencies to be a single value, was a list");
}
+ else
+ {
+ string errMsg = "Invalid config object \"";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += "\"";
+ throw ParserException(errMsg);
+ }
}
void SibsConfig::finished()
@@ -734,7 +759,17 @@ namespace sibs
throw ParserException(errMsg);
}
}
-
+
+ void SibsConfig::failInvalidFieldUnderObject(const StringView &fieldName) const
+ {
+ string errMsg = "Invalid field \"";
+ errMsg += string(fieldName.data, fieldName.size);
+ errMsg += "\" under object \"";
+ errMsg += string(currentObject.data, currentObject.size);
+ errMsg += "\"";
+ throw ParserException(errMsg);
+ }
+
void SibsTestConfig::processObject(StringView name)
{
currentObject = name;
diff --git a/tests/src/confTest/confTest.cpp b/tests/src/confTest/confTest.cpp
index 5bab144..17b5995 100644
--- a/tests/src/confTest/confTest.cpp
+++ b/tests/src/confTest/confTest.cpp
@@ -6,7 +6,7 @@ using namespace sibs;
TEST_CASE("parse config")
{
SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
- Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/project.conf"), sibsConfig);
+ Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/validProject.conf"), sibsConfig);
if(result.isErr())
{
fprintf(stderr, "%s", result.getErrMsg().c_str());
@@ -28,3 +28,19 @@ TEST_CASE("parse config")
REQUIRE(catch2Dependency.name == "catch2");
REQUIRE(catch2Dependency.version == "1.0.0");
}
+
+TEST_CASE("parse config - invalid object")
+{
+ SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
+ Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/invalidObject.conf"), sibsConfig);
+ REQUIRE(result.isErr());
+ REQUIRE(result.getErrMsg() == "Invalid config object \"invalidObj\"");
+}
+
+TEST_CASE("parse config - invalid field")
+{
+ SibsConfig sibsConfig(Compiler::GCC, TINYDIR_STRING("tests/src/confTest"));
+ Result<bool> result = Config::readFromFile(TINYDIR_STRING("tests/src/confTest/invalidField.conf"), sibsConfig);
+ REQUIRE(result.isErr());
+ REQUIRE(result.getErrMsg() == "Invalid field \"invalidField\" under object \"package\"");
+}
diff --git a/tests/src/confTest/invalidField.conf b/tests/src/confTest/invalidField.conf
new file mode 100644
index 0000000..c0f5892
--- /dev/null
+++ b/tests/src/confTest/invalidField.conf
@@ -0,0 +1,10 @@
+[package]
+name = "confTest"
+version = "0.1.0"
+type = "library"
+platforms = ["linux64", "win64"]
+invalidField = "value"
+
+[dependencies]
+xxhash = "0.1.0"
+catch2 = "1.0.0"
diff --git a/tests/src/confTest/invalidObject.conf b/tests/src/confTest/invalidObject.conf
new file mode 100644
index 0000000..fe9fc86
--- /dev/null
+++ b/tests/src/confTest/invalidObject.conf
@@ -0,0 +1,12 @@
+[package]
+name = "confTest"
+version = "0.1.0"
+type = "library"
+platforms = ["linux64", "win64"]
+
+[dependencies]
+xxhash = "0.1.0"
+catch2 = "1.0.0"
+
+[invalidObj]
+field = "value"
diff --git a/tests/src/confTest/project.conf b/tests/src/confTest/validProject.conf
index de5112d..de5112d 100644
--- a/tests/src/confTest/project.conf
+++ b/tests/src/confTest/validProject.conf