Skip to content

Commit 062c69f

Browse files
committed
chore: add logger output as test context
1 parent da52162 commit 062c69f

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

test/compat_test.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ int compare_versions(std::string_view v1str, std::string_view v2str) {
947947
return 0;
948948
}
949949

950-
void check_compat(logger& lgr [[maybe_unused]], reader::filesystem_v2 const& fs,
951-
std::string const& version) {
950+
void check_compat(test::test_logger& lgr [[maybe_unused]],
951+
reader::filesystem_v2 const& fs, std::string const& version) {
952952
bool const has_devices = compare_versions(version, "0.3.0") >= 0;
953953
bool const has_ac_time = compare_versions(version, "0.3.0") < 0;
954954
bool const nlink_affects_blocks = compare_versions(version, "0.5.0") >= 0;
@@ -1162,16 +1162,16 @@ void check_compat(logger& lgr [[maybe_unused]], reader::filesystem_v2 const& fs,
11621162
utility::filesystem_extractor ext(lgr, os);
11631163
std::ostringstream oss;
11641164

1165-
EXPECT_NO_THROW(ext.open_stream(oss, {.name = "mtree"}));
1166-
EXPECT_NO_THROW(ext.extract(fs, {.enable_progress = true}));
1165+
EXPECT_NO_THROW(ext.open_stream(oss, {.name = "mtree"})) << lgr;
1166+
EXPECT_NO_THROW(ext.extract(fs, {.enable_progress = true})) << lgr;
11671167

11681168
{
11691169
auto const pi = ext.get_progress();
11701170
ASSERT_TRUE(pi.total_bytes.has_value());
11711171
EXPECT_EQ(pi.total_bytes.value(), pi.extracted_bytes);
11721172
}
11731173

1174-
EXPECT_NO_THROW(ext.close());
1174+
EXPECT_NO_THROW(ext.close()) << lgr;
11751175

11761176
ref_entries.erase("");
11771177

@@ -1279,7 +1279,7 @@ void check_compat(logger& lgr [[maybe_unused]], reader::filesystem_v2 const& fs,
12791279
}
12801280
}
12811281

1282-
void check_extract_format(logger& lgr, test::os_access_mock& os,
1282+
void check_extract_format(test::test_logger& lgr, test::os_access_mock& os,
12831283
reader::filesystem_v2 const& fs,
12841284
std::optional<std::string_view> format = std::nullopt,
12851285
glob_matcher const* matcher = nullptr) {
@@ -1295,30 +1295,32 @@ void check_extract_format(logger& lgr, test::os_access_mock& os,
12951295
.skip_devices = true,
12961296
.skip_specials = true,
12971297
}))
1298-
<< context;
1298+
<< context << "\n"
1299+
<< lgr;
12991300

13001301
auto const pi = fsx.get_progress();
13011302
ASSERT_TRUE(pi.total_bytes.has_value()) << context;
13021303
EXPECT_EQ(pi.total_bytes.value(), pi.extracted_bytes) << context;
13031304

1304-
EXPECT_NO_THROW(fsx.close()) << context;
1305+
EXPECT_NO_THROW(fsx.close()) << context << "\n" << lgr;
13051306
};
13061307

13071308
if (format.has_value()) {
13081309
#ifndef DWARFS_FILESYSTEM_EXTRACTOR_NO_OPEN_FORMAT
13091310
std::ostringstream oss;
1310-
EXPECT_NO_THROW(fsx.open_stream(oss, {.name = std::string{*format}}));
1311+
EXPECT_NO_THROW(fsx.open_stream(oss, {.name = std::string{*format}}))
1312+
<< lgr;
13111313
do_extract();
13121314
#endif
13131315
} else {
13141316
temporary_directory tempdir("dwarfs");
13151317
auto const td = tempdir.path();
1316-
EXPECT_NO_THROW(fsx.open_disk(td));
1318+
EXPECT_NO_THROW(fsx.open_disk(td)) << lgr;
13171319
do_extract();
13181320
}
13191321
}
13201322

1321-
void check_extract_matcher(logger& lgr, test::os_access_mock& os,
1323+
void check_extract_matcher(test::test_logger& lgr, test::os_access_mock& os,
13221324
reader::filesystem_v2 const& fs,
13231325
glob_matcher const* matcher = nullptr) {
13241326
// check extract-to-disk
@@ -1335,7 +1337,7 @@ void check_extract_matcher(logger& lgr, test::os_access_mock& os,
13351337
#endif
13361338
}
13371339

1338-
void check_extract(logger& lgr, test::os_access_mock& os,
1340+
void check_extract(test::test_logger& lgr, test::os_access_mock& os,
13391341
reader::filesystem_v2 const& fs) {
13401342
// no matcher - extract all
13411343
check_extract_matcher(lgr, os, fs);

test/test_logger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ class test_logger : public ::dwarfs::logger {
9393

9494
void clear() { log_.clear(); }
9595

96+
friend std::ostream& operator<<(std::ostream& os, test_logger const& logger) {
97+
os << logger.as_string();
98+
return os;
99+
}
100+
96101
private:
97102
static level_type default_threshold() { return level_type::INFO; }
98103

0 commit comments

Comments
 (0)