Skip to content

Commit 707712a

Browse files
committed
Unify the lists of allowed test file extensions
1 parent 0619894 commit 707712a

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

test/Common.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ bool isValidSemanticTestPath(boost::filesystem::path const& _testPath)
306306
return true;
307307
}
308308

309+
std::set<std::string> testFileExtensions()
310+
{
311+
return {
312+
".sol",
313+
".yul",
314+
".asm",
315+
".asmjson", // Not .json because JSON files that do not represent test cases exist in some test dirs.
316+
".stack",
317+
};
318+
}
319+
309320
boost::unit_test::precondition::predicate_t nonEOF()
310321
{
311322
return [](boost::unit_test::test_unit_id) {

test/Common.h

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct CommonOptions
107107
/// Note: @p _testPath can be relative but must include at least the `/test/libsolidity/semanticTests/` part
108108
bool isValidSemanticTestPath(boost::filesystem::path const& _testPath);
109109

110+
/// Returns a list of file extensions allowed for test files.
111+
std::set<std::string> testFileExtensions();
112+
110113
/// Helper that can be used to skip tests when the EVM version selected on the command line
111114
/// is older than @p _minEVMVersion.
112115
/// @return A predicate (function) that can be passed into @a boost::unit_test::precondition().

test/TestCase.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ void TestCase::printUpdatedSettings(std::ostream& _stream, std::string const& _l
5151

5252
bool TestCase::isTestFilename(boost::filesystem::path const& _filename)
5353
{
54-
std::string extension = _filename.extension().string();
55-
// NOTE: .asmjson rather than .json because JSON files that do not represent test cases exist in some test dirs.
56-
return (extension == ".sol" || extension == ".yul" || extension == ".asm" || extension == ".asmjson" || extension == ".stack") &&
54+
return
55+
testFileExtensions().contains(_filename.extension().string()) &&
5756
!_filename.string().starts_with('~') &&
5857
!_filename.string().starts_with('.');
5958
}

test/tools/isoltest.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
#include <test/InteractiveTests.h>
2626
#include <test/EVMHost.h>
2727

28+
#include <boost/algorithm/string/predicate.hpp>
2829
#include <boost/algorithm/string/replace.hpp>
2930
#include <boost/filesystem.hpp>
3031

32+
#include <fmt/format.h>
33+
34+
#include <range/v3/algorithm/all_of.hpp>
35+
3136
#include <cstdlib>
3237
#include <iostream>
3338
#include <queue>
@@ -65,14 +70,17 @@ struct TestStats
6570
class TestFilter
6671
{
6772
public:
68-
explicit TestFilter(std::string _filter): m_filter(std::move(_filter))
73+
explicit TestFilter(std::string _filter):
74+
m_filter(std::move(_filter))
6975
{
70-
std::string filter{m_filter};
71-
72-
boost::replace_all(filter, "/", "\\/");
73-
boost::replace_all(filter, "*", ".*");
74-
75-
m_filterExpression = std::regex{"(" + filter + "(\\.sol|\\.yul|\\.asm|\\.asmjson|\\.stack))"};
76+
auto const startsWithDot = [](std::string const& _extension) { return boost::starts_with(_extension, "."); };
77+
soltestAssert(ranges::all_of(testFileExtensions(), startsWithDot));
78+
79+
m_filterExpression = std::regex{fmt::format(
80+
"({}({}))",
81+
boost::replace_all_copy(boost::replace_all_copy(m_filter, "/", "\\/"), "*", ".*"),
82+
boost::replace_all_copy(joinHumanReadable(testFileExtensions(), "|"), ".", "\\.")
83+
)};
7684
}
7785

7886
bool matches(fs::path const& _path, std::string const& _name) const

0 commit comments

Comments
 (0)