Skip to content

Commit

Permalink
treemerge: tolerate zero input paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cebtenzzre committed Jun 20, 2023
1 parent 6696a60 commit c4b4662
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/treemerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ static bool rm_tm_count_files(RmTrie *count_tree, const RmCfg *const cfg) {
g_assert(cfg);
guint path_count = cfg->path_count;

g_assert(path_count);
g_assert(path_count == g_slist_length(cfg->paths));
if(path_count == 0) {
return true;
}

const char **const path_vec = malloc(sizeof(*path_vec) * (path_count + 1));
if(!path_vec) {
Expand Down
7 changes: 4 additions & 3 deletions tests/test_options/test_stdin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def test_path_starting_with_dash():

# Regression test for https://github.com/sahib/rmlint/issues/400
# Do not search in current directory when piped empty input.
@parameterized([("-", ), ("-0", )])
# Also, treemerge should not fail if given zero paths.
@parameterized([('-',), ('-0',), ('-D', '-')])
@with_setup(usual_setup_func, usual_teardown_func)
def test_stdin_empty(stdin_opt):
def test_stdin_empty(*opts):
create_file('1234', 'a')
create_file('1234', 'b')

Expand All @@ -93,7 +94,7 @@ def test_stdin_empty(stdin_opt):
try:
os.chdir(TESTDIR_NAME)
proc = subprocess.Popen(
[cwd + '/rmlint', stdin_opt, '-o', 'json'],
[cwd + '/rmlint', *opts, '-o', 'json'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE
)
Expand Down

0 comments on commit c4b4662

Please sign in to comment.