Merge pull request #11888 from ethereum/spdx-license-handling-10145

Properly detect multiple licenses and validate them.
This commit is contained in:
chriseth
2021-09-16 14:18:17 +02:00
committed by GitHub
12 changed files with 68 additions and 46 deletions
+9 -31
View File
@@ -457,28 +457,6 @@ BOOST_AUTO_TEST_CASE(metadata_license_gpl3_or_apache2)
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0 OR Apache-2.0");
}
BOOST_AUTO_TEST_CASE(metadata_license_ignored_unicode)
{
char const* sourceCode = R"(
// SPDX-License-Identifier: ⡉⡊⡋⡌⡍⡎⡏⡐⡑⡒
pragma solidity >=0.0;
contract C {
}
)";
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt);
}
BOOST_AUTO_TEST_CASE(metadata_license_ignored_stray_unicode)
{
char const* sourceCode = R"(
// SPDX-License-Identifier: GPL-3.0 ⡉⡊⡋⡌⡍⡎⡏⡐⡑⡒
pragma solidity >=0.0;
contract C {
}
)";
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0");
}
BOOST_AUTO_TEST_CASE(metadata_license_bidi_marks)
{
char const* sourceCode =
@@ -570,15 +548,6 @@ BOOST_AUTO_TEST_CASE(metadata_license_natspec_multiline)
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0");
}
BOOST_AUTO_TEST_CASE(metadata_license_no_whitespace)
{
char const* sourceCode = R"(
//SPDX-License-Identifier:GPL-3.0
contract C {}
)";
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0");
}
BOOST_AUTO_TEST_CASE(metadata_license_no_whitespace_multiline)
{
char const* sourceCode = R"(
@@ -597,6 +566,15 @@ BOOST_AUTO_TEST_CASE(metadata_license_nonempty_line)
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0");
}
BOOST_AUTO_TEST_CASE(metadata_license_no_whitespace)
{
char const* sourceCode = R"(
//SPDX-License-Identifier:GPL-3.0
contract C {}
)";
BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0");
}
BOOST_AUTO_TEST_SUITE_END()
}
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: GPL-3.0 AND GPL-2.0
contract C {}
// ----
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: GPL-3.0 OR GPL-2.0
contract C {}
// ----
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: MIT
contract C {}
// ----
// ParserError 3716: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GPL-3.0
contract C {}
// ----
// ParserError 3716: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.
@@ -0,0 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0 OR GPL-2.0
SPDX-License-Identifier: GPL-3.0 OR GPL-2.0 */
contract C {}
// ----
// ParserError 3716: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.
@@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-3.0 OR GPL-2.0 */ /* SPDX-License-Identifier: GPL-3.0 OR GPL-2.0 */
contract C {}
// ----
// ParserError 3716: Multiple SPDX license identifiers found in source file. Use "AND" or "OR" to combine multiple licenses. Please see https://spdx.org for more information.
@@ -1,4 +1,4 @@
// This is parsed as GPL-3.0:
// SPDX-License-Identifier: GPL-3.0 ⡉⡊⡋⡌⡍⡎⡏⡐⡑⡒
contract C {}
// ----
// ParserError 1114: Invalid SPDX license identifier.
@@ -1,4 +1,4 @@
// 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.
// ParserError 1114: Invalid SPDX license identifier.