Merge pull request #12798 from ethereum/lsp-tests-expectations

LSP.py: Implement expectations directly in the test files
This commit is contained in:
Christian Parpart 2022-04-25 15:27:57 +02:00 committed by GitHub
commit fbecdbe76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 948 additions and 322 deletions

View File

@ -84,7 +84,7 @@ printTask "Testing Python scripts..."
"$REPO_ROOT/test/pyscriptTests.py"
printTask "Testing LSP..."
"$REPO_ROOT/scripts/test_solidity_lsp.py" "${SOLIDITY_BUILD_DIR}/solc/solc"
"$REPO_ROOT/test/lsp.py" "${SOLIDITY_BUILD_DIR}/solc/solc"
printTask "Running commandline tests..."
# Only run in parallel if this is run on CI infrastructure

View File

@ -2,13 +2,16 @@
pragma solidity >=0.8.0;
import "./lib.sol";
// ^ @importDirective
interface I
{
function f(uint x) external returns (uint);
// ^ @functionF
}
contract IA is I
// ^^ @IASymbol
{
function f(uint x) public pure override returns (uint) { return x + 1; }
}
@ -21,6 +24,7 @@ contract IB is I
library IntLib
{
function add(int self, int b) public pure returns (int) { return self + b; }
// ^^^ @IntLibAdd
}
contract C
@ -29,40 +33,175 @@ contract C
function virtual_inheritance() public payable
{
obj = new IA();
// ^ @usingIASymbol
obj.f(1); // goto-definition should jump to definition of interface.
// ^ @virtualFunctionLookup
}
using IntLib for *;
function using_for(int i) pure public
{
i.add(5);
// ^ @usingIntAdd
14.add(4);
}
function useLib(uint n) public payable returns (uint)
{
return Lib.add(n, 1);
// ^ @LibSymbol
// ^ @LibAddSymbol
}
function enums(Color c) public pure returns (Color d)
// ^ @ColorSymbolInParameter
{
Color e = Color.Red;
// ^ @eVariableDeclaration
// ^ @RedEnumMemberAccess
if (c == e)
// ^ @eVariableAccess
d = Color.Green;
else
d = c;
}
type Price is uint128;
// ^^^^^ @PriceDeclaration
function udlTest() public pure returns (uint128)
{
Price p = Price.wrap(128);
// ^ @PriceSymbol
// ^ @PriceInWrap
return Price.unwrap(p);
}
function structCtorTest(uint8 v) public pure returns (uint8 result)
{
RGBColor memory c = RGBColor(v, 2 * v, 3 * v);
// ^ @RGBColorCursor
result = c.red;
int a;
// ^^^^^ @unusedLocalVar
}
}
// ----
// goto_definition: @unusedLocalVar 2072
// lib: @diagnostics 2072
// -> textDocument/definition {
// "position": @importDirective
// }
// <- [
// {
// "range": {
// "end": {
// "character": 0,
// "line": 0
// },
// "start": {
// "character": 0,
// "line": 0
// }
// },
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @usingIASymbol
// }
// <- [
// {
// "range": @IASymbol,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @virtualFunctionLookup
// }
// <- [
// {
// "range": @functionF,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @usingIntAdd
// }
// <- [
// {
// "range": @IntLibAdd,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @LibSymbol
// }
// <- [
// {
// "range": @LibLibrary,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @LibAddSymbol
// }
// <- [
// {
// "range": @addSymbol,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ColorSymbolInParameter
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @RedEnumMemberAccess
// }
// <- [
// {
// "range": @EnumMemberRed,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @eVariableAccess
// }
// <- [
// {
// "range": @eVariableDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @PriceSymbol
// }
// <- [
// {
// "range": @PriceDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @PriceInWrap
// }
// <- [
// {
// "range": @PriceDeclaration,
// "uri": "goto_definition.sol"
// }
// ]
// -> textDocument/definition {
// "position": @RGBColorCursor
// }
// <- [
// {
// "range": @RGBColorStruct,
// "uri": "lib.sol"
// }
// ]

View File

@ -2,18 +2,70 @@
pragma solidity >=0.8.0;
import {Weather as Wetter} from "./lib.sol";
// ^ @wheatherImportCursor
import "./lib.sol" as That;
// ^^^^ @ThatImport
contract C
{
function test_symbol_alias() public pure returns (Wetter result)
// ^ @WetterCursor
{
result = Wetter.Sunny;
}
function test_library_alias() public pure returns (That.Color result)
// ^ @ThatCursor
{
That.Color color = That.Color.Red;
// ^ @ThatVarCursor ^ @ThatExpressionCursor
result = color;
}
}
// ----
// lib: @diagnostics 2072
// -> textDocument/definition {
// "position": @wheatherImportCursor
// }
// <- [
// {
// "range": @whetherEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @WetterCursor
// }
// <- [
// {
// "range": @whetherEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatCursor
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatVarCursor
// }
// <- [
// {
// "range": @ColorEnum,
// "uri": "lib.sol"
// }
// ]
// -> textDocument/definition {
// "position": @ThatExpressionCursor
// }
// <- [
// {
// "range": @ThatImport,
// "uri": "goto_definition_imports.sol"
// }
// ]

View File

@ -5,6 +5,7 @@ pragma solidity >=0.8.0;
error E(uint, uint);
enum Weather {
// ^^^^^^^ @whetherEnum
Sunny,
Cloudy,
Rainy
@ -12,8 +13,10 @@ enum Weather {
/// Some custom Color enum type holding 3 colors.
enum Color {
// ^^^^^ @ColorEnum
/// Red color.
Red,
// ^^^ @EnumMemberRed
/// Green color.
Green,
/// Blue color.
@ -21,9 +24,11 @@ enum Color {
}
library Lib
// @ ^^^ @LibLibrary
{
function add(uint a, uint b) public pure returns (uint result)
// ^( @addFunction
// ^^^ @addSymbol
{
result = a + b;
}
@ -37,8 +42,11 @@ library Lib
}
struct RGBColor
// ^^^^^^^^ @RGBColorStruct
{
uint8 red;
uint8 green;
uint8 blue;
}
// ----
// lib: @diagnostics 2072

View File

@ -19,3 +19,5 @@ contract D
// ^^^^^^^^^^^^ @unusedContractVariable
}
}
// ----
// publish_diagnostics_1: @unusedReturnVariable 6321 @unusedVariable 2072 @unusedContractVariable 2072

View File

@ -22,3 +22,5 @@ contract D
// ^^^^^^^^^^^^^^^^^^^^^ @wrongArgumentsCount
}
}
// ----
// publish_diagnostics_2: @conversionError 9574 @argumentsRequired 6777 @wrongArgumentsCount 6160

File diff suppressed because it is too large Load Diff