Skip to content

Commit 6ad8b53

Browse files
author
Paul Dreik
committed
fix #60: minfilesize and ignoreempty in combination
2 parents b9b7811 + 8227df4 commit 6ad8b53

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

Options.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "config.h" //header file from autoconf, must come first to make large file support work properly
22

3+
#include <algorithm>
34
#include <iostream>
45
#include <limits>
56

@@ -106,7 +107,8 @@ parseOptions(Parser& parser)
106107
o.resultsfile = parser.get_parsed_string();
107108
} else if (parser.try_parse_bool("-ignoreempty")) {
108109
if (parser.get_parsed_bool()) {
109-
o.minimumfilesize = 1;
110+
o.minimumfilesize =
111+
std::max(Fileinfo::filesizetype{ 1 }, o.minimumfilesize);
110112
} else {
111113
o.minimumfilesize = 0;
112114
}

inofficial_cmake/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ foreach(testscript ${testscripts})
9696
endforeach()
9797

9898
if(Catch2_FOUND)
99-
set(unittests test_checksum)
99+
set(unittests test_checksum test_options)
100100
foreach(unittest ${unittests})
101-
add_executable(${unittest} ../unittests/test_checksum.cc)
101+
add_executable(${unittest} ../unittests/${unittest}.cc)
102102
target_compile_features(${unittest} PRIVATE cxx_std_20)
103103
target_link_libraries(${unittest} PRIVATE rdfindimpl Catch2::Catch2WithMain)
104104
endforeach()

unittests/test_options.cc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include <catch2/catch_test_macros.hpp>
2+
3+
#include "CmdlineParser.hh"
4+
#include "Options.hh"
5+
6+
TEST_CASE("minimum filesize is 1 by default")
7+
{
8+
Options defaults;
9+
REQUIRE(defaults.minimumfilesize == 1);
10+
}
11+
12+
TEST_CASE("-ignoreempty false")
13+
{
14+
const int argc = 3;
15+
const char* argv[argc] = { "progname", "-ignoreempty", "false" };
16+
Parser parser(argc, argv);
17+
18+
Options o = parseOptions(parser);
19+
REQUIRE(o.minimumfilesize == 0);
20+
}
21+
22+
TEST_CASE("-ignoreempty true")
23+
{
24+
const int argc = 3;
25+
const char* argv[argc] = { "progname", "-ignoreempty", "true" };
26+
Parser parser(argc, argv);
27+
28+
Options o = parseOptions(parser);
29+
REQUIRE(o.minimumfilesize == 1);
30+
}
31+
32+
TEST_CASE("-minsize 1234")
33+
{
34+
const int argc = 3;
35+
const char* argv[argc] = { "progname", "-minsize", "1234" };
36+
Parser parser(argc, argv);
37+
38+
Options o = parseOptions(parser);
39+
REQUIRE(o.minimumfilesize == 1234);
40+
}
41+
42+
// https://github.com/pauldreik/rdfind/issues/60
43+
TEST_CASE("-minsize 100000000 -ignoreempty true")
44+
{
45+
const int argc = 5;
46+
const char* argv[argc] = {
47+
"progname", "-minsize", "100000000", "-ignoreempty", "true"
48+
};
49+
Parser parser(argc, argv);
50+
51+
Options o = parseOptions(parser);
52+
REQUIRE(o.minimumfilesize == 100000000);
53+
}
54+
55+
TEST_CASE("-ignoreempty true -minsize 100000000")
56+
{
57+
const int argc = 5;
58+
const char* argv[argc] = {
59+
"progname", "-ignoreempty", "true", "-minsize", "100000000"
60+
};
61+
Parser parser(argc, argv);
62+
63+
Options o = parseOptions(parser);
64+
REQUIRE(o.minimumfilesize == 100000000);
65+
}
66+
67+
TEST_CASE("-ignoreempty false -minsize 1234")
68+
{
69+
const int argc = 5;
70+
const char* argv[argc] = {
71+
"progname", "-ignoreempty", "false", "-minsize", "1234"
72+
};
73+
Parser parser(argc, argv);
74+
75+
Options o = parseOptions(parser);
76+
REQUIRE(o.minimumfilesize == 1234);
77+
}
78+
79+
TEST_CASE("-minsize 1234 -ignoreempty false")
80+
{
81+
const int argc = 5;
82+
const char* argv[argc] = {
83+
"progname", "-minsize", "1234", "-ignoreempty", "false"
84+
};
85+
Parser parser(argc, argv);
86+
87+
Options o = parseOptions(parser);
88+
REQUIRE(o.minimumfilesize == 0);
89+
}

0 commit comments

Comments
 (0)