diff --git a/dnf5/commands/repoquery/repoquery.cpp b/dnf5/commands/repoquery/repoquery.cpp index f810e9eae..52eaff080 100644 --- a/dnf5/commands/repoquery/repoquery.cpp +++ b/dnf5/commands/repoquery/repoquery.cpp @@ -57,11 +57,13 @@ void RepoqueryCommand::set_argument_parser() { info_option = dynamic_cast( parser.add_init_value(std::unique_ptr(new libdnf::OptionBool(false)))); - nevra_option = dynamic_cast( - parser.add_init_value(std::unique_ptr(new libdnf::OptionBool(true)))); + // The default format is full_nevra + query_format_option = dynamic_cast( + parser.add_init_value(std::make_unique("%{full_nevra}\n"))); auto available = parser.add_new_named_arg("available"); available->set_long_name("available"); + //TODO(amatej): Unify description of all repoquery options to use the same wording available->set_description("display available packages (default)"); available->set_const_value("true"); available->link_value(available_option); @@ -78,11 +80,13 @@ void RepoqueryCommand::set_argument_parser() { info->set_const_value("true"); info->link_value(info_option); - auto nevra = parser.add_new_named_arg("nevra"); - nevra->set_long_name("nevra"); - nevra->set_description("use name-epoch:version-release.architecture format for displaying packages (default)"); - nevra->set_const_value("true"); - nevra->link_value(nevra_option); + auto query_format = parser.add_new_named_arg("queryformat"); + query_format->set_long_name("queryformat"); + query_format->set_description( + "display format for listing packages: %{name} %{version} ... use --querytags to view full tag list"); + query_format->set_has_value(true); + query_format->set_arg_value_help("QUERYFORMAT"); + query_format->link_value(query_format_option); auto keys = parser.add_new_positional_arg("keys_to_match", ArgumentParser::PositionalArg::UNLIMITED, nullptr, nullptr); @@ -102,8 +106,6 @@ void RepoqueryCommand::set_argument_parser() { } }); - info->add_conflict_argument(*nevra); - whatdepends_option = dynamic_cast( parser.add_init_value(std::make_unique(std::vector(), "", false, ","))); auto * whatdepends = parser.add_new_named_arg("whatdepends"); @@ -222,10 +224,45 @@ void RepoqueryCommand::set_argument_parser() { advisory_bz = std::make_unique(*this); advisory_cve = std::make_unique(*this); + std::vector pkg_attrs_options{ + "conflicts", + "enhances", + "obsoletes", + "provides", + "recommends", + "requires", + "requires-pre", + "suggests", + "supplements", + "", // empty when option is not used + }; + pkg_attr_option = dynamic_cast *>( + parser.add_init_value(std::make_unique>("", pkg_attrs_options))); + + auto * repoquery_formatting = get_context().get_argument_parser().add_new_group("repoquery_formatting"); + repoquery_formatting->set_header("Formatting:"); + cmd.register_group(repoquery_formatting); + + // remove the last empty ("") option, it should not be an arg + pkg_attrs_options.pop_back(); + for (const auto & pkg_attr : pkg_attrs_options) { + auto * arg = parser.add_new_named_arg(pkg_attr); + arg->set_long_name(pkg_attr); + arg->set_description("Like --queryformat=\"%{" + pkg_attr + "}\" but deduplicated and sorted."); + arg->set_has_value(false); + arg->set_const_value(pkg_attr); + arg->link_value(pkg_attr_option); + repoquery_formatting->register_argument(arg); + cmd.register_named_arg(arg); + } + repoquery_formatting->register_argument(info); + cmd.register_named_arg(info); + repoquery_formatting->register_argument(query_format); + cmd.register_named_arg(query_format); + cmd.register_named_arg(available); cmd.register_named_arg(installed); - cmd.register_named_arg(info); - cmd.register_named_arg(nevra); + cmd.register_named_arg(whatdepends); cmd.register_named_arg(whatconflicts); cmd.register_named_arg(whatprovides); @@ -235,6 +272,7 @@ void RepoqueryCommand::set_argument_parser() { cmd.register_named_arg(whatenhances); cmd.register_named_arg(whatsupplements); cmd.register_named_arg(whatsuggests); + cmd.register_positional_arg(keys); } @@ -450,10 +488,10 @@ void RepoqueryCommand::run() { libdnf::cli::output::print_package_info_table(package); std::cout << '\n'; } + } else if (!pkg_attr_option->get_value().empty()) { + libdnf::cli::output::print_pkg_attr_uniq_sorted(stdout, result_pset, pkg_attr_option->get_value()); } else { - for (auto package : result_pset) { - std::cout << package.get_full_nevra() << '\n'; - } + libdnf::cli::output::print_pkg_set_with_format(stdout, result_pset, query_format_option->get_value()); } } diff --git a/dnf5/commands/repoquery/repoquery.hpp b/dnf5/commands/repoquery/repoquery.hpp index f53f9d08c..92cbf0b11 100644 --- a/dnf5/commands/repoquery/repoquery.hpp +++ b/dnf5/commands/repoquery/repoquery.hpp @@ -48,7 +48,6 @@ class RepoqueryCommand : public Command { libdnf::OptionBool * available_option{nullptr}; libdnf::OptionBool * installed_option{nullptr}; libdnf::OptionBool * info_option{nullptr}; - libdnf::OptionBool * nevra_option{nullptr}; std::vector pkg_specs; std::vector cmdline_packages; @@ -65,6 +64,9 @@ class RepoqueryCommand : public Command { std::unique_ptr exactdeps{nullptr}; std::unique_ptr duplicates{nullptr}; + libdnf::OptionString * query_format_option{nullptr}; + libdnf::OptionEnum * pkg_attr_option{nullptr}; + std::unique_ptr advisory_name{nullptr}; std::unique_ptr advisory_security{nullptr}; std::unique_ptr advisory_bugfix{nullptr}; diff --git a/include/libdnf-cli/output/repoquery.hpp b/include/libdnf-cli/output/repoquery.hpp index 844b00617..89f4e8ef5 100644 --- a/include/libdnf-cli/output/repoquery.hpp +++ b/include/libdnf-cli/output/repoquery.hpp @@ -21,11 +21,14 @@ along with libdnf. If not, see . #ifndef LIBDNF_CLI_OUTPUT_REPOQUERY_HPP #define LIBDNF_CLI_OUTPUT_REPOQUERY_HPP +#include "libdnf/rpm/package_set.hpp" + #include namespace libdnf::cli::output { -static void add_line_into_package_info_table(struct libscols_table * table, const char * key, const char * value) { +[[maybe_unused]] static void add_line_into_package_info_table( + struct libscols_table * table, const char * key, const char * value) { struct libscols_line * ln = scols_table_new_line(table, nullptr); scols_line_set_data(ln, 0, key); scols_line_set_data(ln, 1, value); @@ -68,6 +71,11 @@ static void print_package_info_table(Package & package) { scols_unref_table(table); } +void print_pkg_set_with_format( + std::FILE * target, const libdnf::rpm::PackageSet & pkgs, const std::string & queryformat); + +void print_pkg_attr_uniq_sorted( + std::FILE * target, const libdnf::rpm::PackageSet & pkgs, const std::string & getter_name); } // namespace libdnf::cli::output diff --git a/libdnf-cli/output/repoqueryformat.cpp b/libdnf-cli/output/repoqueryformat.cpp new file mode 100644 index 000000000..d3d4866e4 --- /dev/null +++ b/libdnf-cli/output/repoqueryformat.cpp @@ -0,0 +1,256 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with libdnf. If not, see . +*/ + + +#include "fmt/args.h" +#include "utils/bgettext/bgettext-mark-domain.h" + +#include "libdnf-cli/output/repoquery.hpp" + +#include +#include + +namespace libdnf::cli::output { + +using StrGetter = std::string (libdnf::rpm::Package::*)() const; +using UnsignedLongLongGetter = unsigned long long (libdnf::rpm::Package::*)() const; +using ReldepListGetter = libdnf::rpm::ReldepList (libdnf::rpm::Package::*)() const; + +using Getter = std::variant; + +static const std::unordered_map NAME_TO_GETTER = { + {"name", &libdnf::rpm::Package::get_name}, + {"epoch", &libdnf::rpm::Package::get_epoch}, + {"version", &libdnf::rpm::Package::get_version}, + {"release", &libdnf::rpm::Package::get_release}, + {"arch", &libdnf::rpm::Package::get_arch}, + {"evr", &libdnf::rpm::Package::get_evr}, + {"nevra", &libdnf::rpm::Package::get_nevra}, + {"full_nevra", &libdnf::rpm::Package::get_full_nevra}, + {"na", &libdnf::rpm::Package::get_na}, + {"group", &libdnf::rpm::Package::get_group}, + {"packagesize", &libdnf::rpm::Package::get_package_size}, + {"installsize", &libdnf::rpm::Package::get_install_size}, + {"license", &libdnf::rpm::Package::get_license}, + {"source_name", &libdnf::rpm::Package::get_source_name}, + {"sourcerpm", &libdnf::rpm::Package::get_sourcerpm}, + {"buildtime", &libdnf::rpm::Package::get_build_time}, + {"packager", &libdnf::rpm::Package::get_packager}, + {"vendor", &libdnf::rpm::Package::get_vendor}, + {"url", &libdnf::rpm::Package::get_url}, + {"summary", &libdnf::rpm::Package::get_summary}, + {"description", &libdnf::rpm::Package::get_description}, + {"provides", &libdnf::rpm::Package::get_provides}, + {"requires", &libdnf::rpm::Package::get_requires}, + {"requires_pre", &libdnf::rpm::Package::get_requires_pre}, // this is for --repoformat="%{requires_pre}" + {"requires-pre", &libdnf::rpm::Package::get_requires_pre}, // this is for option --requires-pre + {"conflicts", &libdnf::rpm::Package::get_conflicts}, + {"obsoletes", &libdnf::rpm::Package::get_obsoletes}, + {"prereq_ignoreinst", &libdnf::rpm::Package::get_prereq_ignoreinst}, + {"regular_requires", &libdnf::rpm::Package::get_regular_requires}, + {"recommends", &libdnf::rpm::Package::get_recommends}, + {"suggests", &libdnf::rpm::Package::get_suggests}, + {"enhances", &libdnf::rpm::Package::get_enhances}, + {"supplements", &libdnf::rpm::Package::get_supplements}, + {"from_repo", &libdnf::rpm::Package::get_from_repo_id}, + {"installtime", &libdnf::rpm::Package::get_install_time}, + {"repoid", &libdnf::rpm::Package::get_repo_id}, +}; + +//TODO(amatej): Use keys of NAME_TO_GETTER for --querytags options + +// Argument format contains partially copied and converted queryformat, for example: "name: %-30{{name". +// We know the tag "name" is valid so this function check align spec "-30" and if it is valid +// it overwrites the format with fmt formatting: "name: {:<30}". +static bool replace_tag_in_format( + std::string & format, + std::string::size_type & format_size, + std::string::size_type tag_start, + std::string::size_type tag_name_start) { + std::string align_spec; + // Check if there is valid align spec between '%' and '{' -> ..%-30{... + if (tag_start + 1 != tag_name_start) { + align_spec = format.substr(tag_start + 1, tag_name_start - tag_start - 1); + auto iter = align_spec.begin(); + // first char can be either a digit or '-' sign + if ((*iter != '-') && (std::isdigit(*iter) == 0)) { + return false; + } + // verify the rest is only digits + ++iter; + while (iter != align_spec.end() && (std::isdigit(*iter) != 0)) { + ++iter; + } + if (iter != align_spec.end()) { + return false; + } + } + + // Since we use positional args for fmt::vprint we have to remove the tag name. + // We do this by overwriting the previously copied tag. + format_size = tag_start; + format[format_size] = '{'; + format_size++; + + if (!align_spec.empty()) { + format[format_size] = ':'; + format_size++; + + auto iter = align_spec.begin(); + if (*iter == '-') { + format[format_size] = '<'; + iter++; //skip the sign + } else { + format[format_size] = '>'; + } + format_size++; + while (iter != align_spec.end()) { + format[format_size] = *iter; + format_size++; + ++iter; + } + } + + format[format_size] = '}'; + format_size++; + return true; +} + +void print_pkg_set_with_format( + std::FILE * target, const libdnf::rpm::PackageSet & pkgs, const std::string & queryformat) { + std::vector getters; + std::string format; + // format max possible len is 2 * queryformat.size() (if it contained just curly braces) + format.resize(2 * queryformat.size()); + std::string::size_type format_size = 0; + std::string::size_type tag_start = 0; + std::string::size_type tag_name_start = 0; + char previous_qf_char = 0; + + enum State { OUTSIDE, IN_TAG, IN_TAG_NAME }; + State state = OUTSIDE; + + // Prepare format string and getters. + // We try to match rpm query formatting. + // For example: "%-30{name}%{evr}" needs to be converted to "{:<30}{}" that is + // two positional fmt arguments (first one with align formatting) and we need + // get_name() and get_evr() getters. + for (char qf_char : queryformat) { + if (qf_char == '%') { // start of tag + state = IN_TAG; + tag_start = format_size; + } else if (qf_char == '{' && state == IN_TAG) { // start of tag name + state = IN_TAG_NAME; + tag_name_start = format_size; + } else if (qf_char == '}' && state == IN_TAG_NAME) { // end of tag + state = OUTSIDE; + // To get the name we add/subtract 2 becasue each tag name (after brace expansion) starts with "{{". + auto getter_name = format.substr(tag_name_start + 2, format_size - tag_name_start - 2); + auto getter = NAME_TO_GETTER.find(getter_name); + if (getter != NAME_TO_GETTER.end()) { + if (replace_tag_in_format(format, format_size, tag_start, tag_name_start)) { + getters.push_back(getter->second); + continue; // continue to skip adding the current qf_char ('}') + } + } + } + + // Copy each char of queryformat to format string with required changes. + if (qf_char == '{' || qf_char == '}') { + // double the brace -> escaping for fmt + format[format_size] = qf_char; + format_size++; + format[format_size] = qf_char; + format_size++; + } else if (previous_qf_char == '\\' && qf_char == 'n') { + // replace new lines, two characters in input: '\' 'n' -> '\n' + format[format_size - 1] = '\n'; //replace the previous '\' + } else { + format[format_size] = qf_char; + format_size++; + } + + previous_qf_char = qf_char; + } + + // Resize the format to resulting size to trim excess characters. + format.resize(format_size); + + std::set output; + // Format and print each package. + fmt::dynamic_format_arg_store arg_store; + arg_store.reserve(getters.size(), getters.size()); + for (auto package : pkgs) { + arg_store.clear(); + for (const auto & getter : getters) { + std::visit( + [&arg_store, &package](const auto & getter_func) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + std::string joined; + for (const auto & reldep : (package.*getter_func)()) { + joined.append(std::move(reldep.to_string())); + joined.push_back('\n'); + } + arg_store.push_back(joined); + } else { + arg_store.push_back((package.*getter_func)()); + } + }, + getter); + } + + output.insert(fmt::vformat(format, arg_store)); + } + + for (const auto & line : output) { + fmt::print(target, "{}", line); + } +} + +void print_pkg_attr_uniq_sorted( + std::FILE * target, const libdnf::rpm::PackageSet & pkgs, const std::string & getter_name) { + auto getter = NAME_TO_GETTER.find(getter_name); + if (getter == NAME_TO_GETTER.end()) { + throw RuntimeError(M_("package getter: %s not available"), getter_name); + } + std::set output; + for (auto package : pkgs) { + std::visit( + [&output, &package](const auto & getter_func) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + for (const auto & reldep : (package.*getter_func)()) { + output.insert(std::move(reldep.to_string())); + } + } else if constexpr (std::is_same_v) { + output.insert(std::move(std::to_string((package.*getter_func)()))); + } else { + output.insert(std::move((package.*getter_func)())); + } + }, + getter->second); + } + + for (const auto & line : output) { + fmt::print(target, "{}\n", line); + } +} + +} // namespace libdnf::cli::output diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f5ef41e0..c2efc9c0f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,3 +43,6 @@ add_subdirectory(ruby) # components add_subdirectory(dnf5daemon-server) + +# add shared +add_subdirectory(shared) diff --git a/test/libdnf-cli/CMakeLists.txt b/test/libdnf-cli/CMakeLists.txt index 3bc702083..4f8e4e25b 100644 --- a/test/libdnf-cli/CMakeLists.txt +++ b/test/libdnf-cli/CMakeLists.txt @@ -16,7 +16,7 @@ include_directories(${PROJECT_SOURCE_DIR}/libdnf) add_executable(run_tests_cli ${TEST_LIBDNF5_CLI_SOURCES}) target_link_directories(run_tests_cli PUBLIC ${CMAKE_BINARY_DIR}/libdnf) -target_link_libraries(run_tests_cli stdc++ libdnf libdnf-cli cppunit) +target_link_libraries(run_tests_cli stdc++ libdnf libdnf-cli cppunit test_shared) add_test(NAME test_libdnf_cli COMMAND run_tests_cli) diff --git a/test/libdnf-cli/output/test_repoquery.cpp b/test/libdnf-cli/output/test_repoquery.cpp new file mode 100644 index 000000000..0670a27a2 --- /dev/null +++ b/test/libdnf-cli/output/test_repoquery.cpp @@ -0,0 +1,179 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + + +#include "test_repoquery.hpp" + +#include "libdnf-cli/output/repoquery.hpp" + + +CPPUNIT_TEST_SUITE_REGISTRATION(RepoqueryTest); + + +void RepoqueryTest::setUp() { + BaseTestCase::setUp(); + BaseTestCase::add_repo_repomd("repomd-repo1"); + pkgs = std::make_unique(base); +} + + +void RepoqueryTest::test_format_set_with_simple_str() { + FILE * stream = nullptr; + char * buf = nullptr; + size_t len = 0; + stream = open_memstream(&buf, &len); + + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "test\n"); + CPPUNIT_ASSERT_EQUAL(fflush(stream), 0); + + CPPUNIT_ASSERT_EQUAL(std::string("test\n"), std::string(buf)); + + free(buf); +} + + +void RepoqueryTest::test_format_set_with_tags() { + FILE * stream = nullptr; + char * buf = nullptr; + size_t len = 0; + + // One tag + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{name}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("pkg\npkg-libs\nunresolvable\n"), std::string(buf)); + free(buf); + + // Duplicate tag + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{name}-%{name}-%{name}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL( + std::string("pkg-libs-pkg-libs-pkg-libs\npkg-pkg-pkg\nunresolvable-unresolvable-unresolvable\n"), + std::string(buf)); + free(buf); + + // Different tags + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{name}-%{arch}-%{installsize}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL( + std::string("pkg-libs-x86_64-222\npkg-x86_64-222\nunresolvable-noarch-222\n"), std::string(buf)); + free(buf); +} + + +void RepoqueryTest::test_format_set_with_invalid_tags() { + FILE * stream = nullptr; + char * buf = nullptr; + size_t len = 0; + + // Incomplete tag + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{name\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%{name\n"), std::string(buf)); + free(buf); + + // Not matching tag + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{asd}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%{asd}\n"), std::string(buf)); + free(buf); + + // Incomplate tag with not matching tag and additional braces + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%%{ %% {{{%{asd}"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%%{ %% {{{%{asd}"), std::string(buf)); + free(buf); + + // Incomplate tag with matching tag and additional braces + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%%{}{}{{%{name}}"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%%{}{}{{pkg-libs}%%{}{}{{pkg}%%{}{}{{unresolvable}"), std::string(buf)); + free(buf); + + // fmt formatting strings are disabled + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%{name:^30}"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%{name:^30}"), std::string(buf)); + free(buf); +} + + +void RepoqueryTest::test_format_set_with_tags_with_spacing() { + FILE * stream = nullptr; + char * buf = nullptr; + size_t len = 0; + + // Tag with invalid format spec + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%aa20{name}%{evr}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("%aa20{name}1.2-3\n%aa20{name}1:1.3-4\n%aa20{name}1:2-3\n"), std::string(buf)); + free(buf); + + // One tag with align spec + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_set_with_format(stream, *pkgs, "%-20{name}%{evr}\n"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL( + std::string("pkg 1.2-3\npkg-libs 1:1.3-4\nunresolvable 1:2-3\n"), + std::string(buf)); + free(buf); +} + +void RepoqueryTest::test_pkg_attr_uniq_sorted() { + FILE * stream = nullptr; + char * buf = nullptr; + size_t len = 0; + + // requires + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_attr_uniq_sorted(stream, *pkgs, "requires"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("prereq\nreq = 1:2-3\n"), std::string(buf)); + free(buf); + + // provides + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_attr_uniq_sorted(stream, *pkgs, "provides"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL( + std::string("pkg = 1.2-3\npkg-libs = 1:1.3-4\nprv = 1:2-3\nunresolvable = 1:2-3\n"), std::string(buf)); + free(buf); + + // name + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_attr_uniq_sorted(stream, *pkgs, "name"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("pkg\npkg-libs\nunresolvable\n"), std::string(buf)); + free(buf); + + // deduplicated buildtimes + stream = open_memstream(&buf, &len); + libdnf::cli::output::print_pkg_attr_uniq_sorted(stream, *pkgs, "buildtime"); + CPPUNIT_ASSERT_EQUAL(fclose(stream), 0); + CPPUNIT_ASSERT_EQUAL(std::string("456\n"), std::string(buf)); + free(buf); +} diff --git a/test/libdnf-cli/output/test_repoquery.hpp b/test/libdnf-cli/output/test_repoquery.hpp new file mode 100644 index 000000000..4694676ff --- /dev/null +++ b/test/libdnf-cli/output/test_repoquery.hpp @@ -0,0 +1,60 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Libdnf is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with libdnf. If not, see . +*/ + + +#ifndef TEST_LIBDNF_CLI_OUTPUT_REPOQUERY_HPP +#define TEST_LIBDNF_CLI_OUTPUT_REPOQUERY_HPP + + +#include "../../shared/base_test_case.hpp" + +#include "libdnf/rpm/package_query.hpp" + +#include +#include + +#include + + +class RepoqueryTest : public BaseTestCase { + CPPUNIT_TEST_SUITE(RepoqueryTest); + + CPPUNIT_TEST(test_format_set_with_simple_str); + CPPUNIT_TEST(test_format_set_with_tags); + CPPUNIT_TEST(test_format_set_with_invalid_tags); + CPPUNIT_TEST(test_format_set_with_tags_with_spacing); + CPPUNIT_TEST(test_pkg_attr_uniq_sorted); + + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() override; + + void test_format_set_with_simple_str(); + void test_format_set_with_tags(); + void test_format_set_with_invalid_tags(); + void test_format_set_with_tags_with_spacing(); + void test_pkg_attr_uniq_sorted(); + +private: + std::unique_ptr pkgs; +}; + + +#endif // TEST_LIBDNF_CLI_OUTPUT_REPOQUERY_HPP diff --git a/test/libdnf-cli/test_argument_parser.cpp b/test/libdnf-cli/test_argument_parser.cpp index bae8fccfc..2234e75ce 100644 --- a/test/libdnf-cli/test_argument_parser.cpp +++ b/test/libdnf-cli/test_argument_parser.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_argument_parser.hpp" -#include "../libdnf/utils.hpp" +#include "../shared/utils.hpp" #include "libdnf-cli/argument_parser.hpp" diff --git a/test/libdnf/CMakeLists.txt b/test/libdnf/CMakeLists.txt index 44554f54e..25822fbb7 100644 --- a/test/libdnf/CMakeLists.txt +++ b/test/libdnf/CMakeLists.txt @@ -16,7 +16,7 @@ target_compile_options(run_tests PRIVATE "-Wno-self-assign-overloaded") target_compile_options(run_tests PRIVATE "-Wno-self-move") target_link_directories(run_tests PUBLIC ${CMAKE_BINARY_DIR}/libdnf) -target_link_libraries(run_tests stdc++ libdnf cppunit) +target_link_libraries(run_tests stdc++ libdnf cppunit test_shared) pkg_check_modules(JSONC REQUIRED json-c) include_directories(${JSONC_INCLUDE_DIRS}) diff --git a/test/libdnf/advisory/test_advisory.hpp b/test/libdnf/advisory/test_advisory.hpp index 9d08650df..0bb44bffa 100644 --- a/test/libdnf/advisory/test_advisory.hpp +++ b/test/libdnf/advisory/test_advisory.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/advisory/advisory_collection.hpp" diff --git a/test/libdnf/advisory/test_advisory_module.hpp b/test/libdnf/advisory/test_advisory_module.hpp index 6455677c6..d16f2b73b 100644 --- a/test/libdnf/advisory/test_advisory_module.hpp +++ b/test/libdnf/advisory/test_advisory_module.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_MODULE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/advisory/advisory_collection.hpp" #include "libdnf/advisory/advisory_module.hpp" diff --git a/test/libdnf/advisory/test_advisory_package.hpp b/test/libdnf/advisory/test_advisory_package.hpp index 679ab9afb..bd061e8dc 100644 --- a/test/libdnf/advisory/test_advisory_package.hpp +++ b/test/libdnf/advisory/test_advisory_package.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_PACKAGE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/advisory/advisory_collection.hpp" #include "libdnf/advisory/advisory_package.hpp" diff --git a/test/libdnf/advisory/test_advisory_query.cpp b/test/libdnf/advisory/test_advisory_query.cpp index 537c7e5a9..8b338aa32 100644 --- a/test/libdnf/advisory/test_advisory_query.cpp +++ b/test/libdnf/advisory/test_advisory_query.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_advisory_query.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/package_query.hpp" #include "libdnf/rpm/package_set.hpp" diff --git a/test/libdnf/advisory/test_advisory_query.hpp b/test/libdnf/advisory/test_advisory_query.hpp index 67abb4642..bd55ce6c3 100644 --- a/test/libdnf/advisory/test_advisory_query.hpp +++ b/test/libdnf/advisory/test_advisory_query.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_QUERY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/advisory/test_advisory_reference.hpp b/test/libdnf/advisory/test_advisory_reference.hpp index f85374710..8b69e8c1f 100644 --- a/test/libdnf/advisory/test_advisory_reference.hpp +++ b/test/libdnf/advisory/test_advisory_reference.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_REFERENCE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/advisory/advisory_collection.hpp" #include "libdnf/advisory/advisory_reference.hpp" diff --git a/test/libdnf/advisory/test_advisory_set.hpp b/test/libdnf/advisory/test_advisory_set.hpp index a23d25935..d20836380 100644 --- a/test/libdnf/advisory/test_advisory_set.hpp +++ b/test/libdnf/advisory/test_advisory_set.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_ADVISORY_ADVISORY_SET_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/advisory/advisory_set.hpp" diff --git a/test/libdnf/base/test_base.hpp b/test/libdnf/base/test_base.hpp index 126aa3168..2b5c85ed6 100644 --- a/test/libdnf/base/test_base.hpp +++ b/test/libdnf/base/test_base.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_BASE_BASE_HPP -#include "test_case_fixture.hpp" +#include "../shared/test_case_fixture.hpp" #include diff --git a/test/libdnf/base/test_goal.cpp b/test/libdnf/base/test_goal.cpp index bf966da62..f84948000 100644 --- a/test/libdnf/base/test_goal.cpp +++ b/test/libdnf/base/test_goal.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_goal.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/base/goal.hpp" #include "libdnf/base/transaction_package.hpp" diff --git a/test/libdnf/base/test_goal.hpp b/test/libdnf/base/test_goal.hpp index a7cd39411..847ddf1ac 100644 --- a/test/libdnf/base/test_goal.hpp +++ b/test/libdnf/base/test_goal.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_BASE_GOAL_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/comps/test_environment.hpp b/test/libdnf/comps/test_environment.hpp index 400016548..3f101f0ea 100644 --- a/test/libdnf/comps/test_environment.hpp +++ b/test/libdnf/comps/test_environment.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_COMPS_ENVIRONMENT_HPP #define LIBDNF_TEST_COMPS_ENVIRONMENT_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/comps/test_environment_query.cpp b/test/libdnf/comps/test_environment_query.cpp index c65e7147d..c940fe689 100644 --- a/test/libdnf/comps/test_environment_query.cpp +++ b/test/libdnf/comps/test_environment_query.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_environment_query.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/comps/environment/query.hpp" diff --git a/test/libdnf/comps/test_environment_query.hpp b/test/libdnf/comps/test_environment_query.hpp index f49952e7d..940e2571c 100644 --- a/test/libdnf/comps/test_environment_query.hpp +++ b/test/libdnf/comps/test_environment_query.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_COMPS_ENVIRONMENT_QUERY_HPP #define LIBDNF_TEST_COMPS_ENVIRONMENT_QUERY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/comps/test_group.cpp b/test/libdnf/comps/test_group.cpp index 17600efb0..6e784b777 100644 --- a/test/libdnf/comps/test_group.cpp +++ b/test/libdnf/comps/test_group.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_group.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "utils/fs/file.hpp" #include "libdnf/comps/comps.hpp" diff --git a/test/libdnf/comps/test_group.hpp b/test/libdnf/comps/test_group.hpp index 090f8ea1c..41fa79d45 100644 --- a/test/libdnf/comps/test_group.hpp +++ b/test/libdnf/comps/test_group.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_COMPS_GROUP_HPP #define LIBDNF_TEST_COMPS_GROUP_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/comps/test_group_query.cpp b/test/libdnf/comps/test_group_query.cpp index 5b2b135f3..966566bef 100644 --- a/test/libdnf/comps/test_group_query.cpp +++ b/test/libdnf/comps/test_group_query.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_group_query.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/comps/group/query.hpp" diff --git a/test/libdnf/comps/test_group_query.hpp b/test/libdnf/comps/test_group_query.hpp index ba22eeaa5..5fe1157d1 100644 --- a/test/libdnf/comps/test_group_query.hpp +++ b/test/libdnf/comps/test_group_query.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_COMPS_GROUP_QUERY_HPP #define LIBDNF_TEST_COMPS_GROUP_QUERY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/conf/test_conf.cpp b/test/libdnf/conf/test_conf.cpp index 7c83c5188..5fb8a5904 100644 --- a/test/libdnf/conf/test_conf.cpp +++ b/test/libdnf/conf/test_conf.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_conf.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/repo/config_repo.hpp" diff --git a/test/libdnf/conf/test_conf.hpp b/test/libdnf/conf/test_conf.hpp index e2d8487d3..4023fe71c 100644 --- a/test/libdnf/conf/test_conf.hpp +++ b/test/libdnf/conf/test_conf.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef TEST_LIBDNF_CONF_CONF_HPP #define TEST_LIBDNF_CONF_CONF_HPP -#include "test_case_fixture.hpp" +#include "../shared/test_case_fixture.hpp" #include "libdnf/base/base.hpp" #include "libdnf/logger/log_router.hpp" diff --git a/test/libdnf/conf/test_option.cpp b/test/libdnf/conf/test_option.cpp index 7f191b111..6f486a6eb 100644 --- a/test/libdnf/conf/test_option.cpp +++ b/test/libdnf/conf/test_option.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_option.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/conf/option_bool.hpp" #include "libdnf/conf/option_child.hpp" diff --git a/test/libdnf/conf/test_vars.hpp b/test/libdnf/conf/test_vars.hpp index aa09b8a3d..cdd5246df 100644 --- a/test/libdnf/conf/test_vars.hpp +++ b/test/libdnf/conf/test_vars.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef TEST_LIBDNF_CONF_VARS_HPP #define TEST_LIBDNF_CONF_VARS_HPP -#include "test_case_fixture.hpp" +#include "../shared/test_case_fixture.hpp" #include "libdnf/base/base.hpp" diff --git a/test/libdnf/logger/test_file_logger.hpp b/test/libdnf/logger/test_file_logger.hpp index 4c391d4aa..916c38bac 100644 --- a/test/libdnf/logger/test_file_logger.hpp +++ b/test/libdnf/logger/test_file_logger.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_FILE_LOGGER_HPP #define LIBDNF_TEST_FILE_LOGGER_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/module/test_module.cpp b/test/libdnf/module/test_module.cpp index 8f59b93ac..3e863c087 100644 --- a/test/libdnf/module/test_module.cpp +++ b/test/libdnf/module/test_module.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_module.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "utils/fs/file.hpp" #include "libdnf/module/module_errors.hpp" diff --git a/test/libdnf/module/test_module.hpp b/test/libdnf/module/test_module.hpp index fdbaac503..c58289986 100644 --- a/test/libdnf/module/test_module.hpp +++ b/test/libdnf/module/test_module.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_MODULE_HPP #define LIBDNF_TEST_MODULE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/repo/test_package_downloader.hpp b/test/libdnf/repo/test_package_downloader.hpp index 34925f3ca..d77de221f 100644 --- a/test/libdnf/repo/test_package_downloader.hpp +++ b/test/libdnf/repo/test_package_downloader.hpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_REPO_PACKAGE_DOWNLOADER_HPP #define LIBDNF_TEST_REPO_PACKAGE_DOWNLOADER_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/repo/test_repo.hpp b/test/libdnf/repo/test_repo.hpp index d381c4fca..d8ff8329d 100644 --- a/test/libdnf/repo/test_repo.hpp +++ b/test/libdnf/repo/test_repo.hpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_REPO_REPO_HPP #define LIBDNF_TEST_REPO_REPO_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/repo/test_repo_query.hpp b/test/libdnf/repo/test_repo_query.hpp index 54ed9b960..64fab9c79 100644 --- a/test/libdnf/repo/test_repo_query.hpp +++ b/test/libdnf/repo/test_repo_query.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #define LIBDNF_TEST_REPO_QUERY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/rpm/test_nevra.cpp b/test/libdnf/rpm/test_nevra.cpp index 4cc23ed66..4e462ec92 100644 --- a/test/libdnf/rpm/test_nevra.cpp +++ b/test/libdnf/rpm/test_nevra.cpp @@ -19,7 +19,7 @@ along with libdnf. If not, see . #include "test_nevra.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/nevra.hpp" diff --git a/test/libdnf/rpm/test_package.cpp b/test/libdnf/rpm/test_package.cpp index c8ec15592..baa72b454 100644 --- a/test/libdnf/rpm/test_package.cpp +++ b/test/libdnf/rpm/test_package.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_package.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/nevra.hpp" diff --git a/test/libdnf/rpm/test_package.hpp b/test/libdnf/rpm/test_package.hpp index b7e42e933..d3f101fae 100644 --- a/test/libdnf/rpm/test_package.hpp +++ b/test/libdnf/rpm/test_package.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_RPM_PACKAGE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/rpm/test_package_query.cpp b/test/libdnf/rpm/test_package_query.cpp index dac58371b..131cdb3f8 100644 --- a/test/libdnf/rpm/test_package_query.cpp +++ b/test/libdnf/rpm/test_package_query.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_package_query.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/package_query.hpp" #include "libdnf/rpm/package_set.hpp" diff --git a/test/libdnf/rpm/test_package_query.hpp b/test/libdnf/rpm/test_package_query.hpp index 9d77ad75c..7a98bcd91 100644 --- a/test/libdnf/rpm/test_package_query.hpp +++ b/test/libdnf/rpm/test_package_query.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_RPM_PACKAGE_QUERY_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/rpm/test_package_sack.cpp b/test/libdnf/rpm/test_package_sack.cpp index 7dd571063..712cad7d2 100644 --- a/test/libdnf/rpm/test_package_sack.cpp +++ b/test/libdnf/rpm/test_package_sack.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_package_sack.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/package_sack.hpp" #include "libdnf/rpm/package_set.hpp" diff --git a/test/libdnf/rpm/test_package_sack.hpp b/test/libdnf/rpm/test_package_sack.hpp index 5c9123f68..deeefbbc7 100644 --- a/test/libdnf/rpm/test_package_sack.hpp +++ b/test/libdnf/rpm/test_package_sack.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_RPM_PACKAGE_SACK_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/rpm/package_set.hpp" diff --git a/test/libdnf/rpm/test_package_set.hpp b/test/libdnf/rpm/test_package_set.hpp index 7966d9ac5..c2bd033b1 100644 --- a/test/libdnf/rpm/test_package_set.hpp +++ b/test/libdnf/rpm/test_package_set.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_RPM_PACKAGE_SET_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/rpm/package_set.hpp" diff --git a/test/libdnf/rpm/test_reldep.hpp b/test/libdnf/rpm/test_reldep.hpp index 3e2f9b258..7f673b25a 100644 --- a/test/libdnf/rpm/test_reldep.hpp +++ b/test/libdnf/rpm/test_reldep.hpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_RELDEP_HPP #define LIBDNF_TEST_RELDEP_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include diff --git a/test/libdnf/rpm/test_reldep_list.cpp b/test/libdnf/rpm/test_reldep_list.cpp index dfff3bd6c..a4a8bcf92 100644 --- a/test/libdnf/rpm/test_reldep_list.cpp +++ b/test/libdnf/rpm/test_reldep_list.cpp @@ -19,7 +19,7 @@ along with libdnf. If not, see . #include "test_reldep_list.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/rpm/reldep_list.hpp" diff --git a/test/libdnf/rpm/test_reldep_list.hpp b/test/libdnf/rpm/test_reldep_list.hpp index 70e5aa454..fef6ed5d0 100644 --- a/test/libdnf/rpm/test_reldep_list.hpp +++ b/test/libdnf/rpm/test_reldep_list.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef TEST_LIBDNF_RPM_RELDEP_LIST_HPP #define TEST_LIBDNF_RPM_RELDEP_LIST_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/base/base.hpp" #include "libdnf/rpm/package_sack.hpp" diff --git a/test/libdnf/rpm/test_transaction.cpp b/test/libdnf/rpm/test_transaction.cpp index 66e8da335..c3cf09b9c 100644 --- a/test/libdnf/rpm/test_transaction.cpp +++ b/test/libdnf/rpm/test_transaction.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_transaction.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "libdnf/base/base.hpp" #include "libdnf/base/goal.hpp" diff --git a/test/libdnf/rpm/test_transaction.hpp b/test/libdnf/rpm/test_transaction.hpp index 0a5d0ab25..016afe785 100644 --- a/test/libdnf/rpm/test_transaction.hpp +++ b/test/libdnf/rpm/test_transaction.hpp @@ -21,7 +21,7 @@ along with libdnf. If not, see . #ifndef LIBDNF_TEST_RPM_TRANSACTION_HPP #define LIBDNF_TEST_RPM_TRANSACTION_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include #include diff --git a/test/libdnf/run_tests.cpp b/test/libdnf/run_tests.cpp index bde00a279..93c3660ab 100644 --- a/test/libdnf/run_tests.cpp +++ b/test/libdnf/run_tests.cpp @@ -18,7 +18,7 @@ along with libdnf. If not, see . */ -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "libdnf/logger/memory_buffer_logger.hpp" #include "libdnf/logger/stream_logger.hpp" diff --git a/test/libdnf/system/test_state.cpp b/test/libdnf/system/test_state.cpp index bf98a64ef..3013adb83 100644 --- a/test/libdnf/system/test_state.cpp +++ b/test/libdnf/system/test_state.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_state.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "utils/fs/file.hpp" diff --git a/test/libdnf/system/test_state.hpp b/test/libdnf/system/test_state.hpp index 9377d620e..4f852eb8f 100644 --- a/test/libdnf/system/test_state.hpp +++ b/test/libdnf/system/test_state.hpp @@ -22,7 +22,7 @@ along with libdnf. If not, see . #define TEST_LIBDNF_SYSTEM_STATE_HPP -#include "base_test_case.hpp" +#include "../shared/base_test_case.hpp" #include "system/state.hpp" #include "utils/fs/temp.hpp" diff --git a/test/libdnf/transaction/test_comps_environment.cpp b/test/libdnf/transaction/test_comps_environment.cpp index 76afe6505..95e65f7f4 100644 --- a/test/libdnf/transaction/test_comps_environment.cpp +++ b/test/libdnf/transaction/test_comps_environment.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_comps_environment.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/comps/group/package.hpp" #include "libdnf/transaction/comps_environment.hpp" diff --git a/test/libdnf/transaction/test_comps_group.cpp b/test/libdnf/transaction/test_comps_group.cpp index c92e60da5..925e3e080 100644 --- a/test/libdnf/transaction/test_comps_group.cpp +++ b/test/libdnf/transaction/test_comps_group.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_comps_group.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/comps/group/package.hpp" #include "libdnf/transaction/comps_group.hpp" diff --git a/test/libdnf/transaction/test_query.cpp b/test/libdnf/transaction/test_query.cpp index dea54b25d..5c119e91e 100644 --- a/test/libdnf/transaction/test_query.cpp +++ b/test/libdnf/transaction/test_query.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_query.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/transaction/transaction.hpp" diff --git a/test/libdnf/transaction/test_rpm_package.cpp b/test/libdnf/transaction/test_rpm_package.cpp index 921dd8b48..68e6b5f5b 100644 --- a/test/libdnf/transaction/test_rpm_package.cpp +++ b/test/libdnf/transaction/test_rpm_package.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_rpm_package.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/common/sack/query_cmp.hpp" #include "libdnf/transaction/rpm_package.hpp" diff --git a/test/libdnf/transaction/test_transaction.cpp b/test/libdnf/transaction/test_transaction.cpp index 644b7d5c4..82b03320f 100644 --- a/test/libdnf/transaction/test_transaction.cpp +++ b/test/libdnf/transaction/test_transaction.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_transaction.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/transaction/transaction.hpp" diff --git a/test/libdnf/transaction/test_workflow.cpp b/test/libdnf/transaction/test_workflow.cpp index ef16c9db5..2024f5e0f 100644 --- a/test/libdnf/transaction/test_workflow.cpp +++ b/test/libdnf/transaction/test_workflow.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_workflow.hpp" -#include "private_accessor.hpp" +#include "../shared/private_accessor.hpp" #include "libdnf/common/sack/query_cmp.hpp" #include "libdnf/comps/group/package.hpp" diff --git a/test/libdnf/utils/test_string.cpp b/test/libdnf/utils/test_string.cpp index f1c7539dc..dd6d601ea 100644 --- a/test/libdnf/utils/test_string.cpp +++ b/test/libdnf/utils/test_string.cpp @@ -20,7 +20,7 @@ along with libdnf. If not, see . #include "test_string.hpp" -#include "utils.hpp" +#include "../shared/utils.hpp" #include "utils/string.hpp" diff --git a/test/shared/CMakeLists.txt b/test/shared/CMakeLists.txt new file mode 100644 index 000000000..e087fe071 --- /dev/null +++ b/test/shared/CMakeLists.txt @@ -0,0 +1,13 @@ +pkg_check_modules(CPPUNIT REQUIRED cppunit) + + +# use any sources found under the current directory +file(GLOB_RECURSE TEST_SHARED_SOURCES *.cpp) + +include_directories(.) +include_directories(${PROJECT_SOURCE_DIR}/libdnf) + +add_library(test_shared OBJECT ${TEST_SHARED_SOURCES}) + +target_link_directories(test_shared PUBLIC ${CMAKE_BINARY_DIR}/libdnf) +target_link_libraries(test_shared stdc++ libdnf cppunit) diff --git a/test/libdnf/base_test_case.cpp b/test/shared/base_test_case.cpp similarity index 100% rename from test/libdnf/base_test_case.cpp rename to test/shared/base_test_case.cpp diff --git a/test/libdnf/base_test_case.hpp b/test/shared/base_test_case.hpp similarity index 100% rename from test/libdnf/base_test_case.hpp rename to test/shared/base_test_case.hpp diff --git a/test/libdnf/private_accessor.hpp b/test/shared/private_accessor.hpp similarity index 100% rename from test/libdnf/private_accessor.hpp rename to test/shared/private_accessor.hpp diff --git a/test/libdnf/test_case_fixture.cpp b/test/shared/test_case_fixture.cpp similarity index 100% rename from test/libdnf/test_case_fixture.cpp rename to test/shared/test_case_fixture.cpp diff --git a/test/libdnf/test_case_fixture.hpp b/test/shared/test_case_fixture.hpp similarity index 100% rename from test/libdnf/test_case_fixture.hpp rename to test/shared/test_case_fixture.hpp diff --git a/test/libdnf/utils.cpp b/test/shared/utils.cpp similarity index 100% rename from test/libdnf/utils.cpp rename to test/shared/utils.cpp diff --git a/test/libdnf/utils.hpp b/test/shared/utils.hpp similarity index 100% rename from test/libdnf/utils.hpp rename to test/shared/utils.hpp