diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 4848d7569..c901e7a2a 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -5,6 +5,8 @@ EXCLUDE_FILES=( "libsolutil/picosha2.h" "test/libsolutil/UTF8.cpp" + "test/libsolidity/syntaxTests/license/license_cr_endings.sol" + "test/libsolidity/syntaxTests/license/license_crlf_endings.sol" "test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol" ) EXCLUDE_FILES_JOINED=$(printf "%s\|" "${EXCLUDE_FILES[@]}") diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp index aa88b2240..a82199b59 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -432,6 +432,124 @@ BOOST_AUTO_TEST_CASE(metadata_license_ignored_stray_unicode) BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); } +BOOST_AUTO_TEST_CASE(metadata_license_bidi_marks) +{ + char const* sourceCode = + "// \xE2\x80\xAE""0.3-LPG :reifitnedI-esneciL-XDPS\xE2\x80\xAC\n" + "// NOTE: The text above is reversed using Unicode directional marks. In raw form it would look like this:\n" + "// 0.3-LPG :reifitnedI-esneciL-XDPS\n" + "contract C {}\n"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt); +} + +BOOST_AUTO_TEST_CASE(metadata_license_bottom) +{ + char const* sourceCode = R"( + contract C {} + // SPDX-License-Identifier: GPL-3.0 + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); +} + +BOOST_AUTO_TEST_CASE(metadata_cr_endings) +{ + char const* sourceCode = + "// SPDX-License-Identifier: GPL-3.0\r" + "contract C {}\r"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); +} + +BOOST_AUTO_TEST_CASE(metadata_crlf_endings) +{ + char const* sourceCode = + "// SPDX-License-Identifier: GPL-3.0\r\n" + "contract C {}\r\n"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); +} + +BOOST_AUTO_TEST_CASE(metadata_license_in_string) +{ + char const* sourceCode = R"( + contract C { + bytes license = "// SPDX-License-Identifier: GPL-3.0"; + } + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt); +} + +BOOST_AUTO_TEST_CASE(metadata_license_in_contract) +{ + char const* sourceCode = R"( + contract C { + // SPDX-License-Identifier: GPL-3.0 + } + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt); +} + +BOOST_AUTO_TEST_CASE(metadata_license_missing_colon) +{ + char const* sourceCode = R"( + // SPDX-License-Identifier GPL-3.0 + contract C {} + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == nullopt); +} + +BOOST_AUTO_TEST_CASE(metadata_license_multiline) +{ + 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_natspec) +{ + 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_natspec_multiline) +{ + 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) +{ + 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"( + /*SPDX-License-Identifier:GPL-3.0*/ + contract C {} + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); +} + +BOOST_AUTO_TEST_CASE(metadata_license_nonempty_line) +{ + char const* sourceCode = R"( + pragma solidity >= 0.0; // SPDX-License-Identifier: GPL-3.0 + contract C {} + )"; + BOOST_CHECK(compileAndCheckLicenseMetadata("C", sourceCode) == "GPL-3.0"); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/syntaxTests/license/license_bidi_marks.sol b/test/libsolidity/syntaxTests/license/license_bidi_marks.sol new file mode 100644 index 000000000..12c88861d --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_bidi_marks.sol @@ -0,0 +1,5 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +// ‮0.3-LPG :reifitnedI-esneciL-XDPS‬ +// NOTE: The text above is reversed using Unicode directional marks. In raw form it would look like this: +// 0.3-LPG :reifitnedI-esneciL-XDPS +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_bottom.sol b/test/libsolidity/syntaxTests/license/license_bottom.sol new file mode 100644 index 000000000..6a7e5016e --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_bottom.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +contract C {} +// SPDX-License-Identifier: GPL-3.0 diff --git a/test/libsolidity/syntaxTests/license/license_cr_endings.sol b/test/libsolidity/syntaxTests/license/license_cr_endings.sol new file mode 100644 index 000000000..a844d80a9 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_cr_endings.sol @@ -0,0 +1 @@ +// This test is actually useless, as the test suite adds the automatic preamble. // SPDX-License-Identifier: GPL-3.0 contract C {} \ No newline at end of file diff --git a/test/libsolidity/syntaxTests/license/license_crlf_endings.sol b/test/libsolidity/syntaxTests/license/license_crlf_endings.sol new file mode 100644 index 000000000..8e83125ee --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_crlf_endings.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +// SPDX-License-Identifier: GPL-3.0 +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_in_contract.sol b/test/libsolidity/syntaxTests/license/license_in_contract.sol new file mode 100644 index 000000000..8318fbd80 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_in_contract.sol @@ -0,0 +1,5 @@ +contract C { +// SPDX-License-Identifier: GPL-3.0 +} +// ---- +// Warning 1878: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information. diff --git a/test/libsolidity/syntaxTests/license/license_in_import.sol b/test/libsolidity/syntaxTests/license/license_in_import.sol new file mode 100644 index 000000000..e31d49aa7 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_in_import.sol @@ -0,0 +1,5 @@ +import "// SPDX-License-Identifier: GPL-3.0"; +contract C {} +// ---- +// Warning 1878: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information. +// ParserError 6275: (0-45): Source "// SPDX-License-Identifier: GPL-3.0" not found: File not supplied initially. diff --git a/test/libsolidity/syntaxTests/license/license_in_string.sol b/test/libsolidity/syntaxTests/license/license_in_string.sol new file mode 100644 index 000000000..5db1c6f66 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_in_string.sol @@ -0,0 +1,5 @@ +contract C { + bytes license = "// SPDX-License-Identifier: GPL-3.0"; +} +// ---- +// Warning 1878: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information. diff --git a/test/libsolidity/syntaxTests/license/license_missing_colon.sol b/test/libsolidity/syntaxTests/license/license_missing_colon.sol new file mode 100644 index 000000000..0212093a1 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_missing_colon.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +// SPDX-License-Identifier GPL-3.0 +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_multiline.sol b/test/libsolidity/syntaxTests/license/license_multiline.sol new file mode 100644 index 000000000..026c47a83 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_multiline.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +/* SPDX-License-Identifier: GPL-3.0 */ +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_natspec.sol b/test/libsolidity/syntaxTests/license/license_natspec.sol index 3b6a40778..2717b0ca0 100644 --- a/test/libsolidity/syntaxTests/license/license_natspec.sol +++ b/test/libsolidity/syntaxTests/license/license_natspec.sol @@ -1,2 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. /// SPDX-License-Identifier: GPL-3.0 contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_natspec_multiline.sol b/test/libsolidity/syntaxTests/license/license_natspec_multiline.sol new file mode 100644 index 000000000..77b0daf93 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_natspec_multiline.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +/** SPDX-License-Identifier: GPL-3.0 */ +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_no_whitespace.sol b/test/libsolidity/syntaxTests/license/license_no_whitespace.sol new file mode 100644 index 000000000..d69215ee4 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_no_whitespace.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +//SPDX-License-Identifier:GPL-3.0 +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_no_whitespace_multiline.sol b/test/libsolidity/syntaxTests/license/license_no_whitespace_multiline.sol new file mode 100644 index 000000000..782ad5d5b --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_no_whitespace_multiline.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +/*SPDX-License-Identifier:GPL-3.0*/ +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_nonempty_line.sol b/test/libsolidity/syntaxTests/license/license_nonempty_line.sol new file mode 100644 index 000000000..43659d595 --- /dev/null +++ b/test/libsolidity/syntaxTests/license/license_nonempty_line.sol @@ -0,0 +1,3 @@ +// This test is actually useless, as the test suite adds the automatic preamble. +pragma solidity >= 0.0; // SPDX-License-Identifier: GPL-3.0 +contract C {} diff --git a/test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol b/test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol index 96d8f572c..24903ce48 100644 --- a/test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol +++ b/test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol @@ -1,2 +1,3 @@ // SPDX-License-Identifier: GPL-3.0 +// NOTE: Trailing space at the end of the line above is intentional. contract C {}