diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-07 00:37:01 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-10 20:08:22 +0800 |
commit | f03695731b9b36cd4014620b7b63556a69b4e952 (patch) | |
tree | 7e9ef254705fc96cf53d625ca0aad9f43cddc87d /test/tools | |
parent | 2bc4ec31e2526abac57ac2864fa5c4bc4a7cd3a1 (diff) | |
download | dexon-solidity-f03695731b9b36cd4014620b7b63556a69b4e952.tar.gz dexon-solidity-f03695731b9b36cd4014620b7b63556a69b4e952.tar.zst dexon-solidity-f03695731b9b36cd4014620b7b63556a69b4e952.zip |
Add source locations to syntax test expectations.
Diffstat (limited to 'test/tools')
-rw-r--r-- | test/tools/isoltest.cpp | 71 |
1 files changed, 52 insertions, 19 deletions
diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 07df8f60..7a147bd0 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -55,7 +55,6 @@ public: { Success, Failure, - InputOutputError, Exception }; @@ -90,11 +89,53 @@ string SyntaxTestTool::editor; void SyntaxTestTool::printContract() const { - stringstream stream(m_test->source()); - string line; - while (getline(stream, line)) - cout << " " << line << endl; - cout << endl; + if (m_formatted) + { + string const& source = m_test->source(); + if (source.empty()) + return; + + std::vector<char const*> sourceFormatting(source.length(), formatting::RESET); + for (auto const& error: m_test->errorList()) + if (error.locationStart >= 0 && error.locationEnd >= 0) + { + assert(static_cast<size_t>(error.locationStart) < source.length()); + assert(static_cast<size_t>(error.locationEnd) < source.length()); + bool isWarning = error.type == "Warning"; + for (int i = error.locationStart; i < error.locationEnd; i++) + if (isWarning) + { + if (sourceFormatting[i] == formatting::RESET) + sourceFormatting[i] = formatting::ORANGE_BACKGROUND; + } + else + sourceFormatting[i] = formatting::RED_BACKGROUND; + } + + cout << " " << sourceFormatting.front() << source.front(); + for (size_t i = 1; i < source.length(); i++) + { + if (sourceFormatting[i] != sourceFormatting[i - 1]) + cout << sourceFormatting[i]; + if (source[i] != '\n') + cout << source[i]; + else + { + cout << formatting::RESET << endl; + if (i + 1 < source.length()) + cout << " " << sourceFormatting[i]; + } + } + cout << formatting::RESET << endl; + } + else + { + stringstream stream(m_test->source()); + string line; + while (getline(stream, line)) + cout << " " << line << endl; + cout << endl; + } } SyntaxTestTool::Result SyntaxTestTool::process() @@ -107,15 +148,6 @@ SyntaxTestTool::Result SyntaxTestTool::process() try { m_test = unique_ptr<SyntaxTest>(new SyntaxTest(m_path.string())); - } - catch (std::exception const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << "cannot read test: " << _e.what() << endl; - return Result::InputOutputError; - } - - try - { success = m_test->run(outputMessages, " ", m_formatted); } catch(CompilerError const& _e) @@ -142,6 +174,11 @@ SyntaxTestTool::Result SyntaxTestTool::process() "UnimplementedFeatureError: " << SyntaxTest::errorMessage(_e) << endl; return Result::Exception; } + catch (std::exception const& _e) + { + FormattedScope(cout, m_formatted, {BOLD, RED}) << "Exception: " << _e.what() << endl; + return Result::Exception; + } catch(...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << @@ -262,10 +299,6 @@ SyntaxTestStats SyntaxTestTool::processPath( paths.pop(); ++successCount; break; - default: - // non-recoverable error; continue with next test case - paths.pop(); - break; } } } |