modified test network to test exceptions during parsing of documentation

todo:
 - change to work wirh all exceptions
 - fix white space problems in the output text for Natspec
This commit is contained in:
Liana Husikyan 2015-06-17 11:47:29 +02:00
parent c432ec46f9
commit dd1e770009
3 changed files with 45 additions and 31 deletions

View File

@ -25,6 +25,7 @@
#include <tuple> #include <tuple>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcore/Hash.h> #include <libdevcore/Hash.h>
#include <libsolidity/Exceptions.h>
#include <test/libsolidity/solidityExecutionFramework.h> #include <test/libsolidity/solidityExecutionFramework.h>
using namespace std; using namespace std;
@ -4657,6 +4658,32 @@ BOOST_AUTO_TEST_CASE(bytes_memory_index_access)
) == encodeArgs(u256(data.size()), string("d"))); ) == encodeArgs(u256(data.size()), string("d")));
} }
BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
{
char const* sourceCode = " /// @author Lefteris\n"
" /// @title Just a test contract\n"
"contract test {\n"
" /// @dev Mul function\n"
" /// @title I really should not be here\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
compileRequireThrow(sourceCode);
}
BOOST_AUTO_TEST_CASE(dev_documenting_nonexistant_param)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param not_existing Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
compileRequireThrow(sourceCode);
}
BOOST_AUTO_TEST_CASE(storage_array_ref) BOOST_AUTO_TEST_CASE(storage_array_ref)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(

View File

@ -38,9 +38,11 @@ class DocumentationChecker
public: public:
DocumentationChecker(): m_compilerStack(false) {} DocumentationChecker(): m_compilerStack(false) {}
void checkNatspec(std::string const& _code, void checkNatspec(
std::string const& _expectedDocumentationString, std::string const& _code,
bool _userDocumentation) std::string const& _expectedDocumentationString,
bool _userDocumentation
)
{ {
std::string generatedDocumentationString; std::string generatedDocumentationString;
ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed"); ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parse(_code), "Parsing failed");
@ -53,9 +55,11 @@ public:
m_reader.parse(generatedDocumentationString, generatedDocumentation); m_reader.parse(generatedDocumentationString, generatedDocumentation);
Json::Value expectedDocumentation; Json::Value expectedDocumentation;
m_reader.parse(_expectedDocumentationString, expectedDocumentation); m_reader.parse(_expectedDocumentationString, expectedDocumentation);
BOOST_CHECK_MESSAGE(expectedDocumentation == generatedDocumentation, BOOST_CHECK_MESSAGE(
"Expected " << _expectedDocumentationString << expectedDocumentation == generatedDocumentation,
"\n but got:\n" << generatedDocumentationString); "Expected " << _expectedDocumentationString <<
"\n but got:\n" << generatedDocumentationString
);
} }
private: private:
@ -229,18 +233,6 @@ BOOST_AUTO_TEST_CASE(dev_multiple_params)
checkNatspec(sourceCode, natspec, false); checkNatspec(sourceCode, natspec, false);
} }
BOOST_AUTO_TEST_CASE(dev_documenting_nonexistant_param)
{
char const* sourceCode = "contract test {\n"
" /// @dev Multiplies a number by 7 and adds second parameter\n"
" /// @param a Documentation for the first parameter\n"
" /// @param not_existing Documentation for the second parameter\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
BOOST_CHECK_THROW(checkNatspec(sourceCode, "", false), DocstringParsingError);
}
BOOST_AUTO_TEST_CASE(dev_mutiline_param_description) BOOST_AUTO_TEST_CASE(dev_mutiline_param_description)
{ {
char const* sourceCode = "contract test {\n" char const* sourceCode = "contract test {\n"
@ -488,19 +480,6 @@ BOOST_AUTO_TEST_CASE(dev_author_at_function)
checkNatspec(sourceCode, natspec, false); checkNatspec(sourceCode, natspec, false);
} }
BOOST_AUTO_TEST_CASE(dev_title_at_function_error)
{
char const* sourceCode = " /// @author Lefteris\n"
" /// @title Just a test contract\n"
"contract test {\n"
" /// @dev Mul function\n"
" /// @title I really should not be here\n"
" function mul(uint a, uint second) returns(uint d) { return a * 7 + second; }\n"
"}\n";
BOOST_CHECK_THROW(checkNatspec(sourceCode, "", false), DocstringParsingError);
}
BOOST_AUTO_TEST_CASE(natspec_notice_without_tag) BOOST_AUTO_TEST_CASE(natspec_notice_without_tag)
{ {
char const* sourceCode = "contract test {\n" char const* sourceCode = "contract test {\n"

View File

@ -28,6 +28,7 @@
#include <libethereum/State.h> #include <libethereum/State.h>
#include <libethereum/Executive.h> #include <libethereum/Executive.h>
#include <libsolidity/CompilerStack.h> #include <libsolidity/CompilerStack.h>
#include <libsolidity/Exceptions.h>
namespace dev namespace dev
{ {
@ -57,6 +58,13 @@ public:
return m_output; return m_output;
} }
void compileRequireThrow(std::string const& _sourceCode)
{
m_compiler.reset(false, m_addStandardSources);
m_compiler.addSource("", _sourceCode);
BOOST_REQUIRE_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), DocstringParsingError);
}
bytes const& compileAndRun( bytes const& compileAndRun(
std::string const& _sourceCode, std::string const& _sourceCode,
u256 const& _value = 0, u256 const& _value = 0,