mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
prepare_report.py: Print some statistics about contracts and errors
This commit is contained in:
@@ -9,7 +9,7 @@ from unittest_helpers import FIXTURE_DIR, LIBSOLIDITY_TEST_DIR, load_fixture, lo
|
||||
|
||||
# NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
|
||||
# pragma pylint: disable=import-error
|
||||
from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse
|
||||
from bytecodecompare.prepare_report import CompilerInterface, FileReport, ContractReport, SMTUse, Statistics
|
||||
from bytecodecompare.prepare_report import load_source, parse_cli_output, parse_standard_json_output, prepare_compiler_input
|
||||
# pragma pylint: enable=import-error
|
||||
|
||||
@@ -99,6 +99,58 @@ class TestFileReport(PrepareReportTestBase):
|
||||
|
||||
self.assertEqual(report.format_report(), '')
|
||||
|
||||
class TestPrepareReport_Statistics(unittest.TestCase):
|
||||
def test_initialization(self):
|
||||
self.assertEqual(Statistics(), Statistics(0, 0, 0, 0, 0))
|
||||
|
||||
def test_aggregate_bytecode_and_metadata_present(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', 'M')]))
|
||||
self.assertEqual(statistics, Statistics(1, 1, 0, 0, 0))
|
||||
|
||||
def test_aggregate_bytecode_missing(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', None, 'M')]))
|
||||
self.assertEqual(statistics, Statistics(1, 1, 0, 1, 0))
|
||||
|
||||
def test_aggregate_metadata_missing(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[ContractReport('C', 'c.sol', 'B', None)]))
|
||||
self.assertEqual(statistics, Statistics(1, 1, 0, 0, 1))
|
||||
|
||||
def test_aggregate_no_contract_reports(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[]))
|
||||
self.assertEqual(statistics, Statistics(1, 0, 0, 0, 0))
|
||||
|
||||
def test_aggregate_missing_contract_report_list(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None))
|
||||
self.assertEqual(statistics, Statistics(1, 0, 1, 0, 0))
|
||||
|
||||
def test_aggregate_multiple_contract_reports(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[
|
||||
ContractReport('C', 'c.sol', 'B', 'M'),
|
||||
ContractReport('C', 'c.sol', None, 'M'),
|
||||
ContractReport('C', 'c.sol', 'B', None),
|
||||
ContractReport('C', 'c.sol', None, None),
|
||||
]))
|
||||
self.assertEqual(statistics, Statistics(1, 4, 0, 2, 2))
|
||||
|
||||
def test_str(self):
|
||||
statistics = Statistics()
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=[
|
||||
ContractReport('C', 'c.sol', 'B', 'M'),
|
||||
ContractReport('C', 'c.sol', None, 'M'),
|
||||
ContractReport('C', 'c.sol', 'B', None),
|
||||
ContractReport('C', 'c.sol', None, None),
|
||||
]))
|
||||
statistics.aggregate(FileReport(file_name=Path('F'), contract_reports=None))
|
||||
|
||||
self.assertEqual(statistics, Statistics(2, 4, 1, 2, 2))
|
||||
self.assertEqual(str(statistics), "test cases: 2, contracts: 4+, errors: 1, missing bytecode: 2, missing metadata: 2")
|
||||
|
||||
|
||||
class TestLoadSource(PrepareReportTestBase):
|
||||
def test_load_source_should_strip_smt_pragmas_if_requested(self):
|
||||
|
||||
Reference in New Issue
Block a user