Skip to content
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

Merged
merged 1 commit into from
Nov 29, 2021
Merged

Conversation

dafeda
Copy link
Contributor

@dafeda dafeda commented Nov 23, 2021

Introducing Tmpdir catch2 fixture similar
to tmpdir in pytest.
Copied from ecl.

Issue
Resolves #2387

#include <iostream>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cases_config_fread(cases_config, file_path.c_str());
REQUIRE(cases_config_get_iteration_number(cases_config) ==
iteration_number);
cases_config_free(cases_config);
Copy link
Contributor

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") {
Copy link
Contributor

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);
    }
}

Copy link
Contributor Author

@dafeda dafeda Nov 25, 2021

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.

@dafeda dafeda self-assigned this Nov 25, 2021
@dafeda dafeda marked this pull request as ready for review November 29, 2021 07:04
Copy link
Contributor

@eivindjahren eivindjahren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dafeda dafeda merged commit b34cd74 into equinor:main Nov 29, 2021
@dafeda dafeda deleted the test_cases_config branch November 29, 2021 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test cases_config
3 participants