diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp index 49d6df41..4954436e 100644 --- a/test/tool_main_test.cpp +++ b/test/tool_main_test.cpp @@ -560,9 +560,9 @@ TEST(mkdwarfs_test, input_list_large) { EXPECT_EQ(expected, actual); } -class categorizer_test : public testing::TestWithParam {}; +class logging_test : public testing::TestWithParam {}; -TEST_P(categorizer_test, end_to_end) { +TEST_P(logging_test, end_to_end) { auto level = GetParam(); std::string const image_file = "test.dwarfs"; @@ -615,7 +615,56 @@ TEST_P(categorizer_test, end_to_end) { } } -INSTANTIATE_TEST_SUITE_P(dwarfs, categorizer_test, +TEST_P(logging_test, fancy_output) { + auto const level = GetParam(); + std::vector const priorities{"error", "warn", "info", + "verbose", "debug", "trace"}; + std::map const match{ + {"error", "E"}, + {"warn", "W"}, + {"info", "I"}, + {"verbose", "V"}, + {"debug", "D"}, + {"trace", "T"}, + }; + auto const cutoff = std::find(priorities.begin(), priorities.end(), level); + ASSERT_FALSE(cutoff == priorities.end()); + + { + mkdwarfs_tester t; + t.iol->set_terminal_fancy(true); + t.os->set_access_fail("/somedir/ipsum.py"); // trigger an error + EXPECT_EQ(1, t.run("-l1 -i / -o - --categorize --num-workers=8 -S 22 " + "-L 16M --progress=none --log-level=" + + level)) + << t.err(); + + auto err = t.err(); + auto it = priorities.begin(); + + auto make_contains_regex = [](auto m) { + std::string end = m->second.size() > 1 ? "" : ""; + return ::testing::ContainsRegex( + m->second + "\\s[0-9][0-9]:[0-9][0-9]:[0-9][0-9].*" + end + "\n"); + }; + + while (it != cutoff + 1) { + auto m = match.find(*it); + EXPECT_FALSE(m == match.end()); + EXPECT_THAT(err, make_contains_regex(m)); + ++it; + } + + while (it != priorities.end()) { + auto m = match.find(*it); + EXPECT_FALSE(m == match.end()); + EXPECT_THAT(err, ::testing::Not(make_contains_regex(m))); + ++it; + } + } +} + +INSTANTIATE_TEST_SUITE_P(mkdwarfs, logging_test, ::testing::Values("error", "warn", "info", "verbose", "debug", "trace"));