2023-08-04 16:54:06 +00:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
#include <test/libsolidity/util/Common.h>
|
|
|
|
|
2023-08-11 12:54:22 +00:00
|
|
|
#include <regex>
|
|
|
|
|
2023-08-04 16:54:06 +00:00
|
|
|
using namespace solidity;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
|
2023-10-02 11:25:16 +00:00
|
|
|
std::string test::withPreamble(std::string const& _sourceCode, bool _addAbicoderV1Pragma)
|
2023-08-04 16:54:06 +00:00
|
|
|
{
|
2023-10-02 11:25:16 +00:00
|
|
|
static std::string const versionPragma = "pragma solidity >=0.0;\n";
|
|
|
|
static std::string const licenseComment = "// SPDX-License-Identifier: GPL-3.0\n";
|
|
|
|
static std::string const abicoderPragma = "pragma abicoder v1;\n";
|
2023-08-04 16:54:06 +00:00
|
|
|
|
2023-08-11 12:43:37 +00:00
|
|
|
// NOTE: These checks are intentionally loose to match weird cases.
|
2023-08-04 16:54:06 +00:00
|
|
|
// We can manually adjust a test case where this causes problem.
|
2023-10-02 11:25:16 +00:00
|
|
|
bool licenseMissing = _sourceCode.find("SPDX-License-Identifier:") == std::string::npos;
|
2023-08-11 12:43:37 +00:00
|
|
|
bool abicoderMissing =
|
2023-10-02 11:25:16 +00:00
|
|
|
_sourceCode.find("pragma experimental ABIEncoderV2;") == std::string::npos &&
|
|
|
|
_sourceCode.find("pragma abicoder") == std::string::npos;
|
2023-08-04 16:54:06 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
versionPragma +
|
|
|
|
(licenseMissing ? licenseComment : "") +
|
2023-08-11 12:43:37 +00:00
|
|
|
(abicoderMissing && _addAbicoderV1Pragma ? abicoderPragma : "") +
|
2023-08-04 16:54:06 +00:00
|
|
|
_sourceCode;
|
|
|
|
}
|
|
|
|
|
2023-08-11 12:43:37 +00:00
|
|
|
StringMap test::withPreamble(StringMap _sources, bool _addAbicoderV1Pragma)
|
2023-08-04 16:54:06 +00:00
|
|
|
{
|
|
|
|
for (auto&& [sourceName, source]: _sources)
|
2023-08-11 12:43:37 +00:00
|
|
|
source = withPreamble(source, _addAbicoderV1Pragma);
|
2023-08-04 16:54:06 +00:00
|
|
|
|
|
|
|
return _sources;
|
|
|
|
}
|
2023-08-11 12:54:22 +00:00
|
|
|
|
2023-10-02 11:25:16 +00:00
|
|
|
std::string test::stripPreReleaseWarning(std::string const& _stderrContent)
|
2023-08-11 12:54:22 +00:00
|
|
|
{
|
2023-10-02 11:25:16 +00:00
|
|
|
static std::regex const preReleaseWarningRegex{
|
2023-08-11 12:54:22 +00:00
|
|
|
R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)"
|
|
|
|
R"((\n)?)"
|
|
|
|
};
|
2023-10-02 11:25:16 +00:00
|
|
|
static std::regex const noOutputRegex{
|
2023-08-11 12:54:22 +00:00
|
|
|
R"(Compiler run successful, no output requested\.\n)"
|
|
|
|
};
|
|
|
|
|
2023-10-02 11:25:16 +00:00
|
|
|
std::string output = std::regex_replace(_stderrContent, preReleaseWarningRegex, "");
|
|
|
|
return std::regex_replace(std::move(output), noOutputRegex, "");
|
2023-08-11 12:54:22 +00:00
|
|
|
}
|