From 3232561d979954f0625102d33cf042fc5eda7211 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 12 Mar 2018 13:33:37 +0100 Subject: Refactoring; fuse SyntaxTestParser and SyntaxTester to SyntaxTest. --- test/libsolidity/SyntaxTest.h | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/libsolidity/SyntaxTest.h (limited to 'test/libsolidity/SyntaxTest.h') diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h new file mode 100644 index 00000000..4379c77b --- /dev/null +++ b/test/libsolidity/SyntaxTest.h @@ -0,0 +1,77 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ + +#pragma once + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace dev +{ +namespace solidity +{ +namespace test +{ + +struct SyntaxTestExpectation +{ + std::string type; + std::string message; +}; + + +class SyntaxTest: AnalysisFramework +{ +public: + SyntaxTest(std::string const& _filename); + + bool run(std::ostream& _stream, std::string const& _indent); + + void printExpected(std::ostream& _stream, std::string const& _indent) const; + void printErrorList( + std::ostream& _stream, + ErrorList const& _errors, + std::string const& _indent + ) const; + + static int registerTests( + boost::unit_test::test_suite& _suite, + boost::filesystem::path const& _basepath, + boost::filesystem::path const& _path + ); +private: + bool matchesExpectations(ErrorList const& _errors) const; + static std::string errorMessage(Error const& _e); + static std::string parseSource(std::istream& _stream); + static std::vector parseExpectations(std::istream& _stream); + + std::string m_source; + std::vector m_expectations; + ErrorList m_errorList; +}; + +} +} +} -- cgit v1.2.3 From 269241e9105a3b3014002bf711ade985d87febe4 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 12 Mar 2018 13:57:48 +0100 Subject: Add formatted printing to SyntaxTest and expand its public interface. --- test/libsolidity/SyntaxTest.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/SyntaxTest.h') diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index 4379c77b..441cc4f8 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include #include @@ -47,13 +48,22 @@ class SyntaxTest: AnalysisFramework public: SyntaxTest(std::string const& _filename); - bool run(std::ostream& _stream, std::string const& _indent); + bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false); + + std::vector const& expectations() const { return m_expectations; } + std::string const& source() const { return m_source; } + ErrorList const& errorList() const { return m_errorList; } + ErrorList const& compilerErrors() const { return m_compiler.errors(); } + + void printExpected(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted = false) const; - void printExpected(std::ostream& _stream, std::string const& _indent) const; void printErrorList( std::ostream& _stream, ErrorList const& _errors, - std::string const& _indent + std::string const& _linePrefix, + bool const _ignoreWarnings, + bool const _lineNumbers, + bool const _formatted = false ) const; static int registerTests( @@ -66,6 +76,7 @@ private: static std::string errorMessage(Error const& _e); static std::string parseSource(std::istream& _stream); static std::vector parseExpectations(std::istream& _stream); + int offsetToLineNumber(int _location) const; std::string m_source; std::vector m_expectations; -- cgit v1.2.3 From e68c19c47b03eebb9af528bf2b03bb0086484c63 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 16 Mar 2018 11:40:03 +0100 Subject: Only consider files ending with .sol and not starting with ~ in syntax tests. --- test/libsolidity/SyntaxTest.h | 1 + 1 file changed, 1 insertion(+) (limited to 'test/libsolidity/SyntaxTest.h') diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index 441cc4f8..cb6ee05c 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -71,6 +71,7 @@ public: boost::filesystem::path const& _basepath, boost::filesystem::path const& _path ); + static bool isTestFilename(boost::filesystem::path const& _filename); private: bool matchesExpectations(ErrorList const& _errors) const; static std::string errorMessage(Error const& _e); -- cgit v1.2.3 From 6f9644add18b27363a423e2c7ccb0e578ba800bc Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 3 Apr 2018 12:05:26 +0200 Subject: SyntaxTests: extend syntax tests and isoltest to support parser errors and compiler exceptions. --- test/libsolidity/SyntaxTest.h | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'test/libsolidity/SyntaxTest.h') diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index cb6ee05c..dddd86ef 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -36,10 +36,14 @@ namespace solidity namespace test { -struct SyntaxTestExpectation +struct SyntaxTestError { std::string type; std::string message; + bool operator==(SyntaxTestError const& _rhs) const + { + return type == _rhs.type && message == _rhs.message; + } }; @@ -50,21 +54,16 @@ public: bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false); - std::vector const& expectations() const { return m_expectations; } + std::vector const& expectations() const { return m_expectations; } std::string const& source() const { return m_source; } - ErrorList const& errorList() const { return m_errorList; } - ErrorList const& compilerErrors() const { return m_compiler.errors(); } + std::vector const& errorList() const { return m_errorList; } - void printExpected(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted = false) const; - - void printErrorList( + static void printErrorList( std::ostream& _stream, - ErrorList const& _errors, + std::vector const& _errors, std::string const& _linePrefix, - bool const _ignoreWarnings, - bool const _lineNumbers, bool const _formatted = false - ) const; + ); static int registerTests( boost::unit_test::test_suite& _suite, @@ -72,16 +71,14 @@ public: boost::filesystem::path const& _path ); static bool isTestFilename(boost::filesystem::path const& _filename); + static std::string errorMessage(Exception const& _e); private: - bool matchesExpectations(ErrorList const& _errors) const; - static std::string errorMessage(Error const& _e); static std::string parseSource(std::istream& _stream); - static std::vector parseExpectations(std::istream& _stream); - int offsetToLineNumber(int _location) const; + static std::vector parseExpectations(std::istream& _stream); std::string m_source; - std::vector m_expectations; - ErrorList m_errorList; + std::vector m_expectations; + std::vector m_errorList; }; } -- cgit v1.2.3 From f03695731b9b36cd4014620b7b63556a69b4e952 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 6 Apr 2018 18:37:01 +0200 Subject: Add source locations to syntax test expectations. --- test/libsolidity/SyntaxTest.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/SyntaxTest.h') diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index dddd86ef..6159e789 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -40,9 +40,14 @@ struct SyntaxTestError { std::string type; std::string message; + int locationStart; + int locationEnd; bool operator==(SyntaxTestError const& _rhs) const { - return type == _rhs.type && message == _rhs.message; + return type == _rhs.type && + message == _rhs.message && + locationStart == _rhs.locationStart && + locationEnd == _rhs.locationEnd; } }; -- cgit v1.2.3