From 0bed065ee73c467014d5464a7d9dc2596d6e7dfc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 16 May 2018 15:52:39 +0200 Subject: Fix source location assertion in isoltest --- test/tools/isoltest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 7a147bd0..100fcbf0 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -99,8 +99,8 @@ void SyntaxTestTool::printContract() const for (auto const& error: m_test->errorList()) if (error.locationStart >= 0 && error.locationEnd >= 0) { - assert(static_cast(error.locationStart) < source.length()); - assert(static_cast(error.locationEnd) < source.length()); + assert(static_cast(error.locationStart) <= source.length()); + assert(static_cast(error.locationEnd) <= source.length()); bool isWarning = error.type == "Warning"; for (int i = error.locationStart; i < error.locationEnd; i++) if (isWarning) -- cgit v1.2.3 From 9f546cfafcc4a12c6574550724a82074bb0afb66 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 12 Jun 2018 11:06:14 +0200 Subject: Improve exception handling in soltest and isoltest. --- test/tools/isoltest.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 100fcbf0..d4b99e9d 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -150,39 +150,22 @@ SyntaxTestTool::Result SyntaxTestTool::process() m_test = unique_ptr(new SyntaxTest(m_path.string())); success = m_test->run(outputMessages, " ", m_formatted); } - catch(CompilerError const& _e) + catch(boost::exception const& _e) { FormattedScope(cout, m_formatted, {BOLD, RED}) << - "Exception: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(InternalCompilerError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "InternalCompilerError: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(FatalError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "FatalError: " << SyntaxTest::errorMessage(_e) << endl; - return Result::Exception; - } - catch(UnimplementedFeatureError const& _e) - { - FormattedScope(cout, m_formatted, {BOLD, RED}) << - "UnimplementedFeatureError: " << SyntaxTest::errorMessage(_e) << endl; + "Exception during syntax test: " << boost::diagnostic_information(_e) << endl; return Result::Exception; } catch (std::exception const& _e) { - FormattedScope(cout, m_formatted, {BOLD, RED}) << "Exception: " << _e.what() << endl; + FormattedScope(cout, m_formatted, {BOLD, RED}) << + "Exception during syntax test: " << _e.what() << endl; return Result::Exception; } catch(...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << - "Unknown Exception" << endl; + "Unknown exception during syntax test." << endl; return Result::Exception; } -- cgit v1.2.3 From 14d0f8c2f194bfed0ae8d23042f6210cff1f93c9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 8 Jun 2018 14:17:50 +0200 Subject: Refactor syntax test infrastructure to prepare introducing semantics tests. --- test/tools/isoltest.cpp | 110 ++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 79 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index d4b99e9d..41dff148 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -37,18 +37,22 @@ using namespace std; namespace po = boost::program_options; namespace fs = boost::filesystem; -struct SyntaxTestStats +struct TestStats { int successCount; int runCount; operator bool() const { return successCount == runCount; } }; -class SyntaxTestTool +class TestTool { public: - SyntaxTestTool(string const& _name, fs::path const& _path, bool _formatted): - m_formatted(_formatted), m_name(_name), m_path(_path) + TestTool( + TestCase::TestCaseCreator _testCaseCreator, + string const& _name, + fs::path const& _path, + bool _formatted + ): m_testCaseCreator(_testCaseCreator), m_formatted(_formatted), m_name(_name), m_path(_path) {} enum class Result @@ -60,7 +64,8 @@ public: Result process(); - static SyntaxTestStats processPath( + static TestStats processPath( + TestCase::TestCaseCreator _testCaseCreator, fs::path const& _basepath, fs::path const& _path, bool const _formatted @@ -77,68 +82,16 @@ private: Request handleResponse(bool const _exception); - void printContract() const; - + TestCase::TestCaseCreator m_testCaseCreator; bool const m_formatted; string const m_name; fs::path const m_path; - unique_ptr m_test; + unique_ptr m_test; }; -string SyntaxTestTool::editor; - -void SyntaxTestTool::printContract() const -{ - if (m_formatted) - { - string const& source = m_test->source(); - if (source.empty()) - return; - - std::vector sourceFormatting(source.length(), formatting::RESET); - for (auto const& error: m_test->errorList()) - if (error.locationStart >= 0 && error.locationEnd >= 0) - { - assert(static_cast(error.locationStart) <= source.length()); - assert(static_cast(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; - } -} +string TestTool::editor; -SyntaxTestTool::Result SyntaxTestTool::process() +TestTool::Result TestTool::process() { bool success; std::stringstream outputMessages; @@ -147,7 +100,7 @@ SyntaxTestTool::Result SyntaxTestTool::process() try { - m_test = unique_ptr(new SyntaxTest(m_path.string())); + m_test = m_testCaseCreator(m_path.string()); success = m_test->run(outputMessages, " ", m_formatted); } catch(boost::exception const& _e) @@ -179,14 +132,14 @@ SyntaxTestTool::Result SyntaxTestTool::process() FormattedScope(cout, m_formatted, {BOLD, RED}) << "FAIL" << endl; FormattedScope(cout, m_formatted, {BOLD, CYAN}) << " Contract:" << endl; - printContract(); + m_test->printSource(cout, " ", m_formatted); - cout << outputMessages.str() << endl; + cout << endl << outputMessages.str() << endl; return Result::Failure; } } -SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) +TestTool::Request TestTool::handleResponse(bool const _exception) { if (_exception) cout << "(e)dit/(s)kip/(q)uit? "; @@ -208,15 +161,14 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) { cout << endl; ofstream file(m_path.string(), ios::trunc); - file << m_test->source(); + m_test->printSource(file); file << "// ----" << endl; - if (!m_test->errorList().empty()) - m_test->printErrorList(file, m_test->errorList(), "// ", false); + m_test->printUpdatedExpectations(file, "// "); return Request::Rerun; } case 'e': cout << endl << endl; - if (system((editor + " \"" + m_path.string() + "\"").c_str())) + if (system((TestTool::editor + " \"" + m_path.string() + "\"").c_str())) cerr << "Error running editor command." << endl << endl; return Request::Rerun; case 'q': @@ -228,8 +180,8 @@ SyntaxTestTool::Request SyntaxTestTool::handleResponse(bool const _exception) } } - -SyntaxTestStats SyntaxTestTool::processPath( +TestStats TestTool::processPath( + TestCase::TestCaseCreator _testCaseCreator, fs::path const& _basepath, fs::path const& _path, bool const _formatted @@ -252,12 +204,12 @@ SyntaxTestStats SyntaxTestTool::processPath( fs::directory_iterator(fullpath), fs::directory_iterator() )) - if (fs::is_directory(entry.path()) || SyntaxTest::isTestFilename(entry.path().filename())) + if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename())) paths.push(currentPath / entry.path().filename()); } else { - SyntaxTestTool testTool(currentPath.string(), fullpath, _formatted); + TestTool testTool(_testCaseCreator, currentPath.string(), fullpath, _formatted); ++runCount; auto result = testTool.process(); @@ -293,9 +245,9 @@ SyntaxTestStats SyntaxTestTool::processPath( int main(int argc, char *argv[]) { if (getenv("EDITOR")) - SyntaxTestTool::editor = getenv("EDITOR"); + TestTool::editor = getenv("EDITOR"); else if (fs::exists("/usr/bin/editor")) - SyntaxTestTool::editor = "/usr/bin/editor"; + TestTool::editor = "/usr/bin/editor"; fs::path testPath; bool formatted = true; @@ -311,7 +263,7 @@ Allowed options)", ("help", "Show this help screen.") ("testpath", po::value(&testPath), "path to test files") ("no-color", "don't use colors") - ("editor", po::value(&SyntaxTestTool::editor), "editor for opening contracts"); + ("editor", po::value(&TestTool::editor), "editor for opening contracts"); po::variables_map arguments; try @@ -331,7 +283,7 @@ Allowed options)", po::notify(arguments); } - catch (po::error const& _exception) + catch (std::exception const& _exception) { cerr << _exception.what() << endl; return 1; @@ -362,7 +314,7 @@ Allowed options)", if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) { - auto stats = SyntaxTestTool::processPath(testPath / "libsolidity", "syntaxTests", formatted); + auto stats = TestTool::processPath(SyntaxTest::create, testPath / "libsolidity", "syntaxTests", formatted); cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << @@ -373,7 +325,7 @@ Allowed options)", } else { - cerr << "Test path not found. Use the --testpath argument." << endl; + cerr << "Syntax tests not found. Use the --testpath argument." << endl; return 1; } } -- cgit v1.2.3 From 05121eebd1f219e9ae1cdf79afa8d0201ad7975a Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 10 Jul 2018 10:36:36 +0200 Subject: isoltest: adds support for properly handling ANSI escape sequences on Win32/Win64 builds. --- test/tools/isoltest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 41dff148..ed4f148e 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -29,6 +29,10 @@ #include #include +#if defined(_WIN32) +#include +#endif + using namespace dev; using namespace dev::solidity; using namespace dev::solidity::test; @@ -242,8 +246,30 @@ TestStats TestTool::processPath( } +void setupTerminal() +{ +#if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING) + // Set output mode to handle virtual terminal (ANSI escape sequences) + // ignore any error, as this is just a "nice-to-have" + // only windows needs to be taken care of, as other platforms (Linux/OSX) support them natively. + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hOut == INVALID_HANDLE_VALUE) + return; + + DWORD dwMode = 0; + if (!GetConsoleMode(hOut, &dwMode)) + return; + + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (!SetConsoleMode(hOut, dwMode)) + return; +#endif +} + int main(int argc, char *argv[]) { + setupTerminal(); + if (getenv("EDITOR")) TestTool::editor = getenv("EDITOR"); else if (fs::exists("/usr/bin/editor")) -- cgit v1.2.3 From a5a61a0b7762bf5acdd01a4e6943d927b08f92ab Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 17 May 2018 14:57:21 +0200 Subject: More consistent catch statements Also take const& in all cases. --- test/tools/isoltest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index ed4f148e..bd4b0db9 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -119,7 +119,7 @@ TestTool::Result TestTool::process() "Exception during syntax test: " << _e.what() << endl; return Result::Exception; } - catch(...) + catch (...) { FormattedScope(cout, m_formatted, {BOLD, RED}) << "Unknown exception during syntax test." << endl; -- cgit v1.2.3 From d923926ff7ceaad551fe76afb356266e28a2a1ea Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 3 Aug 2018 19:30:18 +0200 Subject: Infrastructure for extracting JSON AST tests. --- test/tools/isoltest.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index bd4b0db9..7d15b07a 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -336,22 +337,53 @@ Allowed options)", } } + TestStats global_stats { 0, 0 }; + fs::path syntaxTestPath = testPath / "libsolidity" / "syntaxTests"; if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) { auto stats = TestTool::processPath(SyntaxTest::create, testPath / "libsolidity", "syntaxTests", formatted); - cout << endl << "Summary: "; + cout << endl << "Syntax Test Summary: "; FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << stats.successCount << "/" << stats.runCount; - cout << " tests successful." << endl; + cout << " tests successful." << endl << endl; - return stats ? 0 : 1; + global_stats.runCount += stats.runCount; + global_stats.successCount += stats.successCount; } else { cerr << "Syntax tests not found. Use the --testpath argument." << endl; return 1; } + + fs::path astJsonTestPath = testPath / "libsolidity" / "ASTJSON"; + + if (fs::exists(astJsonTestPath) && fs::is_directory(astJsonTestPath)) + { + auto stats = TestTool::processPath(ASTJSONTest::create, testPath / "libsolidity", "ASTJSON", formatted); + + cout << endl << "JSON AST Test Summary: "; + FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << + stats.successCount << "/" << stats.runCount; + cout << " tests successful." << endl << endl; + + global_stats.runCount += stats.runCount; + global_stats.successCount += stats.successCount; + } + else + { + cerr << "JSON AST tests not found." << endl; + return 1; + } + + cout << endl << "Summary: "; + FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) << + global_stats.successCount << "/" << global_stats.runCount; + cout << " tests successful." << endl; + + + return global_stats ? 0 : 1; } -- cgit v1.2.3 From a6df7b1fb8109cb2cc99708abcfa440f0ad820d4 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 7 Aug 2018 19:28:21 +0200 Subject: Always count all test cases in isoltest and exit early on user request. --- test/tools/isoltest.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 7d15b07a..6b2d886c 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -45,8 +45,8 @@ namespace fs = boost::filesystem; struct TestStats { int successCount; - int runCount; - operator bool() const { return successCount == runCount; } + int testCount; + operator bool() const { return successCount == testCount; } }; class TestTool @@ -92,9 +92,11 @@ private: string const m_name; fs::path const m_path; unique_ptr m_test; + static bool m_exitRequested; }; string TestTool::editor; +bool TestTool::m_exitRequested = false; TestTool::Result TestTool::process() { @@ -195,7 +197,7 @@ TestStats TestTool::processPath( std::queue paths; paths.push(_path); int successCount = 0; - int runCount = 0; + int testCount = 0; while (!paths.empty()) { @@ -212,10 +214,15 @@ TestStats TestTool::processPath( if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename())) paths.push(currentPath / entry.path().filename()); } + else if (m_exitRequested) + { + ++testCount; + paths.pop(); + } else { + ++testCount; TestTool testTool(_testCaseCreator, currentPath.string(), fullpath, _formatted); - ++runCount; auto result = testTool.process(); switch(result) @@ -225,10 +232,12 @@ TestStats TestTool::processPath( switch(testTool.handleResponse(result == Result::Exception)) { case Request::Quit: - return { successCount, runCount }; + paths.pop(); + m_exitRequested = true; + break; case Request::Rerun: cout << "Re-running test case..." << endl; - --runCount; + --testCount; break; case Request::Skip: paths.pop(); @@ -243,7 +252,7 @@ TestStats TestTool::processPath( } } - return { successCount, runCount }; + return { successCount, testCount }; } @@ -347,10 +356,10 @@ Allowed options)", cout << endl << "Syntax Test Summary: "; FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << - stats.successCount << "/" << stats.runCount; + stats.successCount << "/" << stats.testCount; cout << " tests successful." << endl << endl; - global_stats.runCount += stats.runCount; + global_stats.testCount += stats.testCount; global_stats.successCount += stats.successCount; } else @@ -367,10 +376,10 @@ Allowed options)", cout << endl << "JSON AST Test Summary: "; FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << - stats.successCount << "/" << stats.runCount; + stats.successCount << "/" << stats.testCount; cout << " tests successful." << endl << endl; - global_stats.runCount += stats.runCount; + global_stats.testCount += stats.testCount; global_stats.successCount += stats.successCount; } else @@ -381,7 +390,7 @@ Allowed options)", cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) << - global_stats.successCount << "/" << global_stats.runCount; + global_stats.successCount << "/" << global_stats.testCount; cout << " tests successful." << endl; -- cgit v1.2.3 From 967bb6d999c0b6f7a33799825aac9ab833bf22c9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 7 Aug 2018 21:23:01 +0200 Subject: Initialize ``TestTool::m_formatted``. --- test/tools/isoltest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 6b2d886c..ad6b456d 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -88,7 +88,7 @@ private: Request handleResponse(bool const _exception); TestCase::TestCaseCreator m_testCaseCreator; - bool const m_formatted; + bool const m_formatted = false; string const m_name; fs::path const m_path; unique_ptr m_test; -- cgit v1.2.3 From 9081f803c7d27158d92ddc35a7c39bb76ad63268 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 15:25:28 +0200 Subject: Extract function. --- test/tools/isoltest.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index ad6b456d..cc7e706d 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -256,6 +256,9 @@ TestStats TestTool::processPath( } +namespace +{ + void setupTerminal() { #if defined(_WIN32) && defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING) @@ -276,6 +279,27 @@ void setupTerminal() #endif } +fs::path discoverTestPath() +{ + auto const searchPath = + { + fs::current_path() / ".." / ".." / ".." / "test", + fs::current_path() / ".." / ".." / "test", + fs::current_path() / ".." / "test", + fs::current_path() / "test", + fs::current_path() + }; + for (auto const& basePath: searchPath) + { + fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests"; + if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) + return basePath; + } + return {}; +} + +} + int main(int argc, char *argv[]) { setupTerminal(); @@ -326,25 +350,7 @@ Allowed options)", } if (testPath.empty()) - { - auto const searchPath = - { - fs::current_path() / ".." / ".." / ".." / "test", - fs::current_path() / ".." / ".." / "test", - fs::current_path() / ".." / "test", - fs::current_path() / "test", - fs::current_path() - }; - for (auto const& basePath : searchPath) - { - fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests"; - if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) - { - testPath = basePath; - break; - } - } - } + testPath = discoverTestPath(); TestStats global_stats { 0, 0 }; -- cgit v1.2.3 From 50247dc8d1f1b3f4408670ab0538da8f0e113cf6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 15:36:40 +0200 Subject: Extract test suite runs. --- test/tools/isoltest.cpp | 75 +++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index cc7e706d..5cf1d9c0 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -47,6 +47,12 @@ struct TestStats int successCount; int testCount; operator bool() const { return successCount == testCount; } + TestStats& operator+=(TestStats const& _other) + { + successCount += _other.successCount; + testCount += _other.testCount; + return *this; + } }; class TestTool @@ -298,6 +304,34 @@ fs::path discoverTestPath() return {}; } +boost::optional runTestSuite( + string const& _name, + fs::path const& _basePath, + fs::path const& _subdirectory, + TestCase::TestCaseCreator _testCaseCreator, + bool _formatted +) +{ + fs::path testPath = _basePath / _subdirectory; + + if (!fs::exists(testPath) || !fs::is_directory(testPath)) + { + cerr << _name << " tests not found. Use the --testpath argument." << endl; + return {}; + } + + TestStats stats = TestTool::processPath(_testCaseCreator, _basePath, _subdirectory, _formatted); + + cout << endl << _name << " Test Summary: "; + FormattedScope(cout, _formatted, {BOLD, stats ? GREEN : RED}) << + stats.successCount << + "/" << + stats.testCount; + cout << " tests successful." << endl << endl; + + return stats; +} + } int main(int argc, char *argv[]) @@ -352,53 +386,22 @@ Allowed options)", if (testPath.empty()) testPath = discoverTestPath(); - TestStats global_stats { 0, 0 }; - - fs::path syntaxTestPath = testPath / "libsolidity" / "syntaxTests"; + TestStats global_stats{0, 0}; - if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) - { - auto stats = TestTool::processPath(SyntaxTest::create, testPath / "libsolidity", "syntaxTests", formatted); - - cout << endl << "Syntax Test Summary: "; - FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << - stats.successCount << "/" << stats.testCount; - cout << " tests successful." << endl << endl; - - global_stats.testCount += stats.testCount; - global_stats.successCount += stats.successCount; - } + if (auto stats = runTestSuite("Syntax", testPath / "libsolidity", "syntaxTests", SyntaxTest::create, formatted)) + global_stats += *stats; else - { - cerr << "Syntax tests not found. Use the --testpath argument." << endl; return 1; - } - - fs::path astJsonTestPath = testPath / "libsolidity" / "ASTJSON"; - if (fs::exists(astJsonTestPath) && fs::is_directory(astJsonTestPath)) - { - auto stats = TestTool::processPath(ASTJSONTest::create, testPath / "libsolidity", "ASTJSON", formatted); - - cout << endl << "JSON AST Test Summary: "; - FormattedScope(cout, formatted, {BOLD, stats ? GREEN : RED}) << - stats.successCount << "/" << stats.testCount; - cout << " tests successful." << endl << endl; - - global_stats.testCount += stats.testCount; - global_stats.successCount += stats.successCount; - } + if (auto stats = runTestSuite("JSON AST", testPath / "libsolidity", "ASTJSON", ASTJSONTest::create, formatted)) + global_stats += *stats; else - { - cerr << "JSON AST tests not found." << endl; return 1; - } cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) << global_stats.successCount << "/" << global_stats.testCount; cout << " tests successful." << endl; - return global_stats ? 0 : 1; } -- cgit v1.2.3 From 9da62384eeac37f1709fbb53c57386b5390e72a0 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 10 Oct 2018 16:12:18 +0200 Subject: Combine test path discovery. --- test/tools/isoltest.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 5cf1d9c0..dac87d1c 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -16,6 +16,8 @@ */ #include + +#include #include #include #include @@ -47,7 +49,7 @@ struct TestStats int successCount; int testCount; operator bool() const { return successCount == testCount; } - TestStats& operator+=(TestStats const& _other) + TestStats& operator+=(TestStats const& _other) noexcept { successCount += _other.successCount; testCount += _other.testCount; @@ -285,25 +287,6 @@ void setupTerminal() #endif } -fs::path discoverTestPath() -{ - auto const searchPath = - { - fs::current_path() / ".." / ".." / ".." / "test", - fs::current_path() / ".." / ".." / "test", - fs::current_path() / ".." / "test", - fs::current_path() / "test", - fs::current_path() - }; - for (auto const& basePath: searchPath) - { - fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests"; - if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath)) - return basePath; - } - return {}; -} - boost::optional runTestSuite( string const& _name, fs::path const& _basePath, @@ -384,7 +367,7 @@ Allowed options)", } if (testPath.empty()) - testPath = discoverTestPath(); + testPath = dev::test::discoverTestPath(); TestStats global_stats{0, 0}; -- cgit v1.2.3 From 4607118d2e9bbf59707b48f177aff54ac99163b8 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 9 Oct 2018 15:43:55 +0200 Subject: Add Yul optimizer test framework. --- test/tools/isoltest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index dac87d1c..5134fe4f 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -371,6 +372,8 @@ Allowed options)", TestStats global_stats{0, 0}; + // Actually run the tests. + // If you add new tests here, you also have to add them in boostTest.cpp if (auto stats = runTestSuite("Syntax", testPath / "libsolidity", "syntaxTests", SyntaxTest::create, formatted)) global_stats += *stats; else @@ -381,6 +384,17 @@ Allowed options)", else return 1; + if (auto stats = runTestSuite( + "Yul Optimizer", + testPath / "libjulia", + "yulOptimizerTests", + julia::test::YulOptimizerTest::create, + formatted + )) + global_stats += *stats; + else + return 1; + cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) << global_stats.successCount << "/" << global_stats.testCount; -- cgit v1.2.3 From 9a4bec7e474a310c7f93ff3b84928e0e9ba9cce6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 11:52:35 +0200 Subject: Renaming libjulia to libyul --- test/tools/isoltest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index 5134fe4f..a8e2b09e 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -386,7 +386,7 @@ Allowed options)", if (auto stats = runTestSuite( "Yul Optimizer", - testPath / "libjulia", + testPath / "libyul", "yulOptimizerTests", julia::test::YulOptimizerTest::create, formatted -- cgit v1.2.3 From 1304361b9c48438d5c55903492b5f11c3dac73e5 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 15 Oct 2018 11:58:51 +0200 Subject: Renaming namespace dev::julia to dev::yul. --- test/tools/isoltest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index a8e2b09e..bdc89fb3 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -388,7 +388,7 @@ Allowed options)", "Yul Optimizer", testPath / "libyul", "yulOptimizerTests", - julia::test::YulOptimizerTest::create, + yul::test::YulOptimizerTest::create, formatted )) global_stats += *stats; -- cgit v1.2.3 From e4851cf59eed8d39a4b95e1ce8181b52e5c66d78 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 10 Oct 2018 14:31:49 +0200 Subject: [SMTChecker] Inline calls to internal functions --- test/tools/isoltest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/tools/isoltest.cpp') diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index bdc89fb3..1b6fd54a 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -328,6 +328,7 @@ int main(int argc, char *argv[]) TestTool::editor = "/usr/bin/editor"; fs::path testPath; + bool disableSMT = false; bool formatted = true; po::options_description options( R"(isoltest, tool for interactively managing test contracts. @@ -340,6 +341,7 @@ Allowed options)", options.add_options() ("help", "Show this help screen.") ("testpath", po::value(&testPath), "path to test files") + ("no-smt", "disable SMT checker") ("no-color", "don't use colors") ("editor", po::value(&TestTool::editor), "editor for opening contracts"); @@ -360,6 +362,9 @@ Allowed options)", formatted = false; po::notify(arguments); + + if (arguments.count("no-smt")) + disableSMT = true; } catch (std::exception const& _exception) { @@ -395,6 +400,20 @@ Allowed options)", else return 1; + if (!disableSMT) + { + if (auto stats = runTestSuite( + "SMT Checker", + testPath / "libsolidity", + "smtCheckerTests", + SyntaxTest::create, + formatted + )) + global_stats += *stats; + else + return 1; + } + cout << endl << "Summary: "; FormattedScope(cout, formatted, {BOLD, global_stats ? GREEN : RED}) << global_stats.successCount << "/" << global_stats.testCount; -- cgit v1.2.3