aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-01-04 21:24:35 +0800
committerchriseth <chris@ethereum.org>2018-01-04 21:29:03 +0800
commit7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56 (patch)
tree667735a6921b8e11de55a36715cc0bf15ccdb70c /test
parent00692a4ff66551ae99920380cc4e43de377e63c7 (diff)
downloaddexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar.gz
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar.bz2
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar.lz
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar.xz
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.tar.zst
dexon-solidity-7f4cf00f1b6a41c1fd409dbca329d7bc17f4fd56.zip
Provide easy way to update source location expectation.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/Assembly.cpp54
1 files changed, 45 insertions, 9 deletions
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index 358d3c72..59af6d41 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -86,23 +86,59 @@ eth::AssemblyItems compileContract(const string& _sourceCode)
return AssemblyItems();
}
+void printAssemblyLocations(AssemblyItems const& _items)
+{
+ auto printRepeated = [](SourceLocation const& _loc, size_t _repetitions)
+ {
+ cout <<
+ "\t\tvector<SourceLocation>(" <<
+ _repetitions <<
+ ", SourceLocation(" <<
+ _loc.start <<
+ ", " <<
+ _loc.end <<
+ ", make_shared<string>(\"" <<
+ *_loc.sourceName <<
+ "\"))) +" << endl;
+ };
+
+ vector<SourceLocation> locations;
+ for (auto const& item: _items)
+ locations.push_back(item.location());
+ size_t repetitions = 0;
+ SourceLocation const* previousLoc = nullptr;
+ for (size_t i = 0; i < locations.size(); ++i)
+ {
+ SourceLocation& loc = locations[i];
+ if (previousLoc && *previousLoc == loc)
+ repetitions++;
+ else
+ {
+ if (previousLoc)
+ printRepeated(*previousLoc, repetitions);
+ previousLoc = &loc;
+ repetitions = 1;
+ }
+ }
+ if (previousLoc)
+ printRepeated(*previousLoc, repetitions);
+}
+
void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> const& _locations)
{
BOOST_CHECK_EQUAL(_items.size(), _locations.size());
for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i)
{
- BOOST_CHECK_MESSAGE(
- _items[i].location() == _locations[i],
- "Location mismatch for assembly item " + to_string(i) + ". Found: " +
- (_items[i].location().sourceName ? *_items[i].location().sourceName + ":" : "(null source name)") +
- to_string(_items[i].location().start) + "-" +
- to_string(_items[i].location().end) + ", expected: " +
- (_locations[i].sourceName ? *_locations[i].sourceName + ":" : "(null source name)") +
- to_string(_locations[i].start) + "-" +
- to_string(_locations[i].end));
+ if (_items[i].location() != _locations[i])
+ {
+ BOOST_CHECK_MESSAGE(false, "Location mismatch for item " + to_string(i) + ". Found the following locations:");
+ printAssemblyLocations(_items);
+ return;
+ }
}
}
+
} // end anonymous namespace
BOOST_AUTO_TEST_SUITE(Assembly)