Skip to content

Commit

Permalink
test: more mkdwarfs option tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Jan 2, 2024
1 parent 0a0be0c commit 01065f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/mkdwarfs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,16 +857,16 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
}
}

if (!progress_modes.count(progress_mode)) {
iol.err << "error: invalid progress mode '" << progress_mode << "'\n";
return 1;
}
if (no_progress) {
progress_mode = "none";
}
if (progress_mode != "none" && !iol.term->is_fancy(iol.err)) {
progress_mode = "simple";
}
if (!progress_modes.count(progress_mode)) {
iol.err << "error: invalid progress mode '" << progress_mode << "'\n";
return 1;
}

auto pg_mode = DWARFS_NOTHROW(progress_modes.at(progress_mode));
auto log_level = logger::parse_level(log_level_str);
Expand Down
44 changes: 41 additions & 3 deletions test/tool_main_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,12 @@ TEST_P(mkdwarfs_build_options_test, basic) {
namespace {

constexpr std::array<std::string_view, 7> const build_options = {
"--categorize --order=none",
"--categorize --order=none --file-hash=none",
"--categorize=pcmaudio --order=path",
"--categorize --order=revpath --file-hash=sha512",
"--categorize=pcmaudio,incompressible --order=similarity",
"--categorize --order=nilsimsa",
"--categorize --order=nilsimsa:16",
"--categorize --order=nilsimsa --time-resolution=30",
"--categorize --order=nilsimsa:16 --time-resolution=hour",
"--categorize --order=nilsimsa:16:16 --max-similarity-size=1M",
};

Expand Down Expand Up @@ -788,6 +788,44 @@ TEST(mkdwarfs_test, order_nilsimsa_cannot_be_less) {
EXPECT_THAT(t.err(), ::testing::HasSubstr("cannot be less than 0 for order"));
}

TEST(mkdwarfs_test, unknown_file_hash) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "--file-hash=grmpf"}));
EXPECT_THAT(t.err(), ::testing::HasSubstr("unknown file hash function"));
}

TEST(mkdwarfs_test, invalid_filter_debug_mode) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "--debug-filter=grmpf"}));
EXPECT_THAT(t.err(), ::testing::HasSubstr("invalid filter debug mode"));
}

TEST(mkdwarfs_test, invalid_progress_mode) {
mkdwarfs_tester t;
t.iol->set_terminal_fancy(true);
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "--progress=grmpf"}));
EXPECT_THAT(t.err(), ::testing::HasSubstr("invalid progress mode"));
}

TEST(mkdwarfs_test, invalid_filter_rule) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "-F", "grmpf"}));
EXPECT_THAT(t.err(), ::testing::HasSubstr("could not parse filter rule"));
}

TEST(mkdwarfs_test, time_resolution_zero) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "--time-resolution=0"}));
EXPECT_THAT(t.err(),
::testing::HasSubstr("'--time-resolution' must be nonzero"));
}

TEST(mkdwarfs_test, time_resolution_invalid) {
mkdwarfs_tester t;
EXPECT_NE(0, t.run({"-i", "/", "-o", "-", "--time-resolution=grmpf"}));
EXPECT_THAT(t.err(), ::testing::HasSubstr("'--time-resolution' is invalid"));
}

namespace {

constexpr std::array<std::string_view, 6> const debug_filter_mode_names = {
Expand Down

0 comments on commit 01065f9

Please sign in to comment.