Skip to content

Import/namespace and test extension handling cleanup in soltest #16013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/map.hpp>

#include <fstream>
#include <limits>
#include <iterator>
#include <ostream>
#include <stack>

using namespace solidity;
Expand Down
31 changes: 21 additions & 10 deletions test/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ CommonOptions::CommonOptions(std::string _caption):
void CommonOptions::addOptions()
{
options.add_options()
("evm-version", po::value(&evmVersionString), "which EVM version to use")
("evm-version", po::value(&m_evmVersionString), "which EVM version to use")
// "eof-version" is declared as uint64_t, since uint8_t will be parsed as character by boost.
("eof-version", po::value<uint64_t>()->implicit_value(1u), "which EOF version to use")
("testpath", po::value<fs::path>(&this->testPath)->default_value(solidity::test::testPath()), "path to test files")
("testpath", po::value<fs::path>(&this->testPath)->default_value(test::testPath()), "path to test files")
("vm", po::value<std::vector<fs::path>>(&vmPaths), "path to evmc library, can be supplied multiple times.")
("batches", po::value<size_t>(&this->batches)->default_value(1), "set number of batches to split the tests into")
("selected-batch", po::value<size_t>(&this->selectedBatch)->default_value(0), "zero-based number of batch to execute")
Expand Down Expand Up @@ -259,11 +259,11 @@ void CommonOptions::printSelectedOptions(std::ostream& _stream, std::string cons

langutil::EVMVersion CommonOptions::evmVersion() const
{
if (!evmVersionString.empty())
if (!m_evmVersionString.empty())
{
auto version = langutil::EVMVersion::fromString(evmVersionString);
auto version = langutil::EVMVersion::fromString(m_evmVersionString);
if (!version)
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EVM version: " + evmVersionString));
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EVM version: " + m_evmVersionString));
return *version;
}
else
Expand Down Expand Up @@ -306,17 +306,28 @@ bool isValidSemanticTestPath(boost::filesystem::path const& _testPath)
return true;
}

std::set<std::string> testFileExtensions()
{
return {
".sol",
".yul",
".asm",
".asmjson", // Not .json because JSON files that do not represent test cases exist in some test dirs.
".stack",
};
}

boost::unit_test::precondition::predicate_t nonEOF()
{
return [](boost::unit_test::test_unit_id) {
return !solidity::test::CommonOptions::get().eofVersion().has_value();
return !CommonOptions::get().eofVersion().has_value();
};
}

boost::unit_test::precondition::predicate_t onEOF()
{
return [](boost::unit_test::test_unit_id) {
return solidity::test::CommonOptions::get().eofVersion().has_value();
return CommonOptions::get().eofVersion().has_value();
};
}

Expand All @@ -332,13 +343,13 @@ bool loadVMs(CommonOptions const& _options)
if (_options.disableSemanticTests)
return true;

bool evmSupported = solidity::test::EVMHost::checkVmPaths(_options.vmPaths);
bool evmSupported = EVMHost::checkVmPaths(_options.vmPaths);
if (!_options.disableSemanticTests && !evmSupported)
{
std::cerr << "Unable to find " << solidity::test::evmoneFilename;
std::cerr << "Unable to find " << evmoneFilename;
std::cerr << ". Please disable semantics tests with --no-semantic-tests or provide a path using --vm <path>." << std::endl;
std::cerr << "You can download it at" << std::endl;
std::cerr << solidity::test::evmoneDownloadLink << std::endl;
std::cerr << evmoneDownloadLink << std::endl;
return false;
}
return true;
Expand Down
5 changes: 4 additions & 1 deletion test/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct CommonOptions
boost::program_options::options_description options;

private:
std::string evmVersionString;
std::string m_evmVersionString;
std::optional<uint8_t> m_eofVersion;
static std::unique_ptr<CommonOptions const> m_singleton;
};
Expand All @@ -107,6 +107,9 @@ struct CommonOptions
/// Note: @p _testPath can be relative but must include at least the `/test/libsolidity/semanticTests/` part
bool isValidSemanticTestPath(boost::filesystem::path const& _testPath);

/// Returns a list of file extensions allowed for test files.
std::set<std::string> testFileExtensions();

/// Helper that can be used to skip tests when the EVM version selected on the command line
/// is older than @p _minEVMVersion.
/// @return A predicate (function) that can be passed into @a boost::unit_test::precondition().
Expand Down
5 changes: 2 additions & 3 deletions test/CommonSyntaxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/throw_exception.hpp>

#include <fstream>
#include <memory>
#include <istream>
#include <ostream>
#include <stdexcept>

using namespace solidity;
Expand All @@ -42,7 +42,6 @@ using namespace solidity::frontend;
using namespace solidity::frontend::test;
using namespace solidity::test;
using namespace boost::unit_test;
namespace fs = boost::filesystem;

namespace
{
Expand Down
1 change: 0 additions & 1 deletion test/CommonSyntaxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <iosfwd>
#include <string>
#include <vector>
#include <utility>

namespace solidity::test
{
Expand Down
2 changes: 0 additions & 2 deletions test/ExecutionFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <libsolutil/FunctionSelector.h>
#include <libsolutil/ErrorCodes.h>

#include <functional>

#include <boost/rational.hpp>
#include <boost/test/unit_test.hpp>

Expand Down
5 changes: 4 additions & 1 deletion test/InteractiveTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
#pragma once

#include <test/TestCase.h>

#include <test/libsolidity/ABIJsonTest.h>
#include <test/libsolidity/ASTJSONTest.h>
#include <test/libsolidity/ASTPropertyTest.h>
#include <libsolidity/FunctionDependencyGraphTest.h>
#include <test/libsolidity/GasTest.h>
#include <test/libsolidity/MemoryGuardTest.h>
#include <test/libsolidity/NatspecJSONTest.h>
#include <test/libsolidity/OptimizedIRCachingTest.h>
#include <test/libsolidity/SyntaxTest.h>
#include <test/libsolidity/SemanticTest.h>
#include <test/libsolidity/SMTCheckerTest.h>

#include <test/libyul/ControlFlowGraphTest.h>
#include <test/libyul/SSAControlFlowGraphTest.h>
#include <test/libyul/EVMCodeTransformTest.h>
Expand All @@ -44,6 +45,8 @@

#include <test/libevmasm/EVMAssemblyTest.h>

#include <libsolidity/FunctionDependencyGraphTest.h>

#include <boost/filesystem.hpp>

namespace solidity::frontend::test
Expand Down
12 changes: 6 additions & 6 deletions test/TestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using namespace solidity;
using namespace solidity::frontend;
using namespace solidity::frontend::test;
using namespace solidity::util;
using namespace solidity::test;

void TestCase::printSettings(std::ostream& _stream, const std::string& _linePrefix, const bool)
{
Expand All @@ -50,9 +51,8 @@ void TestCase::printUpdatedSettings(std::ostream& _stream, std::string const& _l

bool TestCase::isTestFilename(boost::filesystem::path const& _filename)
{
std::string extension = _filename.extension().string();
// NOTE: .asmjson rather than .json because JSON files that do not represent test cases exist in some test dirs.
return (extension == ".sol" || extension == ".yul" || extension == ".asm" || extension == ".asmjson" || extension == ".stack") &&
return
testFileExtensions().contains(_filename.extension().string()) &&
!_filename.string().starts_with('~') &&
!_filename.string().starts_with('.');
}
Expand Down Expand Up @@ -123,7 +123,7 @@ void EVMVersionRestrictedTestCase::processEVMVersionSetting()
if (!version)
BOOST_THROW_EXCEPTION(std::runtime_error{"Invalid EVM version: \"" + versionString + "\""});

langutil::EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
langutil::EVMVersion evmVersion = CommonOptions::get().evmVersion();
bool comparisonResult;
if (comparator == ">")
comparisonResult = evmVersion > version;
Expand All @@ -146,9 +146,9 @@ void EVMVersionRestrictedTestCase::processEVMVersionSetting()

void EVMVersionRestrictedTestCase::processBytecodeFormatSetting()
{
std::optional<uint8_t> eofVersion = solidity::test::CommonOptions::get().eofVersion();
std::optional<uint8_t> eofVersion = CommonOptions::get().eofVersion();
// EOF only available since Osaka
solAssert(!eofVersion.has_value() || solidity::test::CommonOptions::get().evmVersion().supportsEOF());
solAssert(!eofVersion.has_value() || CommonOptions::get().evmVersion().supportsEOF());

std::string bytecodeFormatString = m_reader.stringSetting("bytecodeFormat", "legacy,>=EOFv1");
if (bytecodeFormatString == "legacy,>=EOFv1" || bytecodeFormatString == ">=EOFv1,legacy")
Expand Down
Loading