mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use sol file to validate test variants
This commit is contained in:
parent
4c1224e3bf
commit
8a254b7a7f
@ -1,310 +0,0 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"exportedSymbols":
|
||||
{
|
||||
"I":
|
||||
[
|
||||
29
|
||||
],
|
||||
"g":
|
||||
[
|
||||
3
|
||||
]
|
||||
},
|
||||
"id": 30,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"id": 3,
|
||||
"implemented": false,
|
||||
"kind": "freeFunction",
|
||||
"modifiers": [],
|
||||
"name": "g",
|
||||
"nameLocation": "9:1:1",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 1,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "10:2:1"
|
||||
},
|
||||
"returnParameters":
|
||||
{
|
||||
"id": 2,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "19:0:1"
|
||||
},
|
||||
"scope": 30,
|
||||
"src": "0:20:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
},
|
||||
{
|
||||
"abstract": false,
|
||||
"baseContracts": [],
|
||||
"canonicalName": "I",
|
||||
"contractDependencies": [],
|
||||
"contractKind": "interface",
|
||||
"id": 29,
|
||||
"linearizedBaseContracts":
|
||||
[
|
||||
29
|
||||
],
|
||||
"name": "I",
|
||||
"nameLocation": "31:1:1",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"canonicalName": "I.S",
|
||||
"id": 7,
|
||||
"members":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 6,
|
||||
"mutability": "mutable",
|
||||
"name": "s",
|
||||
"nameLocation": "52:1:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 7,
|
||||
"src": "50:3:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 5,
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"pathNode":
|
||||
{
|
||||
"id": 4,
|
||||
"name": "S",
|
||||
"nodeType": "IdentifierPath",
|
||||
"referencedDeclaration": 7,
|
||||
"src": "50:1:1"
|
||||
},
|
||||
"referencedDeclaration": 7,
|
||||
"src": "50:1:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"name": "S",
|
||||
"nameLocation": "46:1:1",
|
||||
"nodeType": "StructDefinition",
|
||||
"scope": 29,
|
||||
"src": "39:17:1",
|
||||
"visibility": "public"
|
||||
},
|
||||
{
|
||||
"body":
|
||||
{
|
||||
"id": 27,
|
||||
"nodeType": "Block",
|
||||
"src": "85:74:1",
|
||||
"statements":
|
||||
[
|
||||
{
|
||||
"assignments":
|
||||
[
|
||||
15
|
||||
],
|
||||
"declarations":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 15,
|
||||
"mutability": "mutable",
|
||||
"name": "E",
|
||||
"nameLocation": "101:1:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 27,
|
||||
"src": "95:7:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 14,
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"pathNode":
|
||||
{
|
||||
"id": 13,
|
||||
"name": "error",
|
||||
"nodeType": "IdentifierPath",
|
||||
"src": "95:5:1"
|
||||
},
|
||||
"src": "95:5:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"id": 16,
|
||||
"nodeType": "VariableDeclarationStatement",
|
||||
"src": "95:7:1"
|
||||
},
|
||||
{
|
||||
"eventCall":
|
||||
{
|
||||
"arguments": [],
|
||||
"expression":
|
||||
{
|
||||
"id": 17,
|
||||
"name": "E",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"src": "110:1:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"id": 18,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "110:3:1",
|
||||
"tryCall": false,
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"id": 19,
|
||||
"nodeType": "EmitStatement",
|
||||
"src": "105:8:1"
|
||||
},
|
||||
{
|
||||
"expression":
|
||||
{
|
||||
"id": 21,
|
||||
"nodeType": "UnaryOperation",
|
||||
"operator": "++",
|
||||
"prefix": true,
|
||||
"src": "123:3:1",
|
||||
"subExpression":
|
||||
{
|
||||
"id": 20,
|
||||
"name": "c",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"src": "125:1:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"id": 22,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "123:3:1"
|
||||
},
|
||||
{
|
||||
"assignments":
|
||||
[
|
||||
24
|
||||
],
|
||||
"declarations":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 24,
|
||||
"mutability": "mutable",
|
||||
"name": "c",
|
||||
"nameLocation": "143:1:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 27,
|
||||
"src": "129:15:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "calldata",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 23,
|
||||
"name": "uint",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "129:4:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"id": 26,
|
||||
"initialValue":
|
||||
{
|
||||
"hexValue": "3132332e34",
|
||||
"id": 25,
|
||||
"kind": "number",
|
||||
"nodeType": "Literal",
|
||||
"src": "147:5:1",
|
||||
"typeDescriptions": {},
|
||||
"value": "123.4"
|
||||
},
|
||||
"nodeType": "VariableDeclarationStatement",
|
||||
"src": "129:23:1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"id": 28,
|
||||
"implemented": true,
|
||||
"kind": "function",
|
||||
"modifiers": [],
|
||||
"name": "f",
|
||||
"nameLocation": "70:1:1",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 11,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 10,
|
||||
"mutability": "mutable",
|
||||
"name": "e",
|
||||
"nameLocation": "82:1:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 28,
|
||||
"src": "72:11:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "storage",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 9,
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"pathNode":
|
||||
{
|
||||
"id": 8,
|
||||
"name": "E",
|
||||
"nodeType": "IdentifierPath",
|
||||
"src": "72:1:1"
|
||||
},
|
||||
"src": "72:1:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"src": "71:13:1"
|
||||
},
|
||||
"returnParameters":
|
||||
{
|
||||
"id": 12,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "85:0:1"
|
||||
},
|
||||
"scope": 29,
|
||||
"src": "61:98:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 30,
|
||||
"src": "21:140:1",
|
||||
"usedErrors": []
|
||||
}
|
||||
],
|
||||
"src": "0:162:1"
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"id": 12,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"absolutePath": "notexisting.sol",
|
||||
"file": "notexisting.sol",
|
||||
"id": 1,
|
||||
"nameLocation": "28:11:1",
|
||||
"nodeType": "ImportDirective",
|
||||
"src": "0:40:1",
|
||||
"symbolAliases": [],
|
||||
"unitAlias": "NotExisting"
|
||||
},
|
||||
{
|
||||
"abstract": false,
|
||||
"baseContracts":
|
||||
[
|
||||
{
|
||||
"baseName":
|
||||
{
|
||||
"id": 2,
|
||||
"name": "NotExisting.X",
|
||||
"nodeType": "IdentifierPath",
|
||||
"src": "55:13:1"
|
||||
},
|
||||
"id": 3,
|
||||
"nodeType": "InheritanceSpecifier",
|
||||
"src": "55:13:1"
|
||||
}
|
||||
],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"id": 11,
|
||||
"name": "C",
|
||||
"nameLocation": "50:1:1",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes":
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"id": 6,
|
||||
"mutability": "mutable",
|
||||
"name": "myStruct",
|
||||
"nameLocation": "102:8:1",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"src": "72:38:1",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {},
|
||||
"typeName":
|
||||
{
|
||||
"id": 5,
|
||||
"nodeType": "UserDefinedTypeName",
|
||||
"pathNode":
|
||||
{
|
||||
"id": 4,
|
||||
"name": "NotExisting.SomeStruct",
|
||||
"nodeType": "IdentifierPath",
|
||||
"src": "72:22:1"
|
||||
},
|
||||
"src": "72:22:1",
|
||||
"typeDescriptions": {}
|
||||
},
|
||||
"visibility": "public"
|
||||
},
|
||||
{
|
||||
"body":
|
||||
{
|
||||
"id": 9,
|
||||
"nodeType": "Block",
|
||||
"src": "127:2:1",
|
||||
"statements": []
|
||||
},
|
||||
"id": 10,
|
||||
"implemented": true,
|
||||
"kind": "constructor",
|
||||
"modifiers": [],
|
||||
"name": "",
|
||||
"nameLocation": "-1:-1:-1",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters":
|
||||
{
|
||||
"id": 7,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "124:2:1"
|
||||
},
|
||||
"returnParameters":
|
||||
{
|
||||
"id": 8,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "127:0:1"
|
||||
},
|
||||
"src": "113:16:1",
|
||||
"stateMutability": "nonpayable",
|
||||
"virtual": false
|
||||
}
|
||||
],
|
||||
"src": "41:90:1",
|
||||
"usedErrors": []
|
||||
}
|
||||
],
|
||||
"src": "0:132:1"
|
||||
}
|
@ -94,12 +94,8 @@ void replaceTagWithVersion(string& _input)
|
||||
|
||||
}
|
||||
|
||||
|
||||
ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
void ASTJSONTest::generateTestVariants(string const& _filename)
|
||||
{
|
||||
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
|
||||
|
||||
string_view baseName = _filename;
|
||||
baseName.remove_suffix(4);
|
||||
|
||||
@ -118,10 +114,10 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
m_variants.push_back(variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_variants.empty())
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Missing file with expected result for: \"" + _filename + "\"."));
|
||||
|
||||
void ASTJSONTest::fillSources(string const& _filename)
|
||||
{
|
||||
ifstream file(_filename);
|
||||
if (!file)
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test contract: \"" + _filename + "\"."));
|
||||
@ -152,15 +148,48 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
if (m_expectedFailAfter.has_value())
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Duplicated \"failAfter\" directive"));
|
||||
m_expectedFailAfter = stringToCompilerState(state);
|
||||
|
||||
}
|
||||
else if (!line.empty() && !boost::algorithm::starts_with(line, delimiter))
|
||||
source += line + "\n";
|
||||
}
|
||||
|
||||
m_sources.emplace_back(sourceName.empty() ? "a" : sourceName, source);
|
||||
file.close();
|
||||
}
|
||||
|
||||
void ASTJSONTest::validateTestConfiguration() const
|
||||
{
|
||||
if (m_variants.empty())
|
||||
BOOST_THROW_EXCEPTION(runtime_error("No file with expected result found."));
|
||||
|
||||
if (m_expectedFailAfter.has_value())
|
||||
{
|
||||
auto unexpectedTestVariant = std::find_if(
|
||||
m_variants.begin(), m_variants.end(),
|
||||
[failAfter = m_expectedFailAfter](TestVariant v) { return v.stopAfter > failAfter; }
|
||||
);
|
||||
|
||||
if (unexpectedTestVariant != m_variants.end())
|
||||
BOOST_THROW_EXCEPTION(
|
||||
runtime_error(
|
||||
string("Unexpected JSON file: ") + unexpectedTestVariant->astFilename() +
|
||||
" in \"failAfter: " +
|
||||
compilerStateToString(m_expectedFailAfter.value()) + "\" scenario."
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ASTJSONTest::ASTJSONTest(string const& _filename)
|
||||
{
|
||||
if (!boost::algorithm::ends_with(_filename, ".sol"))
|
||||
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
|
||||
|
||||
generateTestVariants(_filename);
|
||||
fillSources(_filename);
|
||||
validateTestConfiguration();
|
||||
}
|
||||
|
||||
TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
|
||||
{
|
||||
CompilerStack c;
|
||||
|
@ -89,6 +89,10 @@ private:
|
||||
std::string const& _variant
|
||||
) const;
|
||||
|
||||
void generateTestVariants(std::string const& _filename);
|
||||
void fillSources(std::string const& _filename);
|
||||
void validateTestConfiguration() const;
|
||||
|
||||
std::vector<TestVariant> m_variants;
|
||||
std::optional<CompilerStack::State> m_expectedFailAfter;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user