Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed Oct 13, 2023
1 parent e2ea3fa commit 8441a4b
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/cmdlineTests/no_import_callback/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-import-callback no_import_callback/contract_1.sol
6 changes: 6 additions & 0 deletions test/cmdlineTests/no_import_callback/contract_1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

import "contract_2.sol";

contract A {}
4 changes: 4 additions & 0 deletions test/cmdlineTests/no_import_callback/contract_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

contract B {}
5 changes: 5 additions & 0 deletions test/cmdlineTests/no_import_callback/err
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: Source "contract_2.sol" not found: File reader callback is disabled.
--> no_import_callback/contract_1.sol:4:1:
|
4 | import "contract_2.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^
1 change: 1 addition & 0 deletions test/cmdlineTests/no_import_callback/exit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
4 changes: 4 additions & 0 deletions test/cmdlineTests/standard_no_import_callback/B.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

contract B {}
1 change: 1 addition & 0 deletions test/cmdlineTests/standard_no_import_callback/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--no-import-callback
10 changes: 10 additions & 0 deletions test/cmdlineTests/standard_no_import_callback/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;\nimport \"B.sol\"; contract A {}"
}
}
}
26 changes: 26 additions & 0 deletions test/cmdlineTests/standard_no_import_callback/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"errors":
[
{
"component": "general",
"errorCode": "6275",
"formattedMessage": "ParserError: Source \"B.sol\" not found: File reader callback is disabled.
--> A:3:1:
|
3 | import \"B.sol\"; contract A {}
| ^^^^^^^^^^^^^^^

",
"message": "Source \"B.sol\" not found: File reader callback is disabled.",
"severity": "error",
"sourceLocation":
{
"end": 74,
"file": "A",
"start": 59
},
"type": "ParserError"
}
],
"sources": {}
}
6 changes: 6 additions & 0 deletions test/cmdlineTests/standard_no_import_callback_urls/A.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;

import "contract_2.sol";

contract A {}
1 change: 1 addition & 0 deletions test/cmdlineTests/standard_no_import_callback_urls/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths . --no-import-callback
11 changes: 11 additions & 0 deletions test/cmdlineTests/standard_no_import_callback_urls/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"language": "Solidity",
"sources": {
"A": {
"urls": [
"standard_no_import_callback_urls/A.sol"
]
}
},
"settings": {"outputSelection": {"*": { "*": ["metadata", "evm.bytecode"]}}}
}
13 changes: 13 additions & 0 deletions test/cmdlineTests/standard_no_import_callback_urls/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"errors":
[
{
"component": "general",
"formattedMessage": "Cannot import url (\"standard_no_import_callback_urls/A.sol\"): File reader callback is disabled.",
"message": "Cannot import url (\"standard_no_import_callback_urls/A.sol\"): File reader callback is disabled.",
"severity": "error",
"type": "IOError"
}
],
"sources": {}
}
7 changes: 7 additions & 0 deletions test/solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ BOOST_AUTO_TEST_CASE(no_cbor_metadata)
BOOST_TEST(assert);
}

BOOST_AUTO_TEST_CASE(no_import_callback)
{
vector<string> commandLine = {"solc", "--no-import-callback", "contract.sol"};
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
BOOST_TEST(parsedOptions.input.noImportCallback);
}

BOOST_AUTO_TEST_CASE(via_ir_options)
{
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);
Expand Down

0 comments on commit 8441a4b

Please sign in to comment.