mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add --standard-json option to solfuzzer
This commit is contained in:
parent
3a93aec768
commit
28902f9f42
@ -36,6 +36,8 @@ namespace po = boost::program_options;
|
||||
extern "C"
|
||||
{
|
||||
extern char const* compileJSON(char const* _input, bool _optimize);
|
||||
typedef void (*CStyleReadFileCallback)(char const* _path, char** o_contents, char** o_error);
|
||||
extern char const* compileStandard(char const* _input, CStyleReadFileCallback _readCallback);
|
||||
}
|
||||
|
||||
bool quiet = false;
|
||||
@ -83,10 +85,8 @@ void testConstantOptimizer()
|
||||
}
|
||||
}
|
||||
|
||||
void testCompiler()
|
||||
string readInput()
|
||||
{
|
||||
if (!quiet)
|
||||
cout << "Testing compiler." << endl;
|
||||
string input;
|
||||
while (!cin.eof())
|
||||
{
|
||||
@ -94,6 +94,41 @@ void testCompiler()
|
||||
getline(cin, s);
|
||||
input += s + '\n';
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
void testStandardCompiler()
|
||||
{
|
||||
if (!quiet)
|
||||
cout << "Testing compiler via JSON interface." << endl;
|
||||
string input = readInput();
|
||||
string outputString(compileStandard(input.c_str(), NULL));
|
||||
Json::Value output;
|
||||
if (!Json::Reader().parse(outputString, output))
|
||||
{
|
||||
cout << "Compiler produced invalid JSON output." << endl;
|
||||
abort();
|
||||
}
|
||||
if (output.isMember("errors"))
|
||||
for (auto const& error: output["errors"])
|
||||
{
|
||||
string invalid = contains(error["type"].asString(), vector<string>{
|
||||
"Exception",
|
||||
"InternalCompilerError"
|
||||
});
|
||||
if (!invalid.empty())
|
||||
{
|
||||
cout << "Invalid error: \"" << error["type"].asString() << "\"" << endl;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testCompiler()
|
||||
{
|
||||
if (!quiet)
|
||||
cout << "Testing compiler." << endl;
|
||||
string input = readInput();
|
||||
|
||||
bool optimize = true;
|
||||
string outputString(compileJSON(input.c_str(), optimize));
|
||||
@ -148,6 +183,12 @@ Allowed options)",
|
||||
options.add_options()
|
||||
("help", "Show this help screen.")
|
||||
("quiet", "Only output errors.")
|
||||
(
|
||||
"standard-json",
|
||||
"Test via the standard-json interface, i.e. "
|
||||
"input is expected to be JSON-encoded instead of "
|
||||
"plain source file."
|
||||
)
|
||||
(
|
||||
"const-opt",
|
||||
"Run the constant optimizer instead of compiling. "
|
||||
@ -174,6 +215,8 @@ Allowed options)",
|
||||
cout << options;
|
||||
else if (arguments.count("const-opt"))
|
||||
testConstantOptimizer();
|
||||
else if (arguments.count("standard-json"))
|
||||
testStandardCompiler();
|
||||
else
|
||||
testCompiler();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user