mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11579 from ethereum/better-errors-about-bad-paths-in-tests-with-external-sources
Better errors about bad paths in tests with external sources
This commit is contained in:
@@ -43,9 +43,17 @@ namespace
|
||||
template <typename T>
|
||||
inline T readFile(std::string const& _file)
|
||||
{
|
||||
assertThrow(boost::filesystem::exists(_file), FileNotFound, _file);
|
||||
|
||||
// ifstream does not always fail when the path leads to a directory. Instead it might succeed
|
||||
// with tellg() returning a nonsensical value so that std::length_error gets raised in resize().
|
||||
assertThrow(boost::filesystem::is_regular_file(_file), NotAFile, _file);
|
||||
|
||||
T ret;
|
||||
size_t const c_elementSize = sizeof(typename T::value_type);
|
||||
std::ifstream is(_file, std::ifstream::binary);
|
||||
|
||||
// Technically, this can still fail even though we checked above because FS content can change at any time.
|
||||
assertThrow(is, FileNotFound, _file);
|
||||
|
||||
// get length of file:
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace solidity::util
|
||||
|
||||
/// Retrieve and returns the contents of the given file as a std::string.
|
||||
/// If the file doesn't exist, it will throw a FileNotFound exception.
|
||||
/// If the file exists but is not a regular file, it will throw NotAFile exception.
|
||||
/// If the file is empty, returns an empty string.
|
||||
std::string readFileAsString(std::string const& _file);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ DEV_SIMPLE_EXCEPTION(InvalidAddress);
|
||||
DEV_SIMPLE_EXCEPTION(BadHexCharacter);
|
||||
DEV_SIMPLE_EXCEPTION(BadHexCase);
|
||||
DEV_SIMPLE_EXCEPTION(FileNotFound);
|
||||
DEV_SIMPLE_EXCEPTION(NotAFile);
|
||||
DEV_SIMPLE_EXCEPTION(DataTooLong);
|
||||
DEV_SIMPLE_EXCEPTION(StringTooLong);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user