Do not insert SPDX identifier if already present in SyntaxTest

This commit is contained in:
Alex Beregszaszi 2020-12-18 14:51:30 +00:00 committed by Kamil Śliwak
parent 5bbb017915
commit 6f1f0c5bbc
4 changed files with 18 additions and 3 deletions

View File

@ -51,13 +51,23 @@ TestCase::TestResult SyntaxTest::run(ostream& _stream, string const& _linePrefix
return conclude(_stream, _linePrefix, _formatted);
}
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()
{
string const preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: GPL-3.0\n";
compiler().reset();
auto sourcesWithPragma = m_sources;
for (auto& source: sourcesWithPragma)
source.second = preamble + source.second;
source.second = addPreamble(source.second);
compiler().setSources(sourcesWithPragma);
compiler().setEVMVersion(m_evmVersion);
compiler().setParserErrorRecovery(m_parserErrorRecovery);

View File

@ -50,6 +50,9 @@ public:
TestResult run(std::ostream& _stream, std::string const& _linePrefix = "", bool _formatted = false) override;
protected:
/// Returns @param _sourceCode prefixed with the version pragma and the SPDX license identifier.
static std::string addPreamble(std::string const& _sourceCode);
void setupCompiler();
void parseAndAnalyze() override;
virtual void filterObtainedErrors();

View File

@ -1 +1,2 @@
// This test is actually useless, as the test suite adds the automatic preamble.
contract C {}

View File

@ -1,3 +1,4 @@
// This is just ignored:
// SPDX-License-Identifier:
contract C {}
// ----
// Warning 1878: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.