From e49a5bc519b8c5f74dd4a4e904bf6d3954cac105 Mon Sep 17 00:00:00 2001 From: Shreenidhi Shedi Date: Tue, 4 Nov 2025 18:44:32 +0530 Subject: [PATCH] Error out when an invalid package name is given along with a list of valid package names to tdnf list Error out when a search query does not return anything when multiple search keys are given at a time to tdnf Signed-off-by: Shreenidhi Shedi --- pytests/tests/test_install.py | 2 +- pytests/tests/test_list.py | 13 +++++++++++++ pytests/tests/test_provides.py | 2 +- pytests/tests/test_search.py | 20 ++++++++++++++++++-- pytests/tests/test_whatprovides.py | 2 +- solv/tdnfquery.c | 22 ++++++++++++++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/pytests/tests/test_install.py b/pytests/tests/test_install.py index 30bc2eeb..098449ae 100644 --- a/pytests/tests/test_install.py +++ b/pytests/tests/test_install.py @@ -62,7 +62,7 @@ def test_install_package_verbose(utils): def test_dummy_requires(utils): pkg = utils.config["dummy_requires_pkgname"] ret = utils.run(['tdnf', 'install', '-y', pkg]) - assert ' nothing provides ' in ret['stderr'][0] + assert "nothing provides" in "\n".join(ret['stderr']) def test_install_testonly(utils): diff --git a/pytests/tests/test_list.py b/pytests/tests/test_list.py index 3b0ff8e8..18d74b1a 100644 --- a/pytests/tests/test_list.py +++ b/pytests/tests/test_list.py @@ -88,3 +88,16 @@ def test_list_notinstalled(utils): # spkg is not installed, expect error ret = utils.run(['tdnf', 'list', cmd, spkg]) assert ret['retval'] == 1011 + + +def test_list_invalid_with_valid(utils): + spkg = utils.config["sglversion_pkgname"] + + ret = utils.run(f"tdnf list {spkg} invalid1") + assert ret['retval'] == 1011 + assert "No match found for 'invalid1'" in ret['stderr'] + + ret = utils.run(f"tdnf list invalid1 {spkg} invalid2") + assert ret['retval'] == 1011 + assert "No match found for 'invalid1'" in ret['stderr'] + assert "No match found for 'invalid2'" in ret['stderr'] diff --git a/pytests/tests/test_provides.py b/pytests/tests/test_provides.py index ad6344a8..9ba4077b 100644 --- a/pytests/tests/test_provides.py +++ b/pytests/tests/test_provides.py @@ -31,4 +31,4 @@ def test_provides_valid_pkg_name(utils): def test_provides_invalid_pkg_name(utils): ret = utils.run(['tdnf', 'provides', 'invalid_pkg_name']) - assert ret['stderr'][0] == 'No data available' + assert 'No data available' in ret['stderr'] diff --git a/pytests/tests/test_search.py b/pytests/tests/test_search.py index 5ebc68c5..8701dd99 100644 --- a/pytests/tests/test_search.py +++ b/pytests/tests/test_search.py @@ -30,10 +30,26 @@ def test_search_invalid_arg(utils): def test_search_single(utils): - ret = utils.run(['tdnf', 'search', 'tdnf']) + pkgname = utils.config["sglversion_pkgname"] + ret = utils.run(['tdnf', 'search', pkgname]) assert ret['retval'] == 0 def test_search_multiple(utils): - ret = utils.run(['tdnf', 'search', 'tdnf', 'wget', 'gzip']) + sglpkgname = utils.config["sglversion_pkgname"] + mulpkgname = utils.config["mulversion_pkgname"] + ret = utils.run(['tdnf', 'search', sglpkgname, mulpkgname]) assert ret['retval'] == 0 + + +def test_search_valid_with_invalid(utils): + sglpkgname = utils.config["sglversion_pkgname"] + + ret = utils.run(f"tdnf search {sglpkgname} invalid1") + assert ret['retval'] == 1599 + assert "No search results found for 'invalid1'" in ret['stderr'] + + ret = utils.run(f"tdnf search {sglpkgname} invalid1 invalid2") + assert ret['retval'] == 1599 + assert "No search results found for 'invalid1'" in ret['stderr'] + assert "No search results found for 'invalid2'" in ret['stderr'] diff --git a/pytests/tests/test_whatprovides.py b/pytests/tests/test_whatprovides.py index b61b60c0..719eb359 100644 --- a/pytests/tests/test_whatprovides.py +++ b/pytests/tests/test_whatprovides.py @@ -28,7 +28,7 @@ def test_whatprovides_no_arg(utils): def test_whatprovides_invalid_arg(utils): ret = utils.run(['tdnf', 'whatprovides', 'invalid_arg']) assert ret['retval'] == 0 - assert ret['stderr'][0] == 'No data available' + assert 'No data available' in ret['stderr'] def test_whatprovides_valid_file_notinstalled(utils): diff --git a/solv/tdnfquery.c b/solv/tdnfquery.c index 58af20be..31d91408 100644 --- a/solv/tdnfquery.c +++ b/solv/tdnfquery.c @@ -427,6 +427,7 @@ SolvGenerateCommonJob( Queue queueJob = {0}; uint32_t nFlags = 0; uint32_t nRetFlags = 0; + uint32_t retVal = 0; if(!pQuery || !pQuery->pSack) { @@ -498,6 +499,12 @@ SolvGenerateCommonJob( queueJob.count, queueJob.elements); } + else + { + pr_err("No match found for '%s'\n", *ppszPkgNames); + if (retVal == 0) + retVal = ERROR_TDNF_NO_MATCH; + } ppszPkgNames++; } } @@ -514,6 +521,9 @@ SolvGenerateCommonJob( cleanup: queue_free(&queueJob); + if (retVal) + dwError = retVal; + return dwError; error: @@ -713,6 +723,7 @@ SolvApplySearch( Dataiterator di = {0}; Pool* pPool = NULL; uint32_t dwError = 0; + uint32_t retVal = 0; int nIndex = 0; Queue queueSel = {0}; Queue queueResult = {0}; @@ -728,6 +739,8 @@ SolvApplySearch( for(nIndex = dwStartIndex; nIndex < dwEndIndex; nIndex++) { + int countBeforeInsert = 0; + queue_empty(&queueSel); queue_empty(&queueResult); dataiterator_init(&di, pPool, 0, 0, 0, ppszSearchStrings[nIndex], @@ -747,15 +760,24 @@ SolvApplySearch( dataiterator_free(&di); selection_solvables(pPool, &queueSel, &queueResult); + countBeforeInsert = pQuery->queueResult.count; queue_insertn(&pQuery->queueResult, pQuery->queueResult.count, queueResult.count, queueResult.elements); + + if (pQuery->queueResult.count == countBeforeInsert) { + pr_err("No search results found for '%s'\n", ppszSearchStrings[nIndex]); + if (retVal == 0) + retVal = ERROR_TDNF_NO_MATCH; + } } cleanup: queue_free(&queueSel); queue_free(&queueResult); + if (retVal) + dwError = retVal; return dwError; error: