mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 03:49:44 -04:00
test: factor out mtree parser
This commit is contained in:
parent
c427808bb1
commit
853d8ca966
@ -1085,31 +1085,12 @@ void check_compat(logger& lgr, reader::filesystem_v2 const& fs,
|
||||
EXPECT_NO_THROW(ext.extract(fs));
|
||||
EXPECT_NO_THROW(ext.close());
|
||||
|
||||
std::istringstream iss(oss.str());
|
||||
std::string line;
|
||||
size_t num = 0;
|
||||
ref_entries.erase("");
|
||||
|
||||
while (std::getline(iss, line, '\n')) {
|
||||
if (line == "#mtree") {
|
||||
continue;
|
||||
}
|
||||
auto mtree = test::parse_mtree(oss.str());
|
||||
|
||||
std::vector<std::string> parts;
|
||||
split_to(line, ' ', parts);
|
||||
auto name = parts.front().substr(2);
|
||||
parts.erase(parts.begin());
|
||||
std::unordered_map<std::string, std::string> kv;
|
||||
|
||||
for (auto const& p : parts) {
|
||||
auto pos = p.find('=');
|
||||
if (pos == std::string::npos) {
|
||||
throw std::runtime_error("unexpected mtree line: " + line);
|
||||
}
|
||||
kv[p.substr(0, pos)] = p.substr(pos + 1);
|
||||
}
|
||||
|
||||
++num;
|
||||
for (auto [path, kv] : mtree) {
|
||||
auto name = path.substr(2);
|
||||
|
||||
auto ri = ref_entries.find(name);
|
||||
EXPECT_FALSE(ri == ref_entries.end());
|
||||
@ -1127,7 +1108,7 @@ void check_compat(logger& lgr, reader::filesystem_v2 const& fs,
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_EQ(ref_entries.size(), num);
|
||||
EXPECT_EQ(ref_entries.size(), mtree.size());
|
||||
|
||||
std::map<std::string, std::vector<std::string>> testdirs{
|
||||
{"empty", {"empty/alsoempty"}},
|
||||
|
@ -576,6 +576,40 @@ std::string create_random_string(size_t size, size_t seed) {
|
||||
return create_random_string(size, tmprng);
|
||||
}
|
||||
|
||||
std::vector<
|
||||
std::pair<std::string, std::unordered_map<std::string, std::string>>>
|
||||
parse_mtree(std::string_view mtree) {
|
||||
std::vector<
|
||||
std::pair<std::string, std::unordered_map<std::string, std::string>>>
|
||||
rv;
|
||||
std::istringstream iss{std::string{mtree}};
|
||||
std::string line;
|
||||
|
||||
while (std::getline(iss, line, '\n')) {
|
||||
if (line == "#mtree") {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto parts = split_to<std::vector<std::string>>(line, ' ');
|
||||
auto path = parts.front();
|
||||
parts.erase(parts.begin());
|
||||
|
||||
std::unordered_map<std::string, std::string> attrs;
|
||||
|
||||
for (auto const& p : parts) {
|
||||
auto pos = p.find('=');
|
||||
if (pos == std::string::npos) {
|
||||
throw std::runtime_error("unexpected mtree line: " + line);
|
||||
}
|
||||
attrs[p.substr(0, pos)] = p.substr(pos + 1);
|
||||
}
|
||||
|
||||
rv.emplace_back(std::move(path), std::move(attrs));
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool skip_slow_tests() {
|
||||
static bool skip = getenv_is_enabled("DWARFS_SKIP_SLOW_TESTS");
|
||||
return skip;
|
||||
|
@ -364,6 +364,10 @@ std::string create_random_string(size_t size, uint8_t min, uint8_t max,
|
||||
std::string create_random_string(size_t size, std::mt19937_64& gen);
|
||||
std::string create_random_string(size_t size, size_t seed = 0);
|
||||
|
||||
std::vector<
|
||||
std::pair<std::string, std::unordered_map<std::string, std::string>>>
|
||||
parse_mtree(std::string_view mtree);
|
||||
|
||||
bool skip_slow_tests();
|
||||
|
||||
#define DWARFS_SLOW_TEST() \
|
||||
|
Loading…
x
Reference in New Issue
Block a user