-
Notifications
You must be signed in to change notification settings - Fork 110
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
Test cases_config using catch2 #2425
Conversation
libres/tests/tmpdir.hpp
Outdated
#include <iostream> | ||
#include <string> | ||
#include <filesystem> | ||
namespace fs = std::filesystem; |
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.
Don't add namespace aliases to header files as they bleed into source files.
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.
Ok, thanks.
Should we update this from ecl?
https://github.com/equinor/ecl/blob/master/lib/tests/tmpdir.hpp
cases_config_fread(cases_config, file_path.c_str()); | ||
REQUIRE(cases_config_get_iteration_number(cases_config) == | ||
iteration_number); | ||
cases_config_free(cases_config); |
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.
You probably want the cases_config_free
to happen in the GIVEN
scope.
GIVEN("cases_config") { | ||
cases_config_type *cases_config = cases_config_alloc(); | ||
|
||
THEN("Write and read") { |
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.
Maybe Then("Write and read preserves get/set iteration_number behavior")
. The GIVEN
, WHEN
and THEN
macros refer to the 3xA concept from BDD (Assemble, Act, Assert) and are more or less aliases of SECTION
.
Generally, unless the test is very simple, I think its more readable if all three are present, in the given->when->then order.
GIVEN("A cases config with iteration number") {
cases_config_type *cases_config = cases_config_alloc();
int iteration_number = GENERATE(1,2,3,14);
cases_config_set_int(cases_config, "iteration_number", iteration_number);
WHEN("The cases config is written and then read back") {
fs::path file_path = dirname / "TEST_CASES_CONFIG";
cases_config_fwrite(cases_config, file_path.c_str());
cases_config_fread(cases_config, file_path.c_str());
THEN("Iteration number remains the same") {
REQUIRE(cases_config_get_iteration_number(cases_config) == teration_number);
}
}
cases_config_free(cases_config);
}
}
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.
This was a very helpful example, thanks!
I've updated the code to use this and the new tmpdir.
a5274f9
to
bc4718e
Compare
bc4718e
to
3f8305c
Compare
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.
LGTM
Introducing Tmpdir catch2 fixture similar
to tmpdir in pytest.
Copied from ecl.
Issue
Resolves #2387