From 0c2fce579afad30d186e64329d541bfbf2a493e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 4 Aug 2023 18:48:15 +0200 Subject: [PATCH 1/4] Take into account multi-line license comments when adding preamble in test frameworks --- test/libsolidity/AnalysisFramework.cpp | 2 +- test/libsolidity/SolidityExecutionFramework.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 6c6ad0cb8..d8b6c6e9e 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -52,7 +52,7 @@ AnalysisFramework::parseAnalyseAndReturnError( { compiler().reset(); // Do not insert license if it is already present. - bool insertLicense = _insertLicenseAndVersionPragma && _source.find("// SPDX-License-Identifier:") == string::npos; + bool insertLicense = _insertLicenseAndVersionPragma && _source.find("SPDX-License-Identifier:") == string::npos; compiler().setSources({{"", string{_insertLicenseAndVersionPragma ? "pragma solidity >=0.0;\n" : ""} + string{insertLicense ? "// SPDX-License-Identifier: GPL-3.0\n" : ""} + diff --git a/test/libsolidity/SolidityExecutionFramework.cpp b/test/libsolidity/SolidityExecutionFramework.cpp index 7d18e1bb4..e578dd6ac 100644 --- a/test/libsolidity/SolidityExecutionFramework.cpp +++ b/test/libsolidity/SolidityExecutionFramework.cpp @@ -146,7 +146,7 @@ string SolidityExecutionFramework::addPreamble(string const& _sourceCode) { // Silence compiler version warning string preamble = "pragma solidity >=0.0;\n"; - if (_sourceCode.find("// SPDX-License-Identifier:") == string::npos) + if (_sourceCode.find("SPDX-License-Identifier:") == string::npos) preamble += "// SPDX-License-Identifier: unlicensed\n"; if ( solidity::test::CommonOptions::get().useABIEncoderV1 && From 18db62cf4148a095aae68ada2a5f72b43a378ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 4 Aug 2023 18:54:06 +0200 Subject: [PATCH 2/4] Unify preamble handling between test cases based on AnalysisFramework --- test/CMakeLists.txt | 2 + test/libsolidity/AnalysisFramework.cpp | 9 +--- test/libsolidity/GasTest.cpp | 4 +- test/libsolidity/SyntaxTest.cpp | 17 +------- test/libsolidity/SyntaxTest.h | 3 -- test/libsolidity/util/Common.cpp | 46 +++++++++++++++++++++ test/libsolidity/util/Common.h | 34 +++++++++++++++ test/solc/CommandLineInterface.cpp | 57 ++++++++++++-------------- test/tools/CMakeLists.txt | 1 + 9 files changed, 115 insertions(+), 58 deletions(-) create mode 100644 test/libsolidity/util/Common.cpp create mode 100644 test/libsolidity/util/Common.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a3fa84b4..1ea70fe7a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -112,6 +112,8 @@ set(libsolidity_util_sources libsolidity/util/BytesUtils.cpp libsolidity/util/BytesUtilsTests.cpp libsolidity/util/BytesUtils.h + libsolidity/util/Common.cpp + libsolidity/util/Common.h libsolidity/util/ContractABIUtils.cpp libsolidity/util/ContractABIUtils.h libsolidity/util/SoltestErrors.h diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index d8b6c6e9e..cb462b91d 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -21,6 +21,7 @@ #include +#include #include #include @@ -51,13 +52,7 @@ AnalysisFramework::parseAnalyseAndReturnError( ) { compiler().reset(); - // Do not insert license if it is already present. - bool insertLicense = _insertLicenseAndVersionPragma && _source.find("SPDX-License-Identifier:") == string::npos; - compiler().setSources({{"", - string{_insertLicenseAndVersionPragma ? "pragma solidity >=0.0;\n" : ""} + - string{insertLicense ? "// SPDX-License-Identifier: GPL-3.0\n" : ""} + - _source - }}); + compiler().setSources({{"", _insertLicenseAndVersionPragma ? withPreamble(_source) : _source}}); compiler().setEVMVersion(solidity::test::CommonOptions::get().evmVersion()); compiler().setParserErrorRecovery(_allowRecoveryErrors); _allowMultipleErrors = _allowMultipleErrors || _allowRecoveryErrors; diff --git a/test/libsolidity/GasTest.cpp b/test/libsolidity/GasTest.cpp index 0060c81e4..936c1b891 100644 --- a/test/libsolidity/GasTest.cpp +++ b/test/libsolidity/GasTest.cpp @@ -17,6 +17,7 @@ // SPDX-License-Identifier: GPL-3.0 #include +#include #include #include #include @@ -99,7 +100,6 @@ void GasTest::printUpdatedExpectations(ostream& _stream, string const& _linePref TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, bool _formatted) { - string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n"; compiler().reset(); // Prerelease CBOR metadata varies in size due to changing version numbers and build dates. // This leads to volatile creation cost estimates. Therefore we force the compiler to @@ -113,7 +113,7 @@ TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, b } settings.expectedExecutionsPerDeployment = m_optimiseRuns; compiler().setOptimiserSettings(settings); - compiler().setSources({{"", preamble + m_source}}); + compiler().setSources({{"", withPreamble(m_source)}}); if (!compiler().parseAndAnalyze() || !compiler().compile()) { diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 3efc81878..0a4793d30 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -43,24 +44,10 @@ SyntaxTest::SyntaxTest(string const& _filename, langutil::EVMVersion _evmVersion m_parserErrorRecovery = _parserErrorRecovery; } -string SyntaxTest::addPreamble(string const& _sourceCode) -{ - // Silence compiler version warning - string preamble = "pragma solidity >=0.0;\n"; - // NOTE: this check is intentionally loose to match weird cases. - // We can manually adjust a test case where this causes problem. - if (_sourceCode.find("SPDX-License-Identifier:") == string::npos) - preamble += "// SPDX-License-Identifier: GPL-3.0\n"; - return preamble + _sourceCode; -} - void SyntaxTest::setupCompiler() { compiler().reset(); - auto sourcesWithPragma = m_sources.sources; - for (auto& source: sourcesWithPragma) - source.second = addPreamble(source.second); - compiler().setSources(sourcesWithPragma); + compiler().setSources(withPreamble(m_sources.sources)); compiler().setEVMVersion(m_evmVersion); compiler().setParserErrorRecovery(m_parserErrorRecovery); compiler().setOptimiserSettings( diff --git a/test/libsolidity/SyntaxTest.h b/test/libsolidity/SyntaxTest.h index 4f47f1012..6b3be8a28 100644 --- a/test/libsolidity/SyntaxTest.h +++ b/test/libsolidity/SyntaxTest.h @@ -48,9 +48,6 @@ public: SyntaxTest(std::string const& _filename, langutil::EVMVersion _evmVersion, bool _parserErrorRecovery = false); protected: - /// Returns @param _sourceCode prefixed with the version pragma and the SPDX license identifier. - static std::string addPreamble(std::string const& _sourceCode); - virtual void setupCompiler(); void parseAndAnalyze() override; virtual void filterObtainedErrors(); diff --git a/test/libsolidity/util/Common.cpp b/test/libsolidity/util/Common.cpp new file mode 100644 index 000000000..8d065a463 --- /dev/null +++ b/test/libsolidity/util/Common.cpp @@ -0,0 +1,46 @@ +/* + 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 . +*/ +// SPDX-License-Identifier: GPL-3.0 + +#include + +using namespace std; +using namespace solidity; +using namespace solidity::frontend; + +string test::withPreamble(string const& _sourceCode) +{ + static string const versionPragma = "pragma solidity >=0.0;\n"; + static string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n"; + + // NOTE: this check is intentionally loose to match weird cases. + // We can manually adjust a test case where this causes problem. + bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == string::npos; + + return + versionPragma + + (licenseMissing ? licenseComment : "") + + _sourceCode; +} + +StringMap test::withPreamble(StringMap _sources) +{ + for (auto&& [sourceName, source]: _sources) + source = withPreamble(source); + + return _sources; +} diff --git a/test/libsolidity/util/Common.h b/test/libsolidity/util/Common.h new file mode 100644 index 000000000..d03036078 --- /dev/null +++ b/test/libsolidity/util/Common.h @@ -0,0 +1,34 @@ +/* + 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 . +*/ +// SPDX-License-Identifier: GPL-3.0 + +/// Utilities shared by multiple libsolidity tests. + +#include + +#include + +namespace solidity::frontend::test +{ + +/// @returns @p _sourceCode prefixed with the version pragma and the SPDX license identifier. +std::string withPreamble(std::string const& _sourceCode); + +/// @returns a copy of @p _sources with preamble prepended to all sources. +StringMap withPreamble(StringMap _sources); + +} // namespace solidity::frontend::test diff --git a/test/solc/CommandLineInterface.cpp b/test/solc/CommandLineInterface.cpp index 8124b1545..7732faf38 100644 --- a/test/solc/CommandLineInterface.cpp +++ b/test/solc/CommandLineInterface.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -921,10 +922,7 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME); TemporaryWorkingDirectory tempWorkDir(tempDir); - string const preamble = - "// SPDX-License-Identifier: GPL-3.0\n" - "pragma solidity >=0.0;\n"; - string const mainContractSource = preamble + + string const mainContractSource = withPreamble( "import \"contract.sol\";\n" "import \"contract_via_callback.sol\";\n" "import \"include.sol\";\n" @@ -932,8 +930,10 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) "import \"nested.sol\";\n" "import \"nested_via_callback.sol\";\n" "import \"lib.sol\";\n" - "import \"lib_via_callback.sol\";\n"; + "import \"lib_via_callback.sol\";\n" + ); + string const onlyPreamble = withPreamble(""); createFilesWithParentDirs( { tempDir.path() / "base/contract.sol", @@ -945,7 +945,7 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) tempDir.path() / "lib/lib.sol", tempDir.path() / "lib/lib_via_callback.sol", }, - preamble + onlyPreamble ); createFilesWithParentDirs({tempDir.path() / "base/main.sol"}, mainContractSource); @@ -985,14 +985,14 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) map expectedSources = { {"main.sol", mainContractSource}, - {"contract.sol", preamble}, - {"contract_via_callback.sol", preamble}, - {"include.sol", preamble}, - {"include_via_callback.sol", preamble}, - {"nested.sol", preamble}, - {"nested_via_callback.sol", preamble}, - {"lib.sol", preamble}, - {"lib_via_callback.sol", preamble}, + {"contract.sol", onlyPreamble}, + {"contract_via_callback.sol", onlyPreamble}, + {"include.sol", onlyPreamble}, + {"include_via_callback.sol", onlyPreamble}, + {"nested.sol", onlyPreamble}, + {"nested_via_callback.sol", onlyPreamble}, + {"lib.sol", onlyPreamble}, + {"lib_via_callback.sol", onlyPreamble}, }; vector expectedIncludePaths = { @@ -1066,14 +1066,12 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths) TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME); TemporaryWorkingDirectory tempWorkDir(tempDir); - string const preamble = - "// SPDX-License-Identifier: GPL-3.0\n" - "pragma solidity >=0.0;\n"; - string const mainContractSource = preamble + + string const mainContractSource = withPreamble( "import 'contract_via_callback.sol';\n" "import 'include_via_callback.sol';\n" "import 'nested_via_callback.sol';\n" - "import 'lib_via_callback.sol';\n"; + "import 'lib_via_callback.sol';\n" + ); string const standardJsonInput = R"( { @@ -1084,6 +1082,7 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths) } )"; + string const onlyPreamble = withPreamble(""); createFilesWithParentDirs( { tempDir.path() / "base/contract_via_callback.sol", @@ -1091,7 +1090,7 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths) tempDir.path() / "lib/nested/nested_via_callback.sol", tempDir.path() / "lib/lib_via_callback.sol", }, - preamble + onlyPreamble ); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::canonical(tempDir).relative_path(); @@ -1121,10 +1120,10 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths) // because FileReader is only used once to initialize the compiler stack and after that // its sources are irrelevant (even though the callback still stores everything it loads). map expectedSources = { - {"contract_via_callback.sol", preamble}, - {"include_via_callback.sol", preamble}, - {"nested_via_callback.sol", preamble}, - {"lib_via_callback.sol", preamble}, + {"contract_via_callback.sol", onlyPreamble}, + {"include_via_callback.sol", onlyPreamble}, + {"nested_via_callback.sol", onlyPreamble}, + {"lib_via_callback.sol", onlyPreamble}, }; vector expectedIncludePaths = { @@ -1335,14 +1334,10 @@ BOOST_AUTO_TEST_CASE(cli_include_paths_ambiguous_import) TemporaryDirectory tempDir({"base/", "include/"}, TEST_CASE_NAME); TemporaryWorkingDirectory tempWorkDir(tempDir); - string const preamble = - "// SPDX-License-Identifier: GPL-3.0\n" - "pragma solidity >=0.0;\n"; - string const mainContractSource = preamble + - // Ambiguous: both base/contract.sol and include/contract.sol match the import. - "import \"contract.sol\";"; + // Ambiguous: both base/contract.sol and include/contract.sol match the import. + string const mainContractSource = withPreamble("import \"contract.sol\";"); - createFilesWithParentDirs({"base/contract.sol", "include/contract.sol"}, preamble); + createFilesWithParentDirs({"base/contract.sol", "include/contract.sol"}, withPreamble("")); boost::filesystem::path expectedWorkDir = "/" / boost::filesystem::canonical(tempDir).relative_path(); diff --git a/test/tools/CMakeLists.txt b/test/tools/CMakeLists.txt index 5a2ba8da3..d5a95676d 100644 --- a/test/tools/CMakeLists.txt +++ b/test/tools/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(isoltest ../TestCase.cpp ../TestCaseReader.cpp ../libsolidity/util/BytesUtils.cpp + ../libsolidity/util/Common.cpp ../libsolidity/util/ContractABIUtils.cpp ../libsolidity/util/TestFileParser.cpp ../libsolidity/util/TestFunctionCall.cpp From ec92685bcb6b7c9a452ea8c436c916ad0747431d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 11 Aug 2023 14:43:37 +0200 Subject: [PATCH 3/4] Unify preamble handling between AnalysisFramework and SolidityExecutionFramework --- .../SolidityExecutionFramework.cpp | 24 ++++--------------- test/libsolidity/SolidityExecutionFramework.h | 3 --- test/libsolidity/util/Common.cpp | 13 ++++++---- test/libsolidity/util/Common.h | 5 ++-- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/test/libsolidity/SolidityExecutionFramework.cpp b/test/libsolidity/SolidityExecutionFramework.cpp index e578dd6ac..7b79def1e 100644 --- a/test/libsolidity/SolidityExecutionFramework.cpp +++ b/test/libsolidity/SolidityExecutionFramework.cpp @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -48,12 +49,12 @@ bytes SolidityExecutionFramework::multiSourceCompileContract( { if (_mainSourceName.has_value()) solAssert(_sourceCode.find(_mainSourceName.value()) != _sourceCode.end(), ""); - map sourcesWithPreamble = _sourceCode; - for (auto& entry: sourcesWithPreamble) - entry.second = addPreamble(entry.second); m_compiler.reset(); - m_compiler.setSources(sourcesWithPreamble); + m_compiler.setSources(withPreamble( + _sourceCode, + solidity::test::CommonOptions::get().useABIEncoderV1 // _addAbicoderV1Pragma + )); m_compiler.setLibraries(_libraryAddresses); m_compiler.setRevertStringBehaviour(m_revertStrings); m_compiler.setEVMVersion(m_evmVersion); @@ -141,18 +142,3 @@ bytes SolidityExecutionFramework::compileContract( _libraryAddresses ); } - -string SolidityExecutionFramework::addPreamble(string const& _sourceCode) -{ - // Silence compiler version warning - string preamble = "pragma solidity >=0.0;\n"; - if (_sourceCode.find("SPDX-License-Identifier:") == string::npos) - preamble += "// SPDX-License-Identifier: unlicensed\n"; - if ( - solidity::test::CommonOptions::get().useABIEncoderV1 && - _sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos && - _sourceCode.find("pragma abicoder") == string::npos - ) - preamble += "pragma abicoder v1;\n"; - return preamble + _sourceCode; -} diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index c2cea6600..f91ba758f 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -79,9 +79,6 @@ public: std::map const& _libraryAddresses = {} ); - /// Returns @param _sourceCode prefixed with the version pragma and the abi coder v1 pragma, - /// the latter only if it is forced. - static std::string addPreamble(std::string const& _sourceCode); protected: using CompilerStack = solidity::frontend::CompilerStack; std::optional m_eofVersion; diff --git a/test/libsolidity/util/Common.cpp b/test/libsolidity/util/Common.cpp index 8d065a463..5ed6901f4 100644 --- a/test/libsolidity/util/Common.cpp +++ b/test/libsolidity/util/Common.cpp @@ -22,25 +22,30 @@ using namespace std; using namespace solidity; using namespace solidity::frontend; -string test::withPreamble(string const& _sourceCode) +string test::withPreamble(string const& _sourceCode, bool _addAbicoderV1Pragma) { static string const versionPragma = "pragma solidity >=0.0;\n"; static string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n"; + static string const abicoderPragma = "pragma abicoder v1;\n"; - // NOTE: this check is intentionally loose to match weird cases. + // NOTE: These checks are intentionally loose to match weird cases. // We can manually adjust a test case where this causes problem. bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == string::npos; + bool abicoderMissing = + _sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos && + _sourceCode.find("pragma abicoder") == string::npos; return versionPragma + (licenseMissing ? licenseComment : "") + + (abicoderMissing && _addAbicoderV1Pragma ? abicoderPragma : "") + _sourceCode; } -StringMap test::withPreamble(StringMap _sources) +StringMap test::withPreamble(StringMap _sources, bool _addAbicoderV1Pragma) { for (auto&& [sourceName, source]: _sources) - source = withPreamble(source); + source = withPreamble(source, _addAbicoderV1Pragma); return _sources; } diff --git a/test/libsolidity/util/Common.h b/test/libsolidity/util/Common.h index d03036078..a424d92d9 100644 --- a/test/libsolidity/util/Common.h +++ b/test/libsolidity/util/Common.h @@ -26,9 +26,10 @@ namespace solidity::frontend::test { /// @returns @p _sourceCode prefixed with the version pragma and the SPDX license identifier. -std::string withPreamble(std::string const& _sourceCode); +/// Can optionally also insert an abicoder pragma when missing. +std::string withPreamble(std::string const& _sourceCode, bool _addAbicoderV1Pragma = false); /// @returns a copy of @p _sources with preamble prepended to all sources. -StringMap withPreamble(StringMap _sources); +StringMap withPreamble(StringMap _sources, bool _addAbicoderV1Pragma = false); } // namespace solidity::frontend::test From 2baf9d4d8261395d837c6f96d6779a4f026d0bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 11 Aug 2023 14:54:22 +0200 Subject: [PATCH 4/4] Put stripPreReleaseWarning() next to withPreamble() --- test/libsolidity/util/Common.cpp | 16 ++++++++++++++++ test/libsolidity/util/Common.h | 2 ++ test/solc/Common.cpp | 15 +-------------- test/solc/Common.h | 2 -- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/test/libsolidity/util/Common.cpp b/test/libsolidity/util/Common.cpp index 5ed6901f4..e5dddb721 100644 --- a/test/libsolidity/util/Common.cpp +++ b/test/libsolidity/util/Common.cpp @@ -18,6 +18,8 @@ #include +#include + using namespace std; using namespace solidity; using namespace solidity::frontend; @@ -49,3 +51,17 @@ StringMap test::withPreamble(StringMap _sources, bool _addAbicoderV1Pragma) return _sources; } + +string test::stripPreReleaseWarning(string const& _stderrContent) +{ + static regex const preReleaseWarningRegex{ + R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)" + R"((\n)?)" + }; + static regex const noOutputRegex{ + R"(Compiler run successful, no output requested\.\n)" + }; + + string output = regex_replace(_stderrContent, preReleaseWarningRegex, ""); + return regex_replace(std::move(output), noOutputRegex, ""); +} diff --git a/test/libsolidity/util/Common.h b/test/libsolidity/util/Common.h index a424d92d9..3f1750a66 100644 --- a/test/libsolidity/util/Common.h +++ b/test/libsolidity/util/Common.h @@ -32,4 +32,6 @@ std::string withPreamble(std::string const& _sourceCode, bool _addAbicoderV1Prag /// @returns a copy of @p _sources with preamble prepended to all sources. StringMap withPreamble(StringMap _sources, bool _addAbicoderV1Pragma = false); +std::string stripPreReleaseWarning(std::string const& _stderrContent); + } // namespace solidity::frontend::test diff --git a/test/solc/Common.cpp b/test/solc/Common.cpp index 8e2e329e4..24acd6b6c 100644 --- a/test/solc/Common.cpp +++ b/test/solc/Common.cpp @@ -17,6 +17,7 @@ // SPDX-License-Identifier: GPL-3.0 #include +#include #include @@ -79,17 +80,3 @@ test::OptionsReaderAndMessages test::runCLI( stripPreReleaseWarning(serr.str()), }; } - -string test::stripPreReleaseWarning(string const& _stderrContent) -{ - static regex const preReleaseWarningRegex{ - R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)" - R"((\n)?)" - }; - static regex const noOutputRegex{ - R"(Compiler run successful, no output requested\.\n)" - }; - - string output = regex_replace(_stderrContent, preReleaseWarningRegex, ""); - return regex_replace(std::move(output), noOutputRegex, ""); -} diff --git a/test/solc/Common.h b/test/solc/Common.h index 69131bf2c..e2ddee691 100644 --- a/test/solc/Common.h +++ b/test/solc/Common.h @@ -67,6 +67,4 @@ OptionsReaderAndMessages runCLI( std::string const& _standardInputContent = "" ); -std::string stripPreReleaseWarning(std::string const& _stderrContent); - } // namespace solidity::frontend::test