aboutsummaryrefslogtreecommitdiffstats
path: root/solidityNatspecJSON.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-02 17:41:18 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-02 17:41:18 +0800
commit92724ab80a713332d711fe43a5a09332d9d2d9e4 (patch)
treeeb11e2155937b55c19922b0d4cf24c3f632fb086 /solidityNatspecJSON.cpp
parentbbf4beab45e4e4a8b02bbf5736e8667c2667f815 (diff)
downloaddexon-solidity-92724ab80a713332d711fe43a5a09332d9d2d9e4.tar.gz
dexon-solidity-92724ab80a713332d711fe43a5a09332d9d2d9e4.tar.zst
dexon-solidity-92724ab80a713332d711fe43a5a09332d9d2d9e4.zip
More Natspec JSON export tests and better error reporting
Diffstat (limited to 'solidityNatspecJSON.cpp')
-rw-r--r--solidityNatspecJSON.cpp76
1 files changed, 75 insertions, 1 deletions
diff --git a/solidityNatspecJSON.cpp b/solidityNatspecJSON.cpp
index 5918eec9..5a4649d2 100644
--- a/solidityNatspecJSON.cpp
+++ b/solidityNatspecJSON.cpp
@@ -23,6 +23,7 @@
#include <boost/test/unit_test.hpp>
#include <libsolidity/CompilerStack.h>
#include <jsonrpc/json/json.h>
+#include <libdevcore/Exceptions.h>
namespace dev
{
@@ -36,7 +37,19 @@ class DocumentationChecker
public:
void checkNatspec(std::string const& _code, std::string const& _expectedDocumentationString)
{
- m_compilerStack.parse(_code);
+ try
+ {
+ m_compilerStack.parse(_code);
+ }
+ catch (const std::exception& e)
+ {
+ std::string const* extra = boost::get_error_info<errinfo_comment>(e);
+ std::string msg = std::string("Parsing contract failed with: ") +
+ e.what() + std::string("\n");
+ if (extra)
+ msg += *extra;
+ BOOST_FAIL(msg);
+ }
auto generatedDocumentationString = m_compilerStack.getDocumentation();
Json::Value generatedDocumentation;
m_reader.parse(generatedDocumentationString, generatedDocumentation);
@@ -69,6 +82,67 @@ BOOST_AUTO_TEST_CASE(basic_test)
checkNatspec(sourceCode, natspec);
}
+BOOST_AUTO_TEST_CASE(multiline_comment)
+{
+ char const* sourceCode = "contract test {\n"
+ " /// Multiplies `a` by 7\n"
+ " /// and then adds `b`\n"
+ " function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
+ " {\n"
+ " return (a * 7) + b;\n"
+ " }\n"
+ "}\n";
+
+ char const* natspec = "{"
+ "\"methods\":{"
+ " \"mul_and_add\":{ \"user\": \" Multiplies `a` by 7\n and then adds `b`\"}"
+ "}}";
+
+ checkNatspec(sourceCode, natspec);
+}
+
+BOOST_AUTO_TEST_CASE(multiple_functions)
+{
+ char const* sourceCode = "contract test {\n"
+ " /// Multiplies `a` by 7\n"
+ " /// and then adds `b`\n"
+ " function mul_and_add(uint a, uint256 b) returns(uint256 d)\n"
+ " {\n"
+ " return (a * 7) + b;\n"
+ " }\n"
+ "\n"
+ " /// Divides `input` by `div`\n"
+ " function divide(uint input, uint div) returns(uint d)\n"
+ " {\n"
+ " return input / div;\n"
+ " }\n"
+ " /// Subtracts 3 from `input`\n"
+ " function sub(int input) returns(int d)\n"
+ " {\n"
+ " return input - 3;\n"
+ " }\n"
+ "}\n";
+
+ char const* natspec = "{"
+ "\"methods\":{"
+ " \"mul_and_add\":{ \"user\": \" Multiplies `a` by 7\n and then adds `b`\"},"
+ " \"divide\":{ \"user\": \" Divides `input` by `div`\"},"
+ " \"sub\":{ \"user\": \" Subtracts 3 from `input`\"}"
+ "}}";
+
+ checkNatspec(sourceCode, natspec);
+}
+
+BOOST_AUTO_TEST_CASE(empty_contract)
+{
+ char const* sourceCode = "contract test {\n"
+ "}\n";
+
+ char const* natspec = "{\"methods\":{} }";
+
+ checkNatspec(sourceCode, natspec);
+}
+
BOOST_AUTO_TEST_SUITE_END()