-
Notifications
You must be signed in to change notification settings - Fork 14
Improve Phlex test coverage #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #include "phlex/configuration.hpp" | ||
| #include "phlex/core/consumer.hpp" | ||
| #include "phlex/core/glue.hpp" | ||
| #include "phlex/core/registrar.hpp" | ||
| #include "phlex/model/algorithm_name.hpp" | ||
| #include <catch2/catch_test_macros.hpp> | ||
|
|
||
| #include <boost/json.hpp> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| TEST_CASE("algorithm_name tests", "[model]") | ||
| { | ||
| using namespace phlex::experimental; | ||
|
|
||
| SECTION("Default constructor") | ||
| { | ||
| algorithm_name an; | ||
| CHECK(an.full() == ""); | ||
| } | ||
| SECTION("Create from string with colon") | ||
| { | ||
| auto an = algorithm_name::create("plugin:algo"); | ||
| CHECK(an.full() == "plugin:algo"); | ||
| } | ||
| SECTION("Create from string without colon") | ||
| { | ||
| auto an = algorithm_name::create("algo"); | ||
| // For 'either' cases, the first word is stored as plugin_ | ||
| CHECK(an.full() == "algo:"); | ||
| } | ||
| SECTION("Create from char pointer") | ||
| { | ||
| auto an = algorithm_name::create("ptr:algo"); | ||
| CHECK(an.full() == "ptr:algo"); | ||
| } | ||
| SECTION("Create error - trailing colon") | ||
| { | ||
| CHECK_THROWS_AS(algorithm_name::create("plugin:"), std::runtime_error); | ||
| } | ||
| SECTION("Match neither") | ||
| { | ||
| algorithm_name an = algorithm_name::create("p:a"); | ||
| algorithm_name other; // neither | ||
| CHECK(an.match(other)); | ||
| } | ||
| SECTION("Match either") | ||
| { | ||
| algorithm_name an = algorithm_name::create("p:a"); | ||
| CHECK(an.match(algorithm_name::create("p"))); | ||
| CHECK(an.match(algorithm_name::create("a"))); | ||
| } | ||
| SECTION("Match both") | ||
| { | ||
| algorithm_name an = algorithm_name::create("p:a"); | ||
| CHECK(an.match(algorithm_name::create("p:a"))); | ||
| CHECK_FALSE(an.match(algorithm_name::create("p:b"))); | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("consumer tests", "[core]") | ||
| { | ||
| using namespace phlex::experimental; | ||
| algorithm_name an = algorithm_name::create("p:a"); | ||
| consumer c(an, {"pred1"}); | ||
|
|
||
| CHECK(c.full_name() == "p:a"); | ||
| CHECK(c.plugin() == "p"); | ||
| CHECK(c.algorithm() == "a"); | ||
| CHECK(c.when().size() == 1); | ||
| } | ||
|
|
||
| TEST_CASE("verify_name tests", "[core]") | ||
| { | ||
| using namespace phlex::experimental::detail; | ||
|
|
||
| SECTION("non-empty name does nothing") { CHECK_NOTHROW(verify_name("valid_name", nullptr)); } | ||
|
|
||
| SECTION("empty name throws") { CHECK_THROWS_AS(verify_name("", nullptr), std::runtime_error); } | ||
|
|
||
| SECTION("empty name with config includes module label") | ||
| { | ||
| boost::json::object obj; | ||
| obj["module_label"] = "my_module"; | ||
| phlex::configuration config{obj}; | ||
|
|
||
| try { | ||
| verify_name("", &config); | ||
| FAIL("Should have thrown"); | ||
| } catch (std::runtime_error const& e) { | ||
| std::string msg = e.what(); | ||
| CHECK(msg.find("my_module") != std::string::npos); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("add_to_error_messages tests", "[core]") | ||
| { | ||
| using namespace phlex::experimental::detail; | ||
|
|
||
| std::vector<std::string> errors; | ||
| add_to_error_messages(errors, "duplicate_node"); | ||
|
|
||
| REQUIRE(errors.size() == 1); | ||
| CHECK(errors[0].find("duplicate_node") != std::string::npos); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion
id1 < id2 || id2 < id1is a tautology that will always be true for any two distinct identifiers, since we already established they're not equal on line 73. This doesn't meaningfully test the less-than operator. Consider replacing withassert(id1 < id2);to specifically verify the comparison relationship between "abc" and "def", or split it into two separate assertions to test both directions with known values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if the operators are defined incorrectly.