Skip to content

Commit

Permalink
Fix Options::validate() to accept update option alone
Browse files Browse the repository at this point in the history
Options::validate() threw an exception, when only update option was
passed.
  • Loading branch information
fluks committed Dec 4, 2016
1 parent d170a5c commit 4c91077
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Pdfsearch::Options::getopt() {

void
Pdfsearch::Options::validate() const {
if (!index && query.empty() && !vacuum) {
if (!index && query.empty() && !vacuum && !update) {
throw std::invalid_argument("either index, query, update or vacuum "
"option must be selected");
}
Expand Down
8 changes: 8 additions & 0 deletions tests/00-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,11 @@ TEST_CASE("config file not found", "[options]") {

REQUIRE_THROWS_AS(o.getopt(), std::ios_base::failure);
}

TEST_CASE("validate - update option alone ok", "[options]") {
const char* argv[] = { "", "-u" };
Pdfsearch::Options o(2, const_cast<char**>(argv));
o.getopt();

REQUIRE_NOTHROW(o.validate());
}

0 comments on commit 4c91077

Please sign in to comment.